package
{
import flash.events.KeyboardEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.ui.Keyboard;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
public class Papervision3DObjectScale extends BasicView
{
private var object :Cube;
private var field :TextField;
public function Papervision3DObjectScale()
{
camera.x = 1000;
camera.y = 1000;
object = new Cube(new MaterialsList({
front: new ColorMaterial(0xff0000),
back: new ColorMaterial(0x00ff00),
right: new ColorMaterial(0x0000ff),
left: new ColorMaterial(0xffff00),
top: new ColorMaterial(0xff00ff),
bottom: new ColorMaterial(0x00ffff)}));
scene.addChild(object);
field = new TextField();
field.autoSize = TextFieldAutoSize.LEFT;
field.defaultTextFormat = new TextFormat("verdana");
field.selectable = false;
addChild(field);
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
singleRender();
instructions();
}
private function handleKeyDown(e:KeyboardEvent):void
{
switch (e.keyCode) {
case Keyboard.ENTER:
object.scale = 1;
break;
case "Q".charCodeAt():
object.scaleX++;
break;
case "A".charCodeAt():
object.scaleX--;
break;
case "W".charCodeAt():
object.scaleY++;
break;
case "S".charCodeAt():
object.scaleY--;
break;
case "E".charCodeAt():
object.scaleZ++;
break;
case "D".charCodeAt():
object.scaleZ--;
break;
}
singleRender();
instructions();
}
private function instructions():void
{
field.text = "Click\tStart"
+ "\nEnter\tReset"
+ "\nQ\t\tObject Scale X +"
+ "\nA\t\tObject Scale X -"
+ "\nW\t\tObject Scale Y +"
+ "\nS\t\tObject Scale Y -"
+ "\nE\t\tObject Scale Z +"
+ "\nD\t\tObject Scale Z -"
+ "\n\nObject Scale:"
+ "\nX:\t" + object.scaleX
+ "\nY:\t" + object.scaleY
+ "\nZ:\t" + object.scaleZ;
}
}
}
Download