チェンジセット 1341

差分発生行の前後
無視リスト:
コミット日時:
2008/09/19 17:32:51 (4 ヶ月前)
コミッタ:
tarotarorg
ログメッセージ:

PV3Dのモデルを使った、「あっちの世界の覗き窓」を作成中。
※まだ完成していない

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/FLARToolKit/trunk/samples/org/tarotaro/flash/ar/FLARAnotherWorldWindowLayer.as

    r1332 r1341  
    1616package org.tarotaro.flash.ar  
    1717{ 
    18         import flash.display.Bitmap; 
    19         import flash.display.BitmapData; 
    20         import flash.geom.Point; 
    21         import flash.geom.Transform; 
    22         import org.libspark.flartoolkit.core.FLARCode; 
    23         import org.libspark.flartoolkit.core.FLARParam; 
    24         import org.libspark.flartoolkit.core.FLARSquare; 
    25         import org.libspark.flartoolkit.core.FLARTransMatResult; 
    26         import org.libspark.flartoolkit.core.raster.FLARBitmapData; 
    27         import org.papervision3d.cameras.Camera3D; 
    28         import org.papervision3d.cameras.CameraType; 
    29         import org.papervision3d.core.math.Matrix3D; 
    30         import org.papervision3d.materials.BitmapMaterial; 
    31         import org.papervision3d.objects.primitives.Sphere; 
     18        import org.papervision3d.objects.DisplayObject3D; 
    3219        import org.papervision3d.view.BasicView; 
    3320        import org.tarotaro.flash.ar.layers.FLARSingleMarkerLayer; 
     
    3926        public class FLARAnotherWorldWindowLayer extends FLARSingleMarkerLayer 
    4027        { 
    41                 private var _matrix:Matrix3D; 
     28                private var _model:DisplayObject3D; 
    4229                private var _view:BasicView; 
    43  
     30                /** 
     31                 *  
     32                 * @param       src                             マーカーを探す対象となる画像データ 
     33                 * @param       param                   カメラ用パラメータ 
     34                 * @param       code                    マーカーパターン 
     35                 * @param       markerWidth             マーカーの幅。マーカーは正方形なので、高さもこれと同じになる。 
     36                 * @param       model                   表示したいモデル。原点を中心にしたモデルであることが望ましい。 
     37                 * @param       windowWidth             表示領域の幅 
     38                 * @param       windowHeight    表示領域の高さ 
     39                 * @param       thresh                  マーカー検出時の閾値 
     40                 */ 
    4441                public function FLARAnotherWorldWindowLayer(src:FLARBitmapData, 
    4542                                                                                                        param:FLARParam, 
    4643                                                                                                        code:FLARCode, 
    4744                                                                                                        markerWidth:Number, 
    48                                                                                                         panorama:BitmapData
     45                                                                                                        model:DisplayObject3D
    4946                                                                                                        windowWidth:Number = 640, 
    5047                                                                                                        windowHeight:Number = 480, 
     
    5249                { 
    5350                        super(src, param, code, markerWidth, thresh); 
    54                          
     51 
    5552                        //Viewの作成 
    56                         this._view = new BasicView(windowWidth, windowHeight, true, false, CameraType.FREE); 
     53                        this._view = new BasicView(windowWidth, windowHeight, true, false); 
    5754                        this.addChild(this._view); 
     55 
     56                        //モデルの配置 
     57                        this._model = model; 
     58                        this._view.scene.addChild(this._model); 
    5859 
    5960                        //カメラのセッティング 
    6061                        this._view.camera.focus = 300; 
    6162                        this._view.camera.zoom = 1; 
    62  
    63                         //パノラマ球体の構築 
    64                         //1.パノラマ用のマテリアルを作成 
    65                         var panoramaMaterial:BitmapMaterial = new BitmapMaterial(panorama, false); 
    66                         panoramaMaterial.opposite = true; 
    67                         panoramaMaterial.smooth = true; 
    68                         //2.球体を作成 
    69                         var panoSphere:Sphere = new Sphere(panoramaMaterial, 25000, 30, 30); 
    70                         //3.シーンに追加 
    71                         this._view.scene.addChild(panoSphere,"panorama"); 
     63                        this._view.camera.z = -100; 
    7264                         
    7365                        //4.レンダリング開始 
    7466                        this._view.startRendering(); 
    7567                } 
    76                  
     68 
    7769                override public function update():void  
    7870                { 
     
    9082                                var center:Point = new Point((Mx + mx)/2, (My+my)/2); 
    9183 
    92                                 this._view.camera.rotationY = (center.x - this._source.getWidth()/2) * 0.6; 
    93                                 this._view.camera.rotationX = -(center.y - this._source.getHeight()/2) * 0.6; 
    94                                 trace(this._view.camera.rotationY, this._view.camera.rotationX); 
    95                                 //マーカの大きさから、ズームを判定する 
    96                                 //900-45000 
    97                                 this._view.camera.zoom = 1 + square.area / 9000; 
     84                                this._view.camera.x = (center.x - this._source.getWidth() / 2); 
     85                                this._view.camera.y = (center.y - this._source.getHeight() / 2); 
     86                                this._view.camera.z = -100 - (45000 - square.area); 
    9887                        } else { 
    9988                                 
    10089                        } 
    101  
    102                         //this._view.camera.rotationY += (480 * mouseX/(this._view.width) - this._view.camera.rotationY) * .1; 
    103                         //this._view.camera.rotationX += (180 * mouseY/(this._view.height) - 90 - this._view.camera.rotationX) * .1; 
    104  
    105                 } 
    106                 private function setTranslationMatrix(mtx:Matrix3D):void { 
    107                         var a:Array = this._resultMat.getArray(); 
    108                         mtx.n11 =  a[0][1];     mtx.n12 =  a[0][0];     mtx.n13 =  a[0][2];     mtx.n14 =  a[0][3]; 
    109                         mtx.n21 = -a[1][1];     mtx.n22 = -a[1][0];     mtx.n23 = -a[1][2];     mtx.n24 = -a[1][3]; 
    110                         mtx.n31 =  a[2][1];     mtx.n32 =  a[2][0];     mtx.n33 =  a[2][2];     mtx.n34 =  a[2][3]; 
    11190                } 
    11291