Develop and Download Open Source Software

Browse Subversion Repository

Contents of /nyar4psg/trunk/src/src/jp/nyatla/nyar4psg/NyARPsgBaseClass.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 814 - (show annotations) (download) (as text)
Sat Apr 16 16:28:43 2011 UTC (12 years, 11 months ago) by nyatla
Original Path: nyar4psg/trunk/src/jp/nyatla/nyar4psg/NyARPsgBaseClass.java
File MIME type: text/x-java
File size: 11720 byte(s)
NyAR4psg/0.4.1

NyARToolkit/3.0.0対応、MultiMarker対応
コードのみ実装。マニュアルまだ

1 /*
2 * PROJECT: NyARToolkit for proce55ing.
3 * --------------------------------------------------------------------------------
4 * The MIT License
5 * Copyright (c) 2008 nyatla
6 * airmail(at)ebony.plala.or.jp
7 * http://nyatla.jp/nyartoolkit/
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 *
26 */
27
28 package jp.nyatla.nyar4psg;
29
30
31 import processing.core.*;
32
33 import jp.nyatla.nyartoolkit.*;
34 import jp.nyatla.nyartoolkit.core.param.*;
35 import jp.nyatla.nyartoolkit.core.transmat.*;
36 import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix44;
37
38 class NyPsUtils
39 {
40 public static void dumpObject(PMatrix3D i_mat)
41 {
42 PApplet.println("PMatrix3D");
43 PApplet.println(String.format("%f %f %f %f",i_mat.m00,i_mat.m01,i_mat.m02,i_mat.m03));
44 PApplet.println(String.format("%f %f %f %f",i_mat.m10,i_mat.m11,i_mat.m12,i_mat.m13));
45 PApplet.println(String.format("%f %f %f %f",i_mat.m20,i_mat.m21,i_mat.m22,i_mat.m23));
46 PApplet.println(String.format("%f %f %f %f",i_mat.m30,i_mat.m31,i_mat.m32,i_mat.m33));
47 }
48 public static void dumpObject(double[] i_val)
49 {
50 PApplet.println("double[]");
51 for(int i=0;i<i_val.length;i++){
52 PApplet.println(i_val[i]);
53 }
54 }
55 }
56
57 /**
58 * ���������������������NyARToolkit for Processing������������������������������
59 * ARToolkit���������������������������������������������������������������������������������������������
60 */
61 class NyARPsgBaseClass
62 {
63 /**
64 * ���������������������������������������������������������������������
65 * RightHand���������������������������������
66 * RightHand���������������ARToolKit������������������������������������������Processing���������������������������������������������������������������text������������������������������������������
67 * <br/>EN: -
68 */
69 public final static int CS_RIGHT_HAND=0;
70 /**
71 * ���������������������������������������������������������������������
72 * LeftHand������������������������������
73 * RightHand���������������ARToolKit������������������������������������������Processing������������������������������������������
74 * processing������������������������������������������������������������������������
75 * <br/>EN: -
76 */
77 public final static int CS_LEFT_HAND =1;
78 /**
79 * ���������������������������������
80 * NyAR4psg������������������������������������������
81 * <br/>EN:
82 * version string.
83 */
84 public final String VERSION = "NyAR4psg/0.4.1;NyARToolkit for java/3.0.0;ARToolKit/2.72.1";
85 /**
86 * OpenGL���������������ProjectionMatrix���������
87 * <br/>EN:
88 * OpenGL form projection matrix.
89 */
90 public final double[] projection=new double[16];
91 /**
92 * Processing���������������ProjectionMatrix���������
93 */
94 protected PMatrix3D _ps_projection=new PMatrix3D();
95 /**
96 * ������������Applet������������������������������
97 */
98 protected PApplet _ref_papplet;
99 /**
100 * ARToolkit���������������������������������������������
101 */
102 protected NyARParam _ar_param;
103 protected NyARFrustum _frustum;
104 protected int _coord_system;
105 protected NyARPsgBaseClass(PApplet parent,String i_cparam_file, int i_width,int i_height,int i_coord_system)
106 {
107 checkCoordinateSystemRange(parent,i_coord_system);
108 this._ref_papplet=parent;
109 this._coord_system=i_coord_system;
110 try{
111 this._frustum=new NyARFrustum();
112 this._ar_param=new NyARParam();
113 this._ar_param.loadARParam(this._ref_papplet.createInput(i_cparam_file));
114 this._ar_param.changeScreenSize(i_width, i_height);
115
116 //Processing���projectionMatrix���������������Frustum���������
117 arPerspectiveMat2Projection(this._ar_param.getPerspectiveProjectionMatrix(),i_width,i_height,this._ps_projection,this.projection,this._frustum);
118 }catch(NyARException e){
119 this._ref_papplet.die("Error while setting up NyARToolkit for java", e);
120 }
121 return;
122 }
123 private final static double view_distance_min = 100;
124 private final static double view_distance_max = 100000;
125 private final static void checkCoordinateSystemRange(PApplet i_pa,int i_cs)
126 {
127 switch(i_cs){
128 case NyARPsgBaseClass.CS_LEFT_HAND:
129 case NyARPsgBaseClass.CS_RIGHT_HAND:
130 return;
131 default:
132 i_pa.die("Please set constant CS_LEFT_HAND or CS_RIGHT_HAND.");
133 }
134 }
135 private static void arPerspectiveMat2Projection(NyARPerspectiveProjectionMatrix i_prjmat,int i_w,int i_h,PMatrix3D o_projection,double[] o_gl_projection,NyARFrustum o_frustum)
136 {
137 NyARDoubleMatrix44 tmp=new NyARDoubleMatrix44();
138 i_prjmat.makeCameraFrustumRH(i_w, i_h, view_distance_min, view_distance_max,tmp);
139 o_projection.m00=(float)(o_gl_projection[ 0]=tmp.m00);
140 o_projection.m01=(float)(o_gl_projection[ 1]=tmp.m10);
141 o_projection.m02=(float)(o_gl_projection[ 2]=tmp.m20);
142 o_projection.m03=(float)(o_gl_projection[ 3]=tmp.m30);
143 o_projection.m10=(float)(o_gl_projection[ 4]=tmp.m01);
144 o_projection.m11=(float)(o_gl_projection[ 5]=tmp.m11);
145 o_projection.m12=(float)(o_gl_projection[ 6]=tmp.m21);
146 o_projection.m13=(float)(o_gl_projection[ 7]=tmp.m31);
147 o_projection.m20=(float)(o_gl_projection[ 8]=tmp.m02);
148 o_projection.m21=(float)(o_gl_projection[ 9]=tmp.m12);
149 o_projection.m22=(float)(o_gl_projection[10]=tmp.m22);
150 o_projection.m23=(float)(o_gl_projection[11]=tmp.m32);
151 o_projection.m30=(float)(o_gl_projection[12]=tmp.m03);
152 o_projection.m31=(float)(o_gl_projection[13]=tmp.m13);
153 o_projection.m32=(float)(o_gl_projection[14]=tmp.m23);
154 o_projection.m33=(float)(o_gl_projection[15]=tmp.m33);
155 o_frustum.setValue(tmp, i_w, i_h);
156 }
157 protected static void matResult2GLArray(NyARTransMatResult i_src,double[] o_gl_array)
158 {
159 o_gl_array[0 + 0 * 4] = i_src.m00;
160 o_gl_array[0 + 1 * 4] = i_src.m01;
161 o_gl_array[0 + 2 * 4] = i_src.m02;
162 o_gl_array[0 + 3 * 4] = i_src.m03;
163 o_gl_array[1 + 0 * 4] = -i_src.m10;
164 o_gl_array[1 + 1 * 4] = -i_src.m11;
165 o_gl_array[1 + 2 * 4] = -i_src.m12;
166 o_gl_array[1 + 3 * 4] = -i_src.m13;
167 o_gl_array[2 + 0 * 4] = -i_src.m20;
168 o_gl_array[2 + 1 * 4] = -i_src.m21;
169 o_gl_array[2 + 2 * 4] = -i_src.m22;
170 o_gl_array[2 + 3 * 4] = -i_src.m23;
171 o_gl_array[3 + 0 * 4] = 0.0;
172 o_gl_array[3 + 1 * 4] = 0.0;
173 o_gl_array[3 + 2 * 4] = 0.0;
174 o_gl_array[3 + 3 * 4] = 1.0;
175 }
176 /**
177 * ���������������������������
178 */
179 private final static PMatrix3D _lh_mat=new PMatrix3D(-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);
180
181 /**
182 * ���������������Processing���Matrix���������������������
183 * @param i_src
184 * @param i_mode
185 * @param o_pmatrix
186 */
187 protected static void matResult2PMatrix3D(NyARTransMatResult i_src,int i_mode,PMatrix3D o_pmatrix)
188 {
189 o_pmatrix.m00 = (float)i_src.m00;
190 o_pmatrix.m01 = (float)i_src.m01;
191 o_pmatrix.m02 = (float)i_src.m02;
192 o_pmatrix.m03 = (float)i_src.m03;
193 o_pmatrix.m10 = (float)i_src.m10;//mirror
194 o_pmatrix.m11 = (float)i_src.m11;//mirror
195 o_pmatrix.m12 = (float)i_src.m12;//mirror
196 o_pmatrix.m13 = (float)i_src.m13;//mirror
197 o_pmatrix.m20 = (float)-i_src.m20;
198 o_pmatrix.m21 = (float)-i_src.m21;
199 o_pmatrix.m22 = (float)-i_src.m22;
200 o_pmatrix.m23 = (float)-i_src.m23;
201 o_pmatrix.m30 = 0.0f;
202 o_pmatrix.m31 = 0.0f;
203 o_pmatrix.m32 = 0.0f;
204 o_pmatrix.m33 = 1.0f;
205 if(i_mode==MultiARTookitMarker.CS_LEFT_HAND)
206 {
207 o_pmatrix.apply(_lh_mat);
208 }
209 }
210 /**
211 * ������������������������������������������������������������������������������
212 * ���������������������������������������������������������������
213 * <p>������ -
214 * ������������������gluUnproject������������������������������������������������������������������������������
215 * ���������������������������������������������
216 * http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml
217 * ARToolKit���������������������������������������������OpenGL���unProject������ix,iy���������������������������������������������������������������������������������������
218 * </p>
219 * @param ix
220 * ���������������������������
221 * @param iy
222 * ������������������
223 * @param o_point_on_screen
224 * ���������������
225 */
226 /* public final PVector unProject(double ix,double iy)
227 {
228 double n=(this._frustum_rh.m23/(this._frustum_rh.m22-1));
229 NyARDoubleMatrix44 m44=this._inv_frustum_rh;
230 double v1=(this._screen_size.w-ix-1)*2/this._screen_size.w-1.0;//ARToolKit���Frustram������������������
231 double v2=(this._screen_size.h-iy-1)*2/this._screen_size.h-1.0;
232 double v3=2*n-1.0;
233 double b=1/(m44.m30*v1+m44.m31*v2+m44.m32*v3+m44.m33);
234 o_point_on_screen.x=(m44.m00*v1+m44.m01*v2+m44.m02*v3+m44.m03)*b;
235 o_point_on_screen.y=(m44.m10*v1+m44.m11*v2+m44.m12*v3+m44.m13)*b;
236 o_point_on_screen.z=(m44.m20*v1+m44.m21*v2+m44.m22*v3+m44.m23)*b;
237 return;
238 }
239 */ /**
240 * ���������������������������������������������������������������������������������������������������������������������������������������������������������
241 * ���������������������������������������������
242 * @param ix
243 * ���������������������������
244 * @param iy
245 * ���������������������������
246 * @param i_mat
247 * ������������������������������
248 * @param o_pos
249 * ������������������������������������������������
250 */
251 /* public final PVector unProjectOnCamera(double ix,double iy,PMatrix3D i_mat)
252 {
253 //������������������
254 this.unProject(ix,iy,o_pos);
255 //������������������������������
256 double nx=i_mat.m02;
257 double ny=i_mat.m12;
258 double nz=i_mat.m22;
259 double mx=i_mat.m03;
260 double my=i_mat.m13;
261 double mz=i_mat.m23;
262 double t=(nx*mx+ny*my+nz*mz)/(nx*o_pos.x+ny*o_pos.y+nz*o_pos.z);
263 o_pos.x=t*o_pos.x;
264 o_pos.y=t*o_pos.y;
265 o_pos.z=t*o_pos.z;
266 }
267 */ /**
268 * ������������������������������������������������������������������������������������������������������������������������
269 * ARToolKit������P175���������������������������������
270 * @param ix
271 * ���������������������������
272 * @param iy
273 * ���������������������������
274 * @param i_mat
275 * ������������������������������
276 * @param o_pos
277 * ������������������������������������������������
278 * @return
279 * ���������������������������true������������������
280 */
281 /* public final PVector unProjectOnMatrix(double ix,double iy,PMatrix3D i_mat)
282 {
283 //������������������������������������
284 unProjectOnCamera(ix,iy,i_mat,o_pos);
285 //������������������
286 NyARDoubleMatrix44 m=new NyARDoubleMatrix44();
287 if(!m.inverse(i_mat)){
288 return false;
289 }
290 m.transform3d(o_pos, o_pos);
291 return true;
292 }
293 */ /**
294 * ������������������������������������������������������������������������������
295 * @param i_x
296 * ������������������������
297 * @param i_y
298 * ������������������������
299 * @param i_z
300 * ������������������������
301 * @param o_pos2d
302 * ������������������������������������������������
303 */
304 /* public final PVector project(double i_x,double i_y,double i_z)
305 {
306 NyARDoubleMatrix44 m=this._frustum_rh;
307 double v3_1=1/i_z*m.m32;
308 double w=this._screen_size.w;
309 double h=this._screen_size.h;
310 o_pos2d.x=w-(1+(i_x*m.m00+i_z*m.m02)*v3_1)*w/2;
311 o_pos2d.y=h-(1+(i_y*m.m11+i_z*m.m12)*v3_1)*h/2;
312 return;
313 }
314 */}
315

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26