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 Papervision3DObjectRotate extends BasicView
{
private var object :Cube;
private var field :TextField;
public function Papervision3DObjectRotate()
{
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.localRotationX = 0;
object.localRotationY = 0;
object.localRotationZ = 0;
object.rotationX = 0;
object.rotationY = 0;
object.rotationZ = 0;
break;
case "Q".charCodeAt():
object.rotationX += 10;
break;
case "A".charCodeAt():
object.rotationX -= 10;
break;
case "W".charCodeAt():
object.rotationY += 10;
break;
case "S".charCodeAt():
object.rotationY -= 10;
break;
case "E".charCodeAt():
object.rotationZ += 10;
break;
case "D".charCodeAt():
object.rotationZ -= 10;
break;
case "R".charCodeAt():
object.localRotationX += 10;
break;
case "F".charCodeAt():
object.localRotationX -= 10;
break;
case "T".charCodeAt():
object.localRotationY += 10;
break;
case "G".charCodeAt():
object.localRotationY -= 10;
break;
case "Y".charCodeAt():
object.localRotationZ += 10;
break;
case "H".charCodeAt():
object.localRotationZ -= 10;
break;
case "U".charCodeAt():
object.pitch(10);
break;
case "J".charCodeAt():
object.pitch(-10);
break;
case "I".charCodeAt():
object.yaw(10);
break;
case "K".charCodeAt():
object.yaw(-10);
break;
case "O".charCodeAt():
object.roll(10);
break;
case "L".charCodeAt():
object.roll(-10);
break;
}
singleRender();
instructions();
}
private function instructions():void
{
field.text = "Click\tStart"
+ "\nEnter\tReset"
+ "\nQ\t\tObject Rotate X +"
+ "\nA\t\tObject Rotate X -"
+ "\nW\t\tObject Rotate Y +"
+ "\nS\t\tObject Rotate Y -"
+ "\nE\t\tObject Rotate Z +"
+ "\nD\t\tObject Rotate Z -"
+ "\nR\t\tObject Rotate Local X +"
+ "\nF\t\tObject Rotate Local X -"
+ "\nT\t\tObject Rotate Local Y +"
+ "\nG\t\tObject Rotate Local Y -"
+ "\nY\t\tObject Rotate Local Z +"
+ "\nH\t\tObject Rotate Local Z -"
+ "\nU\t\tObject Pitch +"
+ "\nJ\t\tObject Pitch -"
+ "\nI\t\tObject Yaw +"
+ "\nK\t\tObject Yaw -"
+ "\nO\t\tObject Roll +"
+ "\nL\t\tObject Roll -"
+ "\n\nObject Rotation:"
+ "\nX:\t" + object.rotationX
+ "\nY:\t" + object.rotationY
+ "\nZ:\t" + object.rotationZ
+ "\n\nObject Local Rotation:"
+ "\nX:\t" + object.localRotationX
+ "\nY:\t" + object.localRotationY
+ "\nZ:\t" + object.localRotationZ;
}
}
}
Download