root/as3/FLARToolKit/trunk/src/org/libspark/flartoolkit/core/param/FLARParam.as

リビジョン 4718, 5.5 kB (コミッタ: rokubou, コミット時期: 3 日 前)

FLARToolKit v4 core

Line 
1 /*
2  * PROJECT: FLARToolKit
3  * --------------------------------------------------------------------------------
4  * This work is based on the FLARToolKit developed by
5  *   R.Iizuka (nyatla)
6  * http://nyatla.jp/nyatoolkit/
7  *
8  * The FLARToolKit is ActionScript 3.0 version ARToolkit class library.
9  * Copyright (C)2008 Saqoosha
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  * For further information please contact.
25  *      http://www.libspark.org/wiki/saqoosha/FLARToolKit
26  *      <saq(at)saqoosha.net>
27  *
28  */
29 package org.libspark.flartoolkit.core.param
30 {
31         import org.libspark.flartoolkit.core.types.*;
32         import org.libspark.flartoolkit.core.types.matrix.*;
33         import flash.utils.*;
34        
35         /**
36          * typedef struct { int xsize, ysize; double mat[3][4]; double dist_factor[4]; } ARParam;
37          * FLARの動作パラメータを格納するクラス
38          *
39          */
40         public class FLARParam
41         {
42                 protected var _screen_size:FLARIntSize=new FLARIntSize();
43                 private static const SIZE_OF_PARAM_SET:int = 4 + 4 + (3 * 4 * 8) + (4 * 8);
44                 private var _dist:FLARCameraDistortionFactor =new FLARCameraDistortionFactor();
45                 private var _projection_matrix:FLARPerspectiveProjectionMatrix =new FLARPerspectiveProjectionMatrix();
46                 public function loadDefaultParameter():void
47                 {
48                         var tmp:Vector.<Number>=Vector.<Number>([318.5,263.5,26.2,1.0127565206658486]);
49                         this._screen_size.setValue(640,480);
50                         this._dist.setValue(tmp);
51                         this._projection_matrix.m00=700.9514702992245;
52                         this._projection_matrix.m01=0;
53                         this._projection_matrix.m02=316.5;
54                         this._projection_matrix.m03=0;
55                         this._projection_matrix.m10=0;
56                         this._projection_matrix.m11=726.0941816535367;
57                         this._projection_matrix.m12=241.5;
58                         this._projection_matrix.m13=0.0;
59                         this._projection_matrix.m20=0.0;
60                         this._projection_matrix.m21=0.0;
61                         this._projection_matrix.m22=1.0;
62                         this._projection_matrix.m23=0.0;
63                         this._projection_matrix.m30=0.0;
64                         this._projection_matrix.m31=0.0;
65                         this._projection_matrix.m32=0.0;
66                         this._projection_matrix.m33=1.0;
67                 }
68                 public function getScreenSize():FLARIntSize
69                 {
70                         return this._screen_size;
71                 }
72
73                 public function getPerspectiveProjectionMatrix():FLARPerspectiveProjectionMatrix
74                 {
75                         return this._projection_matrix;
76                 }
77                 public function getDistortionFactor():FLARCameraDistortionFactor
78                 {
79                         return this._dist;
80                 }
81                 /**
82                  *
83                  * @param i_factor
84                  * FLARCameraDistortionFactorにセットする配列を指定する。要素数は4であること。
85                  * @param i_projection
86                  * FLARPerspectiveProjectionMatrixセットする配列を指定する。要素数は12であること。
87                  */
88                 public function setValue(i_factor:Vector.<Number>,i_projection:Vector.<Number>):void
89                 {
90                         this._dist.setValue(i_factor);
91                         this._projection_matrix.setValue(i_projection);
92                         return;
93                 }
94                 /**
95                  * int arParamChangeSize( ARParam *source, int xsize, int ysize, ARParam *newparam );
96                  * 関数の代替関数 サイズプロパティをi_xsize,i_ysizeに変更します。
97                  * @param i_xsize
98                  * @param i_ysize
99                  * @param newparam
100                  * @return
101                  *
102                  */
103                 public function changeScreenSize(i_xsize:int,i_ysize:int):void
104                 {
105                         var scale:Number = Number(i_xsize) / Number(this._screen_size.w);// scale = (double)xsize / (double)(source->xsize);
106                         //スケールを変更
107                         this._dist.changeScale(scale);
108                         this._projection_matrix.changeScale(scale);
109                         this._screen_size.w = i_xsize;// newparam->xsize = xsize;
110                         this._screen_size.h = i_ysize;// newparam->ysize = ysize;
111                         return;
112                 }
113                 /**
114                  * この関数は、現在のスクリーンサイズを変更します。
115                  * {@link #changeScreenSize(int, int)のラッパーです。
116                  * @param i_s
117                  */
118                 public function changeScreenSize_2(i_s:FLARIntSize):void
119                 {
120                         this.changeScreenSize(i_s.w,i_s.h);
121                 }
122                 /**
123                  * 右手系の視錐台を作ります。
124                  * 計算結果を多用するときは、キャッシュするようにして下さい。
125                  * @param i_dist_min
126                  * @param i_dist_max
127                  * @param o_frustum
128                  */
129                 public function makeCameraFrustumRH(i_dist_min:Number,i_dist_max:Number,o_frustum:FLARDoubleMatrix44):void
130                 {
131                         this._projection_matrix.makeCameraFrustumRH(this._screen_size.w, this._screen_size.h, i_dist_min, i_dist_max, o_frustum);
132                         return;
133                 }
134                 public function loadARParam(i_stream:ByteArray):void
135                 {
136                         var tmp:Vector.<Number> = new Vector.<Number>(16);//new double[12];
137
138                         i_stream.endian = Endian.BIG_ENDIAN;
139                         this._screen_size.w = i_stream.readInt();//bb.getInt();
140                         this._screen_size.h = i_stream.readInt();//bb.getInt();
141                         //double値を12個読み込む
142                         var i:int;
143                         for(i = 0; i < 12; i++){
144                                 tmp[i] = i_stream.readDouble();//bb.getDouble();
145                         }
146                         //パディング
147                         tmp[12]=tmp[13]=tmp[14]=0;
148                         tmp[15]=1;                     
149                         //Projectionオブジェクトにセット
150                         this._projection_matrix.setValue(tmp);
151                         //double値を4個読み込む
152                         for (i = 0; i < 4; i++) {
153                                 tmp[i] = i_stream.readDouble();//bb.getDouble();
154                         }
155                         //Factorオブジェクトにセット
156                         this._dist.setValue(tmp);
157
158                         return;
159                 }
160         }
161 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。