| 1 |
nyatla |
420 |
/* |
| 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 |
nyatla |
814 |
|
| 31 |
nyatla |
971 |
|
| 32 |
nyatla |
420 |
import processing.core.*; |
| 33 |
|
|
|
| 34 |
nyatla |
971 |
import jp.nyatla.nyartoolkit.core.*; |
| 35 |
nyatla |
814 |
import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix44; |
| 36 |
nyatla |
420 |
|
| 37 |
|
|
|
| 38 |
nyatla |
820 |
|
| 39 |
nyatla |
420 |
/** |
| 40 |
nyatla |
814 |
* ���������������������NyARToolkit for Processing������������������������������ |
| 41 |
|
|
* ARToolkit��������������������������������������������������������������������������������������������� |
| 42 |
nyatla |
420 |
*/ |
| 43 |
nyatla |
1063 |
public abstract class NyARPsgBaseClass |
| 44 |
nyatla |
420 |
{ |
| 45 |
nyatla |
853 |
/** |
| 46 |
|
|
* near��������������������������������������������� |
| 47 |
|
|
*/ |
| 48 |
|
|
public final float FRUSTUM_DEFAULT_NEAR_CLIP=100; |
| 49 |
|
|
/** |
| 50 |
|
|
* far��������������������������������������������� |
| 51 |
|
|
*/ |
| 52 |
|
|
public final float FRUSTUM_DEFAULT_FAR_CLIP=100000; |
| 53 |
nyatla |
828 |
|
| 54 |
nyatla |
420 |
/** |
| 55 |
|
|
* ��������������������������������� |
| 56 |
nyatla |
814 |
* NyAR4psg������������������������������������������ |
| 57 |
nyatla |
420 |
*/ |
| 58 |
nyatla |
1105 |
public final static String VERSION = "NyAR4psg/1.2.1;NyARToolkit for java/4.1.0;ARToolKit/2.72.1"; |
| 59 |
nyatla |
820 |
/**���������������Applet������������������������������*/ |
| 60 |
|
|
protected PApplet _ref_papplet; |
| 61 |
nyatla |
854 |
/**���������������������������������ModelviewMatrix���������*/ |
| 62 |
|
|
protected final PMatrix3D _ps_background_mv=new PMatrix3D(); |
| 63 |
|
|
|
| 64 |
nyatla |
820 |
/**���ARToolkit���������������������������������������������*/ |
| 65 |
nyatla |
828 |
protected NyAR4PsgConfig _config; |
| 66 |
|
|
|
| 67 |
nyatla |
971 |
|
| 68 |
nyatla |
853 |
|
| 69 |
|
|
private float _clip_far; |
| 70 |
|
|
private float _clip_near; |
| 71 |
nyatla |
971 |
|
| 72 |
nyatla |
820 |
/** |
| 73 |
|
|
* ������������������������������ |
| 74 |
|
|
*/ |
| 75 |
|
|
protected NyARPsgBaseClass() |
| 76 |
nyatla |
420 |
{ |
| 77 |
nyatla |
820 |
} |
| 78 |
nyatla |
971 |
protected void initInstance(PApplet parent,NyAR4PsgConfig i_config) throws NyARException |
| 79 |
nyatla |
820 |
{ |
| 80 |
nyatla |
971 |
this._ref_papplet=parent; |
| 81 |
|
|
this._config=i_config; |
| 82 |
nyatla |
814 |
//Processing���projectionMatrix���������������Frustum��������� |
| 83 |
nyatla |
853 |
this.setARClipping(FRUSTUM_DEFAULT_NEAR_CLIP,FRUSTUM_DEFAULT_FAR_CLIP); |
| 84 |
|
|
return; |
| 85 |
nyatla |
420 |
} |
| 86 |
nyatla |
820 |
/** |
| 87 |
nyatla |
971 |
* [readonly]������������������Processing���������ProjectionMatrix������������������������������ |
| 88 |
nyatla |
876 |
* @return |
| 89 |
nyatla |
971 |
*/ |
| 90 |
|
|
public abstract PMatrix3D getProjectionMatrix(); |
| 91 |
|
|
/** |
| 92 |
|
|
* ������������������ProjectionMatrix���i_buf������������������������������ |
| 93 |
|
|
* @return |
| 94 |
nyatla |
876 |
* ProjectionMatrix��������� |
| 95 |
|
|
*/ |
| 96 |
nyatla |
971 |
public abstract PMatrix3D getProjectionMatrix(PMatrix3D i_buf); |
| 97 |
nyatla |
876 |
/** |
| 98 |
nyatla |
854 |
* ������������������PImage������������������������������������������������PImage���farclip���+1������������������������������ |
| 99 |
nyatla |
853 |
* <div>���������������������������������������������������</div> |
| 100 |
|
|
* <hr/> |
| 101 |
|
|
* :<br/> |
| 102 |
|
|
* PMatrix3D om=new PMatrix3D(((PGraphics3D)g).projection);<br/> |
| 103 |
nyatla |
854 |
* setBackgroundOrtho(img.width,img.height)<br/> |
| 104 |
nyatla |
853 |
* pushMatrix();<br/> |
| 105 |
nyatla |
854 |
* resetMatrix();<br/> |
| 106 |
|
|
* translate(0,0,-(far*0.99f));<br/> |
| 107 |
nyatla |
853 |
* image(img,-width/2,-height/2);<br/> |
| 108 |
|
|
* popMatrix();<br/> |
| 109 |
|
|
* setPerspective(om);<br/> |
| 110 |
|
|
* :<br/> |
| 111 |
|
|
* <hr/> |
| 112 |
|
|
* ������������������PrjectionMatrix���ModelViewMatrix��������������������������������������������������������������������� |
| 113 |
|
|
* ��������������������������������������������������������������������� |
| 114 |
|
|
* @param i_img |
| 115 |
|
|
* ��������������������������������� |
| 116 |
|
|
*/ |
| 117 |
|
|
public void drawBackground(PImage i_img) |
| 118 |
|
|
{ |
| 119 |
|
|
PApplet pa=this._ref_papplet; |
| 120 |
|
|
PMatrix3D om=new PMatrix3D(((PGraphics3D)pa.g).projection); |
| 121 |
nyatla |
854 |
this.setBackgroundOrtho(i_img.width,i_img.height); |
| 122 |
nyatla |
853 |
pa.pushMatrix(); |
| 123 |
nyatla |
854 |
pa.setMatrix(this._ps_background_mv); |
| 124 |
nyatla |
853 |
pa.image(i_img,-i_img.width/2,-i_img.height/2); |
| 125 |
|
|
pa.popMatrix(); |
| 126 |
|
|
//��������������� |
| 127 |
|
|
this.setPerspective(om); |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
/** |
| 131 |
|
|
* ������������������������������������������������������������������������������������������������������{@link #FRUSTUM_DEFAULT_NEAR_CLIP}���{@link #FRUSTUM_DEFAULT_FAR_CLIP}��������� |
| 132 |
|
|
* ������������������������{@link #setARPerspective()}������������������������������������������������������������������������������������������������������������������ |
| 133 |
|
|
* @param i_near |
| 134 |
|
|
* NearPlane������������������������������������[mm]��������� |
| 135 |
|
|
* @param i_far |
| 136 |
|
|
* FarPlane������������������������������������[mm]��������� |
| 137 |
|
|
*/ |
| 138 |
|
|
public void setARClipping(float i_near,float i_far) |
| 139 |
|
|
{ |
| 140 |
|
|
this._clip_far=i_far; |
| 141 |
|
|
this._clip_near=i_near; |
| 142 |
nyatla |
854 |
this._ps_background_mv.reset(); |
| 143 |
|
|
this._ps_background_mv.translate(0,0,-i_far); |
| 144 |
nyatla |
853 |
} |
| 145 |
|
|
/** |
| 146 |
|
|
* ������������������������������������Processing������������������������ |
| 147 |
nyatla |
854 |
* ������������������0,0��������������������������� |
| 148 |
|
|
* near���������������������{@link #setARClipping}������������������������������������������������������ |
| 149 |
|
|
*���far���������������������{@link #setARClipping}���������������������������������+1��������������������� |
| 150 |
nyatla |
853 |
* <div>���������������������������������������������������</div> |
| 151 |
|
|
* <hr/> |
| 152 |
|
|
* :<br/> |
| 153 |
nyatla |
854 |
* ortho(-i_width/2, i_width/2,-i_height/2,i_height/2,near,far+1);<br/> |
| 154 |
nyatla |
853 |
* :<br/> |
| 155 |
|
|
* <hr/> |
| 156 |
|
|
* @param i_width |
| 157 |
|
|
* ������������������������ |
| 158 |
|
|
* @param i_height |
| 159 |
|
|
* ��������������������������� |
| 160 |
|
|
*/ |
| 161 |
nyatla |
854 |
public void setBackgroundOrtho(int i_width,int i_height) |
| 162 |
nyatla |
853 |
{ |
| 163 |
|
|
float half_w=i_width/2; |
| 164 |
|
|
float half_h=i_height/2; |
| 165 |
nyatla |
854 |
this._ref_papplet.ortho(-half_w, half_w,-half_h,half_h,this._clip_near,this._clip_far+1); |
| 166 |
nyatla |
853 |
} |
| 167 |
|
|
/** |
| 168 |
nyatla |
820 |
* ������������������ARToolKit���������ProjectionMatrix���Processing������������������������ |
| 169 |
|
|
* ���������������������������Processing���ProjectionMatrix���ARToolKit��������������������������������������������������������������������������������������������������������������������� |
| 170 |
|
|
* Processing������������������Frustum���������������������{@link PGraphics3D#perspective()}������������������ |
| 171 |
|
|
* Frustum���������������������������{@link PGraphics3D#perspective()}���{@link PGraphics3D#perspective()}��������������������������������� |
| 172 |
nyatla |
854 |
* <p> |
| 173 |
|
|
* Version 1.1.0���������������projection matrix���������������������������������������projection matrix���������������������{@link PGraphics3D#projection}��������������������������������������� |
| 174 |
|
|
* </p> |
| 175 |
nyatla |
820 |
*/ |
| 176 |
nyatla |
853 |
public void setARPerspective() |
| 177 |
nyatla |
814 |
{ |
| 178 |
nyatla |
971 |
this.setPerspective(this.getProjectionMatrix()); |
| 179 |
nyatla |
820 |
} |
| 180 |
|
|
/** |
| 181 |
|
|
* ������������������ProjectionMatrix���Processing������������������������ |
| 182 |
|
|
* @param i_projection |
| 183 |
|
|
* ������������ProjectionMatrix��������������������� |
| 184 |
nyatla |
839 |
* <p> |
| 185 |
|
|
* Processing/1.3������������������{@link PApplet#matrixMode}��������������������������������������������������������� |
| 186 |
|
|
* ������������������������frustum������ |
| 187 |
|
|
* </p> |
| 188 |
nyatla |
854 |
* <p> |
| 189 |
|
|
* Version 1.1.0���������������projection matrix���������������������������������������projection matrix���������������������{@link PGraphics3D#projection}��������������������������������������� |
| 190 |
|
|
* </p> |
| 191 |
nyatla |
820 |
*/ |
| 192 |
nyatla |
853 |
public void setPerspective(PMatrix3D i_projection) |
| 193 |
nyatla |
820 |
{ |
| 194 |
nyatla |
839 |
//Projection���frustum������������������ |
| 195 |
|
|
float far=i_projection.m23/(i_projection.m22+1); |
| 196 |
|
|
float near=i_projection.m23/(i_projection.m22-1); |
| 197 |
|
|
this._ref_papplet.frustum( |
| 198 |
|
|
(i_projection.m02-1)*near/i_projection.m00, |
| 199 |
|
|
(i_projection.m02+1)*near/i_projection.m00, |
| 200 |
|
|
(i_projection.m12-1)*near/i_projection.m11, |
| 201 |
|
|
(i_projection.m12+1)*near/i_projection.m11, |
| 202 |
|
|
near,far); |
| 203 |
nyatla |
853 |
return; |
| 204 |
nyatla |
820 |
} |
| 205 |
|
|
|
| 206 |
|
|
protected static void PMatrix2GLProjection(PMatrix3D i_in,float[] o_out) |
| 207 |
|
|
{ |
| 208 |
|
|
o_out[ 0]=i_in.m00; |
| 209 |
|
|
o_out[ 1]=i_in.m10; |
| 210 |
|
|
o_out[ 2]=i_in.m20; |
| 211 |
|
|
o_out[ 3]=i_in.m30; |
| 212 |
|
|
o_out[ 4]=i_in.m01; |
| 213 |
|
|
o_out[ 5]=i_in.m11; |
| 214 |
|
|
o_out[ 6]=i_in.m21; |
| 215 |
|
|
o_out[ 7]=i_in.m31; |
| 216 |
|
|
o_out[ 8]=i_in.m02; |
| 217 |
|
|
o_out[ 9]=i_in.m12; |
| 218 |
|
|
o_out[10]=i_in.m22; |
| 219 |
|
|
o_out[11]=i_in.m32; |
| 220 |
|
|
o_out[12]=i_in.m03; |
| 221 |
|
|
o_out[13]=i_in.m13; |
| 222 |
|
|
o_out[14]=i_in.m23; |
| 223 |
|
|
o_out[15]=i_in.m33; |
| 224 |
|
|
} |
| 225 |
|
|
protected static void PMatrix2GLProjection(PMatrix3D i_in,double[] o_out) |
| 226 |
|
|
{ |
| 227 |
|
|
o_out[ 0]=i_in.m00; |
| 228 |
|
|
o_out[ 1]=i_in.m10; |
| 229 |
|
|
o_out[ 2]=i_in.m20; |
| 230 |
|
|
o_out[ 3]=i_in.m30; |
| 231 |
|
|
o_out[ 4]=i_in.m01; |
| 232 |
|
|
o_out[ 5]=i_in.m11; |
| 233 |
|
|
o_out[ 6]=i_in.m21; |
| 234 |
|
|
o_out[ 7]=i_in.m31; |
| 235 |
|
|
o_out[ 8]=i_in.m02; |
| 236 |
|
|
o_out[ 9]=i_in.m12; |
| 237 |
|
|
o_out[10]=i_in.m22; |
| 238 |
|
|
o_out[11]=i_in.m32; |
| 239 |
|
|
o_out[12]=i_in.m03; |
| 240 |
|
|
o_out[13]=i_in.m13; |
| 241 |
|
|
o_out[14]=i_in.m23; |
| 242 |
|
|
o_out[15]=i_in.m33; |
| 243 |
|
|
} |
| 244 |
nyatla |
971 |
protected static void nyarMat2PsMat(NyARDoubleMatrix44 i_src,PMatrix3D i_dst) |
| 245 |
nyatla |
820 |
{ |
| 246 |
nyatla |
971 |
i_dst.m00=(float)(i_src.m00); |
| 247 |
|
|
i_dst.m01=(float)(i_src.m01); |
| 248 |
|
|
i_dst.m02=(float)(i_src.m02); |
| 249 |
|
|
i_dst.m03=(float)(i_src.m03); |
| 250 |
|
|
i_dst.m10=(float)(i_src.m10); |
| 251 |
|
|
i_dst.m11=(float)(i_src.m11); |
| 252 |
|
|
i_dst.m12=(float)(i_src.m12); |
| 253 |
|
|
i_dst.m13=(float)(i_src.m13); |
| 254 |
|
|
i_dst.m20=(float)(i_src.m20); |
| 255 |
|
|
i_dst.m21=(float)(i_src.m21); |
| 256 |
|
|
i_dst.m22=(float)(i_src.m22); |
| 257 |
|
|
i_dst.m23=(float)(i_src.m23); |
| 258 |
|
|
i_dst.m30=(float)(i_src.m30); |
| 259 |
|
|
i_dst.m31=(float)(i_src.m31); |
| 260 |
|
|
i_dst.m32=(float)(i_src.m32); |
| 261 |
|
|
i_dst.m33=(float)(i_src.m33); |
| 262 |
nyatla |
814 |
} |
| 263 |
nyatla |
971 |
|
| 264 |
nyatla |
420 |
/** |
| 265 |
nyatla |
814 |
* ��������������������������� |
| 266 |
nyatla |
420 |
*/ |
| 267 |
nyatla |
853 |
private final static PMatrix3D _lh_mat=new PMatrix3D( |
| 268 |
|
|
-1,0,0,0, |
| 269 |
|
|
0,1,0,0, |
| 270 |
|
|
0,0,1,0, |
| 271 |
|
|
0,0,0,1); |
| 272 |
nyatla |
814 |
|
| 273 |
nyatla |
420 |
/** |
| 274 |
nyatla |
814 |
* ���������������Processing���Matrix��������������������� |
| 275 |
|
|
* @param i_src |
| 276 |
|
|
* @param i_mode |
| 277 |
|
|
* @param o_pmatrix |
| 278 |
nyatla |
420 |
*/ |
| 279 |
nyatla |
828 |
protected static void matResult2PMatrix3D(NyARDoubleMatrix44 i_src,int i_mode,PMatrix3D o_pmatrix) |
| 280 |
nyatla |
814 |
{ |
| 281 |
|
|
o_pmatrix.m00 = (float)i_src.m00; |
| 282 |
|
|
o_pmatrix.m01 = (float)i_src.m01; |
| 283 |
|
|
o_pmatrix.m02 = (float)i_src.m02; |
| 284 |
|
|
o_pmatrix.m03 = (float)i_src.m03; |
| 285 |
|
|
o_pmatrix.m10 = (float)i_src.m10;//mirror |
| 286 |
|
|
o_pmatrix.m11 = (float)i_src.m11;//mirror |
| 287 |
|
|
o_pmatrix.m12 = (float)i_src.m12;//mirror |
| 288 |
|
|
o_pmatrix.m13 = (float)i_src.m13;//mirror |
| 289 |
|
|
o_pmatrix.m20 = (float)-i_src.m20; |
| 290 |
|
|
o_pmatrix.m21 = (float)-i_src.m21; |
| 291 |
|
|
o_pmatrix.m22 = (float)-i_src.m22; |
| 292 |
|
|
o_pmatrix.m23 = (float)-i_src.m23; |
| 293 |
|
|
o_pmatrix.m30 = 0.0f; |
| 294 |
|
|
o_pmatrix.m31 = 0.0f; |
| 295 |
|
|
o_pmatrix.m32 = 0.0f; |
| 296 |
|
|
o_pmatrix.m33 = 1.0f; |
| 297 |
nyatla |
828 |
if(i_mode==NyAR4PsgConfig.CS_LEFT_HAND) |
| 298 |
nyatla |
814 |
{ |
| 299 |
|
|
o_pmatrix.apply(_lh_mat); |
| 300 |
|
|
} |
| 301 |
nyatla |
825 |
} |
| 302 |
nyatla |
971 |
protected static void matResult2GLArray(NyARDoubleMatrix44 i_src,double[] o_gl_array) |
| 303 |
nyatla |
825 |
{ |
| 304 |
nyatla |
971 |
o_gl_array[0 + 0 * 4] = i_src.m00; |
| 305 |
|
|
o_gl_array[0 + 1 * 4] = i_src.m01; |
| 306 |
|
|
o_gl_array[0 + 2 * 4] = i_src.m02; |
| 307 |
|
|
o_gl_array[0 + 3 * 4] = i_src.m03; |
| 308 |
|
|
o_gl_array[1 + 0 * 4] = -i_src.m10; |
| 309 |
|
|
o_gl_array[1 + 1 * 4] = -i_src.m11; |
| 310 |
|
|
o_gl_array[1 + 2 * 4] = -i_src.m12; |
| 311 |
|
|
o_gl_array[1 + 3 * 4] = -i_src.m13; |
| 312 |
|
|
o_gl_array[2 + 0 * 4] = -i_src.m20; |
| 313 |
|
|
o_gl_array[2 + 1 * 4] = -i_src.m21; |
| 314 |
|
|
o_gl_array[2 + 2 * 4] = -i_src.m22; |
| 315 |
|
|
o_gl_array[2 + 3 * 4] = -i_src.m23; |
| 316 |
|
|
o_gl_array[3 + 0 * 4] = 0.0; |
| 317 |
|
|
o_gl_array[3 + 1 * 4] = 0.0; |
| 318 |
|
|
o_gl_array[3 + 2 * 4] = 0.0; |
| 319 |
|
|
o_gl_array[3 + 3 * 4] = 1.0; |
| 320 |
nyatla |
814 |
} |
| 321 |
nyatla |
420 |
|
| 322 |
nyatla |
971 |
} |
| 323 |
|
|
|