Camera Rotate

Papervision3D Camera Rotate

Code

Δ

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 Papervision3DCameraRotate extends BasicView
  {
    private var field :TextField;

    public function Papervision3DCameraRotate()
    {
      super(640, 480, true, false, "Free");

      camera.z = 0;

      var material :ColorMaterial = new ColorMaterial(0xff0000);
      material.opposite = true;

      var material2 :ColorMaterial = new ColorMaterial(0x00ff00);
      material2.opposite = true;

      var material3 :ColorMaterial = new ColorMaterial(0x0000ff);
      material3.opposite = true;

      var material4 :ColorMaterial = new ColorMaterial(0xffff00);
      material4.opposite = true;

      var material5 :ColorMaterial = new ColorMaterial(0xff00ff);
      material5.opposite = true;

      var material6 :ColorMaterial = new ColorMaterial(0x00ffff);
      material6.opposite = true;

      var object :Cube = new Cube(new MaterialsList({
        front:  material,
        back:   material2,
        right:  material3,
        left:   material4,
        top:    material5,
        bottom: material6}), 500, 500, 500, 10, 10, 10);
      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:
          camera.localRotationX = 0;
          camera.localRotationY = 0;
          camera.localRotationZ = 0;
          camera.rotationX = 0;
          camera.rotationY = 0;
          camera.rotationZ = 0;
          break;
        case "Q".charCodeAt():
          camera.rotationX += 10;
          break;
        case "A".charCodeAt():
          camera.rotationX -= 10;
          break;
        case "W".charCodeAt():
          camera.rotationY += 10;
          break;
        case "S".charCodeAt():
          camera.rotationY -= 10;
          break;
        case "E".charCodeAt():
          camera.rotationZ += 10;
          break;
        case "D".charCodeAt():
          camera.rotationZ -= 10;
          break;
        case "R".charCodeAt():
          camera.localRotationX += 10;
          break;
        case "F".charCodeAt():
          camera.localRotationX -= 10;
          break;
        case "T".charCodeAt():
          camera.localRotationY += 10;
          break;
        case "G".charCodeAt():
          camera.localRotationY -= 10;
          break;
        case "Y".charCodeAt():
          camera.localRotationZ += 10;
          break;
        case "H".charCodeAt():
          camera.localRotationZ -= 10;
          break;
        case "U".charCodeAt():
          camera.pitch(10);
          break;
        case "J".charCodeAt():
          camera.pitch(-10);
          break;
        case "I".charCodeAt():
          camera.yaw(10);
          break;
        case "K".charCodeAt():
          camera.yaw(-10);
          break;
        case "O".charCodeAt():
          camera.roll(10);
          break;
        case "L".charCodeAt():
          camera.roll(-10);
          break;
      }

      singleRender();
      instructions();
    }

    private function instructions():void
    {
      field.text = "Click\tStart"
        + "\nEnter\tReset"
        + "\nQ\t\tCamera Rotate X +"
        + "\nA\t\tCamera Rotate X -"
        + "\nW\t\tCamera Rotate Y +"
        + "\nS\t\tCamera Rotate Y -"
        + "\nE\t\tCamera Rotate Z +"
        + "\nD\t\tCamera Rotate Z -"
        + "\nR\t\tCamera Rotate Local X +"
        + "\nF\t\tCamera Rotate Local X -"
        + "\nT\t\tCamera Rotate Local Y +"
        + "\nG\t\tCamera Rotate Local Y -"
        + "\nY\t\tCamera Rotate Local Z +"
        + "\nH\t\tCamera Rotate Local Z -"
        + "\nU\t\tCamera Pitch +"
        + "\nJ\t\tCamera Pitch -"
        + "\nI\t\tCamera Yaw +"
        + "\nK\t\tCamera Yaw -"
        + "\nO\t\tCamera Roll +"
        + "\nL\t\tCamera Roll -"
        + "\n\nCamera Rotation:"
        + "\nX:\t" + camera.rotationX
        + "\nY:\t" + camera.rotationY
        + "\nZ:\t" + camera.rotationZ
        + "\n\nCamera Local Rotation:"
        + "\nX:\t" + camera.localRotationX
        + "\nY:\t" + camera.localRotationY
        + "\nZ:\t" + camera.localRotationZ;
    }
  }
}

Download