チェンジセット 969
- コミット日時:
- 2008/08/14 02:27:58 (3 ヶ月前)
- ファイル:
-
- as3/FLARToolKit/trunk/samples/FLARToolKitTest2.as (更新) (4 diffs)
- as3/FLARToolKit/trunk/samples/FLARToolKitTest2.swf (更新) (変更前)
- as3/FLARToolKit/trunk/samples/PV3DARApp.as (追加)
- as3/FLARToolKit/trunk/src/com/libspark/flartoolkit/core/FLARMat.as (更新) (1 diff)
- as3/FLARToolKit/trunk/src/com/libspark/flartoolkit/scene/FLARCamera3D.as (更新) (2 diffs)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/FLARToolKit/trunk/samples/FLARToolKitTest2.as
r479 r969 2 2 3 3 import com.libspark.flartoolkit.core.FLARTransMatResult; 4 import com.libspark.flartoolkit.scene.FLARBaseNode; 4 5 import com.libspark.flartoolkit.scene.FLARCamera3D; 5 6 … … 15 16 import org.papervision3d.materials.shadematerials.FlatShadeMaterial; 16 17 import org.papervision3d.materials.utils.MaterialsList; 17 import org.papervision3d.objects.DisplayObject3D;18 18 import org.papervision3d.objects.primitives.Cube; 19 19 import org.papervision3d.objects.primitives.Plane; 20 20 import org.papervision3d.render.LazyRenderEngine; 21 21 import org.papervision3d.scenes.Scene3D; 22 import org.papervision3d.view.BasicView; 22 23 import org.papervision3d.view.Viewport3D; 23 24 24 25 25 [SWF(width=640,height=480,frameRate= 60,backgroundColor=0x0)]26 [SWF(width=640,height=480,frameRate=120,backgroundColor=0x0)] 26 27 27 public class FLARToolKitTest2 extends ARAppBase{28 public class FLARToolKitTest2 extends PV3DARApp { 28 29 29 30 private static const PATTERN_FILE:String = "Data/patt.hiro"; 30 31 private static const CAMERA_FILE:String = "Data/camera_para.dat"; 31 32 32 private var _base:Sprite; 33 private var _scene:Scene3D; 34 private var _camera3d:FLARCamera3D; 35 private var _viewport:Viewport3D; 36 private var _renderer:LazyRenderEngine; 37 38 private var _transGrp:DisplayObject3D; 39 private var _basePlane:Plane; 33 private var _plane:Plane; 40 34 private var _cube:Cube; 41 42 private var _resultMat:FLARTransMatResult = new FLARTransMatResult();43 44 private var _isMirror:Boolean = false;45 46 35 47 36 public function FLARToolKitTest2() { … … 50 39 51 40 this.addEventListener(Event.INIT, this._onInit); 52 this.init(CAMERA_FILE, PATTERN_FILE , 320, 240);41 this.init(CAMERA_FILE, PATTERN_FILE); 53 42 } 54 43 … … 56 45 this.removeEventListener(Event.INIT, this._onInit); 57 46 58 this._base = this.addChild(new Sprite()) as Sprite; 47 var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2); 48 wmat.doubleSided = true; 49 this._plane = new Plane(wmat, 80, 80); 50 this._baseNode.addChild(this._plane); 59 51 60 this._capture.width = 640; 61 this._capture.height = 480; 62 this._base.addChild(this._capture); 52 var light:PointLight3D = new PointLight3D(); 53 light.x = 1000; 54 light.y = 1000; 55 light.z = -1000; 56 var fmat:FlatShadeMaterial = new FlatShadeMaterial(light, 0xff22aa, 0x0); 57 this._cube = new Cube(new MaterialsList({ all: fmat }), 40, 40, 40); 58 this._cube.z += 20; 59 this._baseNode.addChild(this._cube); 63 60 64 this._viewport = this._base.addChild(new Viewport3D(320, 240, false, false, false, false)) as Viewport3D;65 this._viewport.scaleX = 640 / 320;66 this._viewport.scaleY = 480 / 240;67 this._viewport.x = -4; // 4pix ???68 69 this._camera3d = new FLARCamera3D(this._viewport, this._param);70 71 this._scene = new Scene3D();72 this._transGrp = this._scene.addChild(new DisplayObject3D()) as DisplayObject3D;73 var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2);74 wmat.doubleSided = true;75 this._basePlane = new Plane(wmat, 80, 80);76 this._transGrp.addChild(this._basePlane);77 var light:PointLight3D = new PointLight3D();78 light.x = 1000;79 light.y = 1000;80 light.z = -1000;81 var fmat:FlatShadeMaterial = new FlatShadeMaterial(light, 0xff22aa, 0x0);82 this._cube = new Cube(new MaterialsList({ all: fmat }), 40, 40, 40);83 this._cube.z += 20;84 this._transGrp.addChild(this._cube);85 86 this._renderer = new LazyRenderEngine(this._scene, this._camera3d, this._viewport);87 88 this.addChild(new FPSMeter());89 90 this.addEventListener(Event.ENTER_FRAME, this._onEnterFrame);91 61 this.stage.addEventListener(MouseEvent.CLICK, this._onClick); 92 62 } 93 63 94 private function _onEnterFrame(e:Event = null):void {95 this._capture.bitmapData.draw(this._video);96 if (this._detector.detectMarkerLite(this._raster, 80)) {97 this._detector.getTranslationMatrix(this._resultMat);98 var a:Array = this._resultMat.getArray();99 var mtx:Matrix3D = this._transGrp.transform;100 mtx.n11 = a[0][1]; mtx.n12 = a[0][0]; mtx.n13 = a[0][2]; mtx.n14 = a[0][3];101 mtx.n21 = -a[1][1]; mtx.n22 = -a[1][0]; mtx.n23 = -a[1][2]; mtx.n24 = -a[1][3];102 mtx.n31 = a[2][1]; mtx.n32 = a[2][0]; mtx.n33 = a[2][2]; mtx.n34 = a[2][3];103 this._renderer.render();104 }105 }106 107 64 private function _onClick(e:MouseEvent):void { 108 this._isMirror = !this._isMirror; 109 if (this._isMirror) { 110 this._base.scaleX = -1; 111 this._base.x = 640; 112 } else { 113 this._base.scaleX = 1; 114 this._base.x = 0; 115 } 65 this.mirror = !this.mirror; 116 66 } 117 67 as3/FLARToolKit/trunk/src/com/libspark/flartoolkit/core/FLARMat.as
r481 r969 376 376 */ 377 377 public function matrixDisp():int { 378 FLARException.trap("未チェックのパス"); 379 // System.out.println(" === matrix ("+row+","+clm+") ===");//printf(" === matrix (%d,%d) ===\n", m->row, m->clm); 380 // for (int r = 0; r < row; r++) {//for (int r = 0; r < m->row; r++) { 381 // System.out.print(" |");//printf(" |"); 382 // for (int c = 0; c < clm; c++) {//for (int c = 0; c < m->clm; c++) { 383 // System.out.print(" "+m[r][c]);//printf(" %10g", ARELEM0(m, r, c)); 384 // } 385 // System.out.println(" |");//printf(" |\n"); 386 // } 387 // System.out.println(" ======================");//printf(" ======================\n"); 378 var out:String = ''; 379 out += " === matrix ("+row+","+clm+") ===\n"; 380 for (var r:int = 0; r < row; r++) {//for (int r = 0; r < m->row; r++) { 381 out += ' |'; 382 for (var c:int = 0; c < clm; c++) {//for (int c = 0; c < m->clm; c++) { 383 out += " " + (int(m[r][c] * 1000) / 1000); 384 } 385 out += " |\n"; 386 } 387 out += " ======================"; 388 trace(out); 388 389 return 0; 389 390 } as3/FLARToolKit/trunk/src/com/libspark/flartoolkit/scene/FLARCamera3D.as
r481 r969 35 35 import com.libspark.flartoolkit.util.ArrayUtil; 36 36 37 import org.papervision3d.cameras.FrustumCamera3D; 37 import flash.geom.Matrix; 38 39 import org.papervision3d.cameras.Camera3D; 38 40 import org.papervision3d.core.math.Matrix3D; 39 41 import org.papervision3d.core.proto.CameraObject3D; 40 42 import org.papervision3d.view.Viewport3D; 41 43 42 public class FLARCamera3D extends FrustumCamera3D {44 public class FLARCamera3D extends Camera3D { 43 45 44 46 private static const NEAR_CLIP:Number = 10; 45 47 private static const FAR_CLIP:Number = 10000; 46 48 47 public function FLARCamera3D( viewport3D:Viewport3D,param:FLARParam) {48 super( viewport3D);49 public function FLARCamera3D(param:FLARParam) { 50 super(); 49 51 this.z = 0; 50 52 51 var m_projection:Array = new Array(16); //new double[16];53 var m_projection:Array = new Array(16); 52 54 var trans_mat:FLARMat = new FLARMat(3,4); 53 55 var icpara_mat:FLARMat = new FLARMat(3,4); 54 var p:Array = ArrayUtil.createMultidimensionalArray(3, 3); //new double[3][3], q=new double[4][4];56 var p:Array = ArrayUtil.createMultidimensionalArray(3, 3); 55 57 var q:Array = ArrayUtil.createMultidimensionalArray(4, 4); 56 58 var width:int; … … 111 113 } 112 114 115 this.useProjectionMatrix = true; 116 // 巣の GreatWhite のままだと _projection が Camera3D の private プロパティなのでエラる。 117 // ので protected とかにしてください。無理やり。害はない。つーかまーそれ以外に方法がない。 113 118 this._projection = new Matrix3D(m_projection); 114 119 } 115 120 121 override public function transformView(transform:Matrix3D=null):void { 122 // Camera3D の transformView はいらんことしやがるので super.transformView() しない。 123 // ただし CameraObject3D の transformView は必要なのでそこでやってる処理をここに移植。 124 this.eye.calculateMultiply(this.transform, _flipY ); 125 this.eye.invert(); 126 this.eye.calculateMultiply4x4(this._projection, this.eye); 127 } 128 129 // これも Camera3D の private になってるのでここにコピー。Camera3D のんを protected とかに変更でもいいけど。 130 static private var _flipY :Matrix3D = Matrix3D.scaleMatrix( 1, -1, 1 ); 116 131 } 117 132
