Advertisement
ealbinu

SimpleCube.as

Apr 18th, 2011
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.    
  3.     import flash.events.Event;
  4.     import flash.events.MouseEvent;
  5.    
  6.     import org.papervision3d.lights.PointLight3D;
  7.     import org.papervision3d.materials.WireframeMaterial;
  8.     import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
  9.     import org.papervision3d.materials.utils.MaterialsList;
  10.     import org.papervision3d.objects.primitives.Cube;
  11.     import org.papervision3d.objects.primitives.Plane;
  12.    
  13.     [SWF(width=640, height=480, backgroundColor=0x808080, frameRate=30)]
  14.    
  15.     public class SimpleCube extends PV3DARApp {
  16.        
  17.         private var _plane:Plane;
  18.         private var _cube:Cube;
  19.        
  20.         public function SimpleCube() {
  21.             // Initalize application with the path of camera calibration file and patter definition file.
  22.             // カメラ補正ファイルとパターン定義ファイルのファイル名を渡して初期化。
  23.             addEventListener(Event.INIT, _onInit);
  24.             init('Data/camera_para.dat', 'Data/flarlogo.pat');
  25.         }
  26.        
  27.         private function _onInit(e:Event):void {
  28.             // Create Plane with same size of the marker.
  29.             // マーカーと同じサイズを Plane を作ってみる。
  30.             var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2); // with wireframe. / ワイヤーフレームで。
  31.             _plane = new Plane(wmat, 80, 80); // 80mm x 80mm。
  32.             _plane.rotationX = 180;
  33.             _markerNode.addChild(_plane); // attach to _markerNode to follow the marker. / _markerNode に addChild するとマーカーに追従する。
  34.  
  35.             // Place the light at upper front.
  36.             // ライトの設定。手前、上のほう。
  37.             var light:PointLight3D = new PointLight3D();
  38.             light.x = 0;
  39.             light.y = 1000;
  40.             light.z = -1000;
  41.            
  42.             // Create Cube.
  43.             // Cube を作る。
  44.             var fmat:FlatShadeMaterial = new FlatShadeMaterial(light, 0xff22aa, 0x75104e); // Color is ping. / ピンク色。
  45.             _cube = new Cube(new MaterialsList({all: fmat}), 40, 40, 40); // 40mm x 40mm x 40mm
  46.             _cube.z = 20; // Move the cube to upper (minus Z) direction Half height of the Cube. / 立方体の高さの半分、上方向(-Z方向)に移動させるとちょうどマーカーにのっかる形になる。
  47.             _markerNode.addChild(_cube);
  48.            
  49.             stage.addEventListener(MouseEvent.CLICK, _onClick);
  50.         }
  51.        
  52.         private function _onClick(e:MouseEvent):void {
  53.             mirror = !mirror;
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement