[Papervision3D] 座標系 (1)

Papervision3Dを使って、座標系について調べてみるよ。 :boy:

pv3dCoordinates1

Papervision3Dは、左手座標系Y軸上向きだよ! :cake:

X軸(正値)は赤色、Y軸(正値)は緑色、Z軸(正値)は青色。オブジェクト正面に黄色の矩形を配置。

:caution: 要 Flash Player 11.8 以上

This movie requires Flash Player 11.8.0

Main.as
package {

  import flash.display.Sprite;
  import flash.display.StageScaleMode;
  import flash.display.StageAlign;
  import flash.events.Event;

  import org.papervision3d.Papervision3D;
  import org.papervision3d.scenes.Scene3D;
  import org.papervision3d.cameras.Camera3D;
  import org.papervision3d.view.Viewport3D;
  import org.papervision3d.render.BasicRenderEngine;
  import org.papervision3d.objects.DisplayObject3D;
  import org.papervision3d.core.geom.Lines3D;
  import org.papervision3d.core.geom.renderables.Line3D;
  import org.papervision3d.core.geom.renderables.Vertex3D;
  import org.papervision3d.materials.special.LineMaterial;
  import org.papervision3d.objects.primitives.Plane;
  import org.papervision3d.objects.primitives.Cube;
  import org.papervision3d.materials.ColorMaterial;
  import org.papervision3d.materials.utils.MaterialsList;


  [SWF(backgroundColor="#000000", width="600", height="600", frameRate="30")]

  public class Main extends Sprite {
    // プロパティ
    private var scene:Scene3D;
    private var camera:Camera3D;
    private var viewport:Viewport3D;
    private var renderer:BasicRenderEngine;
    private var axis:Lines3D;
    private var plane:Plane;
    private var cube:Cube;
    private var front:Plane;
    private static var radius:uint = 500;
    private var angle:Number = - 90;
    private var degree:Number = 0;
    private static var depression:uint = 30;
    private static var radian:Number = Math.PI/180;
    private static var center:DisplayObject3D = DisplayObject3D.ZERO;

    // コンストラクタ
    public function Main() {
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      init();
    }

    // メソッド
    private function init():void {
      scene = new Scene3D();
      camera = new Camera3D();
      viewport = new Viewport3D(600, 600, false, false);
      renderer = new BasicRenderEngine();

      setup();
      initialize();
      addChild(viewport);
      addEventListener(Event.ENTER_FRAME, render, false, 0, true);
    }
    private function setup():void {
      camera.x = 0;
      camera.y = 0;
      camera.z = - radius;
      camera.focus = radius;
      camera.zoom = 1;
      camera.target = center;
    }
    private function initialize():void {
      axis = new Lines3D();
      scene.addChild(axis);

      var wmaterial:LineMaterial = new LineMaterial(0xFFFFFF, 1);
      var rmaterial:LineMaterial = new LineMaterial(0xFF0000, 1);
      var gmaterial:LineMaterial = new LineMaterial(0x00FF00, 1);
      var bmaterial:LineMaterial = new LineMaterial(0x0000FF, 1);
      var xaxis0:Line3D = new Line3D(axis, wmaterial, 1, new Vertex3D(-240, 0, 0), new Vertex3D(0, 0, 0));
      var xaxis1:Line3D = new Line3D(axis, rmaterial, 2, new Vertex3D(0, 0, 0), new Vertex3D(240, 0, 0));
      axis.addLine(xaxis0);
      axis.addLine(xaxis1);
      var yaxis0:Line3D = new Line3D(axis, wmaterial, 1, new Vertex3D(0, -240, 0), new Vertex3D(0, 0, 0));
      var yaxis1:Line3D = new Line3D(axis, gmaterial, 2, new Vertex3D(0, 0, 0), new Vertex3D(0, 240, 0));
      axis.addLine(yaxis0);
      axis.addLine(yaxis1);
      var zaxis0:Line3D = new Line3D(axis, wmaterial, 1, new Vertex3D(0, 0, -240), new Vertex3D(0, 0, 0));
      var zaxis1:Line3D = new Line3D(axis, bmaterial, 2, new Vertex3D(0, 0, 0), new Vertex3D(0, 0, 240));
      axis.addLine(zaxis0);
      axis.addLine(zaxis1);

      var pmaterial:ColorMaterial = new ColorMaterial(0x999999, 0.8);
      pmaterial.doubleSided = false;
      plane = new Plane(pmaterial, 320, 320, 40, 40);
      scene.addChild(plane);

      plane.rotationX = 90;
      var cmaterial:ColorMaterial = new ColorMaterial(0xFFFFFF, 1);
      var materials:MaterialsList = new MaterialsList({"all": cmaterial});

      cube = new Cube(materials, 80, 80, 80, 10, 10, 10);
      scene.addChild(cube);

      var material:ColorMaterial = new ColorMaterial(0xFFFF00, 0.6);
      material.doubleSided = false;
      front = new Plane(material, 40, 32, 1, 1);
      scene.addChild(front);

      front.z = -250;
    }
    private function render(evt:Event):void {
      angle += 1;
      degree += 2;
      var dip:Number = depression*Math.sin(degree*radian);
      camera.x = radius*Math.cos(angle*radian)*Math.cos(dip*radian);
      camera.y = radius*Math.sin(dip*radian);
      camera.z = radius*Math.sin(angle*radian)*Math.cos(dip*radian);
      renderer.renderScene(scene, camera, viewport);
    }

  }

}

Flash CC + Flex 4 SDK でパブリッシュ。