チェンジセット 969

差分発生行の前後
無視リスト:
コミット日時:
2008/08/14 02:27:58 (3 ヶ月前)
コミッタ:
saqoosha
ログメッセージ:

FLARToolKitTest2.as を最新版の PV3D GreatWhite? でも動くように。でも完全じゃなくって、GreatWhite? にもちょっと手をいれないといけない。。

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/FLARToolKit/trunk/samples/FLARToolKitTest2.as

    r479 r969  
    22         
    33        import com.libspark.flartoolkit.core.FLARTransMatResult; 
     4        import com.libspark.flartoolkit.scene.FLARBaseNode; 
    45        import com.libspark.flartoolkit.scene.FLARCamera3D; 
    56         
     
    1516        import org.papervision3d.materials.shadematerials.FlatShadeMaterial; 
    1617        import org.papervision3d.materials.utils.MaterialsList; 
    17         import org.papervision3d.objects.DisplayObject3D; 
    1818        import org.papervision3d.objects.primitives.Cube; 
    1919        import org.papervision3d.objects.primitives.Plane; 
    2020        import org.papervision3d.render.LazyRenderEngine; 
    2121        import org.papervision3d.scenes.Scene3D; 
     22        import org.papervision3d.view.BasicView; 
    2223        import org.papervision3d.view.Viewport3D; 
    2324         
    2425 
    25         [SWF(width=640,height=480,frameRate=60,backgroundColor=0x0)] 
     26        [SWF(width=640,height=480,frameRate=120,backgroundColor=0x0)] 
    2627 
    27         public class FLARToolKitTest2 extends ARAppBase
     28        public class FLARToolKitTest2 extends PV3DARApp
    2829                 
    2930                private static const PATTERN_FILE:String = "Data/patt.hiro"; 
    3031                private static const CAMERA_FILE:String = "Data/camera_para.dat"; 
    3132                 
    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; 
    4034                private var _cube:Cube; 
    41                  
    42                 private var _resultMat:FLARTransMatResult = new FLARTransMatResult(); 
    43                  
    44                 private var _isMirror:Boolean = false; 
    45                  
    4635                 
    4736                public function FLARToolKitTest2() { 
     
    5039                         
    5140                        this.addEventListener(Event.INIT, this._onInit); 
    52                         this.init(CAMERA_FILE, PATTERN_FILE, 320, 240); 
     41                        this.init(CAMERA_FILE, PATTERN_FILE); 
    5342                } 
    5443                 
     
    5645                        this.removeEventListener(Event.INIT, this._onInit); 
    5746                         
    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); 
    5951                         
    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); 
    6360                         
    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); 
    9161                        this.stage.addEventListener(MouseEvent.CLICK, this._onClick); 
    9262                } 
    9363                 
    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                  
    10764                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; 
    11666                } 
    11767                 
  • as3/FLARToolKit/trunk/src/com/libspark/flartoolkit/core/FLARMat.as

    r481 r969  
    376376             */ 
    377377            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); 
    388389                return 0; 
    389390            } 
  • as3/FLARToolKit/trunk/src/com/libspark/flartoolkit/scene/FLARCamera3D.as

    r481 r969  
    3535        import com.libspark.flartoolkit.util.ArrayUtil; 
    3636         
    37         import org.papervision3d.cameras.FrustumCamera3D; 
     37        import flash.geom.Matrix; 
     38         
     39        import org.papervision3d.cameras.Camera3D; 
    3840        import org.papervision3d.core.math.Matrix3D; 
    3941        import org.papervision3d.core.proto.CameraObject3D; 
    4042        import org.papervision3d.view.Viewport3D; 
    4143 
    42         public class FLARCamera3D extends FrustumCamera3D { 
     44        public class FLARCamera3D extends Camera3D { 
    4345                 
    4446                private static const NEAR_CLIP:Number = 10; 
    4547                private static const FAR_CLIP:Number = 10000; 
    4648                 
    47                 public function FLARCamera3D(viewport3D:Viewport3D, param:FLARParam) { 
    48                         super(viewport3D); 
     49                public function FLARCamera3D(param:FLARParam) { 
     50                        super(); 
    4951                        this.z = 0; 
    5052                         
    51                         var m_projection:Array = new Array(16);//new double[16]; 
     53                        var m_projection:Array = new Array(16); 
    5254                        var trans_mat:FLARMat = new FLARMat(3,4); 
    5355                        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); 
    5557                        var q:Array = ArrayUtil.createMultidimensionalArray(4, 4); 
    5658                        var width:int; 
     
    111113                        } 
    112114                         
     115                        this.useProjectionMatrix = true; 
     116                        // 巣の GreatWhite のままだと _projection が Camera3D の private プロパティなのでエラる。 
     117                        // ので protected とかにしてください。無理やり。害はない。つーかまーそれ以外に方法がない。 
    113118                        this._projection = new Matrix3D(m_projection); 
    114119                } 
    115120                 
     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 ); 
    116131        } 
    117132