| 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 |
420 |
import processing.core.*; |
| 32 |
|
|
|
| 33 |
|
|
import jp.nyatla.nyartoolkit.*; |
| 34 |
|
|
import jp.nyatla.nyartoolkit.core.param.*; |
| 35 |
nyatla |
828 |
import jp.nyatla.nyartoolkit.core.rasterreader.NyARPerspectiveRasterReader; |
| 36 |
nyatla |
814 |
import jp.nyatla.nyartoolkit.core.transmat.*; |
| 37 |
nyatla |
828 |
import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d; |
| 38 |
nyatla |
825 |
import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d; |
| 39 |
nyatla |
853 |
import jp.nyatla.nyartoolkit.core.types.NyARIntSize; |
| 40 |
nyatla |
814 |
import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix44; |
| 41 |
nyatla |
420 |
|
| 42 |
|
|
|
| 43 |
nyatla |
820 |
|
| 44 |
nyatla |
420 |
/** |
| 45 |
nyatla |
814 |
* ���������������������NyARToolkit for Processing������������������������������ |
| 46 |
|
|
* ARToolkit��������������������������������������������������������������������������������������������� |
| 47 |
nyatla |
420 |
*/ |
| 48 |
|
|
class NyARPsgBaseClass |
| 49 |
|
|
{ |
| 50 |
nyatla |
853 |
/** |
| 51 |
|
|
* near��������������������������������������������� |
| 52 |
|
|
*/ |
| 53 |
|
|
public final float FRUSTUM_DEFAULT_NEAR_CLIP=100; |
| 54 |
|
|
/** |
| 55 |
|
|
* far��������������������������������������������� |
| 56 |
|
|
*/ |
| 57 |
|
|
public final float FRUSTUM_DEFAULT_FAR_CLIP=100000; |
| 58 |
nyatla |
828 |
|
| 59 |
nyatla |
420 |
/** |
| 60 |
|
|
* ��������������������������������� |
| 61 |
nyatla |
814 |
* NyAR4psg������������������������������������������ |
| 62 |
nyatla |
420 |
*/ |
| 63 |
nyatla |
881 |
public final static String VERSION = "NyAR4psg/1.1.7;NyARToolkit for java/3.0.0+;ARToolKit/2.72.1"; |
| 64 |
nyatla |
820 |
/**���������������Applet������������������������������*/ |
| 65 |
|
|
protected PApplet _ref_papplet; |
| 66 |
nyatla |
828 |
/**���Processing���������������ProjectionMatrix���������*/ |
| 67 |
|
|
protected final PMatrix3D _ps_projection=new PMatrix3D(); |
| 68 |
nyatla |
854 |
/**���������������������������������ModelviewMatrix���������*/ |
| 69 |
|
|
protected final PMatrix3D _ps_background_mv=new PMatrix3D(); |
| 70 |
|
|
|
| 71 |
nyatla |
820 |
/**���ARToolkit���������������������������������������������*/ |
| 72 |
nyatla |
828 |
protected final NyARParam _ar_param=new NyARParam(); |
| 73 |
|
|
protected final NyARFrustum _frustum=new NyARFrustum();; |
| 74 |
|
|
protected NyAR4PsgConfig _config; |
| 75 |
|
|
|
| 76 |
|
|
/** ������������������������������{@link PImage}������������������������������������������������������������������������������*/ |
| 77 |
|
|
protected PImageRaster _src_raster; |
| 78 |
|
|
/** ���������������������������������������������{@link #_src_raster}���������������������*/ |
| 79 |
|
|
protected NyARPerspectiveRasterReader _preader; |
| 80 |
nyatla |
853 |
|
| 81 |
|
|
private float _clip_far; |
| 82 |
|
|
private float _clip_near; |
| 83 |
|
|
|
| 84 |
nyatla |
820 |
/** |
| 85 |
|
|
* ������������������������������ |
| 86 |
|
|
*/ |
| 87 |
|
|
protected NyARPsgBaseClass() |
| 88 |
nyatla |
420 |
{ |
| 89 |
nyatla |
820 |
} |
| 90 |
nyatla |
828 |
protected void initInstance(PApplet parent,String i_cparam_file, int i_width,int i_height,NyAR4PsgConfig i_config) throws NyARException |
| 91 |
nyatla |
820 |
{ |
| 92 |
nyatla |
814 |
this._ref_papplet=parent; |
| 93 |
nyatla |
828 |
this._config=i_config; |
| 94 |
|
|
this._src_raster=new PImageRaster(i_width,i_height); |
| 95 |
|
|
this._preader=new NyARPerspectiveRasterReader(this._src_raster.getBufferType()); |
| 96 |
nyatla |
420 |
try{ |
| 97 |
nyatla |
814 |
this._ar_param.loadARParam(this._ref_papplet.createInput(i_cparam_file)); |
| 98 |
nyatla |
853 |
this._ar_param.changeScreenSize(i_width, i_height);//w,h��������������������� |
| 99 |
nyatla |
814 |
|
| 100 |
|
|
//Processing���projectionMatrix���������������Frustum��������� |
| 101 |
nyatla |
853 |
this.setARClipping(FRUSTUM_DEFAULT_NEAR_CLIP,FRUSTUM_DEFAULT_FAR_CLIP); |
| 102 |
nyatla |
420 |
}catch(NyARException e){ |
| 103 |
nyatla |
814 |
this._ref_papplet.die("Error while setting up NyARToolkit for java", e); |
| 104 |
nyatla |
420 |
} |
| 105 |
nyatla |
853 |
return; |
| 106 |
nyatla |
420 |
} |
| 107 |
nyatla |
820 |
/** |
| 108 |
nyatla |
876 |
* ������������������ProjectionMatrix������������������������������ |
| 109 |
|
|
* @return |
| 110 |
|
|
* ProjectionMatrix��������� |
| 111 |
|
|
*/ |
| 112 |
|
|
public PMatrix3D getProjectionMatrix() |
| 113 |
|
|
{ |
| 114 |
|
|
return new PMatrix3D(this._ps_projection); |
| 115 |
|
|
} |
| 116 |
|
|
/** |
| 117 |
nyatla |
854 |
* ������������������PImage������������������������������������������������PImage���farclip���+1������������������������������ |
| 118 |
nyatla |
853 |
* <div>���������������������������������������������������</div> |
| 119 |
|
|
* <hr/> |
| 120 |
|
|
* :<br/> |
| 121 |
|
|
* PMatrix3D om=new PMatrix3D(((PGraphics3D)g).projection);<br/> |
| 122 |
nyatla |
854 |
* setBackgroundOrtho(img.width,img.height)<br/> |
| 123 |
nyatla |
853 |
* pushMatrix();<br/> |
| 124 |
nyatla |
854 |
* resetMatrix();<br/> |
| 125 |
|
|
* translate(0,0,-(far*0.99f));<br/> |
| 126 |
nyatla |
853 |
* image(img,-width/2,-height/2);<br/> |
| 127 |
|
|
* popMatrix();<br/> |
| 128 |
|
|
* setPerspective(om);<br/> |
| 129 |
|
|
* :<br/> |
| 130 |
|
|
* <hr/> |
| 131 |
|
|
* ������������������PrjectionMatrix���ModelViewMatrix��������������������������������������������������������������������� |
| 132 |
|
|
* ��������������������������������������������������������������������� |
| 133 |
|
|
* @param i_img |
| 134 |
|
|
* ��������������������������������� |
| 135 |
|
|
*/ |
| 136 |
|
|
public void drawBackground(PImage i_img) |
| 137 |
|
|
{ |
| 138 |
|
|
PApplet pa=this._ref_papplet; |
| 139 |
|
|
PMatrix3D om=new PMatrix3D(((PGraphics3D)pa.g).projection); |
| 140 |
nyatla |
854 |
this.setBackgroundOrtho(i_img.width,i_img.height); |
| 141 |
nyatla |
853 |
pa.pushMatrix(); |
| 142 |
nyatla |
854 |
pa.setMatrix(this._ps_background_mv); |
| 143 |
nyatla |
853 |
pa.image(i_img,-i_img.width/2,-i_img.height/2); |
| 144 |
|
|
pa.popMatrix(); |
| 145 |
|
|
//��������������� |
| 146 |
|
|
this.setPerspective(om); |
| 147 |
|
|
} |
| 148 |
|
|
|
| 149 |
|
|
/** |
| 150 |
|
|
* ������������������������������������������������������������������������������������������������������{@link #FRUSTUM_DEFAULT_NEAR_CLIP}���{@link #FRUSTUM_DEFAULT_FAR_CLIP}��������� |
| 151 |
|
|
* ������������������������{@link #setARPerspective()}������������������������������������������������������������������������������������������������������������������ |
| 152 |
|
|
* @param i_near |
| 153 |
|
|
* NearPlane������������������������������������[mm]��������� |
| 154 |
|
|
* @param i_far |
| 155 |
|
|
* FarPlane������������������������������������[mm]��������� |
| 156 |
|
|
*/ |
| 157 |
|
|
public void setARClipping(float i_near,float i_far) |
| 158 |
|
|
{ |
| 159 |
|
|
this._clip_far=i_far; |
| 160 |
|
|
this._clip_near=i_near; |
| 161 |
nyatla |
854 |
arPerspectiveMat2Projection(this._ar_param,i_near,i_far,this._ps_projection,this._frustum); |
| 162 |
|
|
this._ps_background_mv.reset(); |
| 163 |
|
|
this._ps_background_mv.translate(0,0,-i_far); |
| 164 |
nyatla |
853 |
} |
| 165 |
|
|
/** |
| 166 |
|
|
* ������������������������������������Processing������������������������ |
| 167 |
nyatla |
854 |
* ������������������0,0��������������������������� |
| 168 |
|
|
* near���������������������{@link #setARClipping}������������������������������������������������������ |
| 169 |
|
|
*���far���������������������{@link #setARClipping}���������������������������������+1��������������������� |
| 170 |
nyatla |
853 |
* <div>���������������������������������������������������</div> |
| 171 |
|
|
* <hr/> |
| 172 |
|
|
* :<br/> |
| 173 |
nyatla |
854 |
* ortho(-i_width/2, i_width/2,-i_height/2,i_height/2,near,far+1);<br/> |
| 174 |
nyatla |
853 |
* :<br/> |
| 175 |
|
|
* <hr/> |
| 176 |
|
|
* @param i_width |
| 177 |
|
|
* ������������������������ |
| 178 |
|
|
* @param i_height |
| 179 |
|
|
* ��������������������������� |
| 180 |
|
|
*/ |
| 181 |
nyatla |
854 |
public void setBackgroundOrtho(int i_width,int i_height) |
| 182 |
nyatla |
853 |
{ |
| 183 |
|
|
float half_w=i_width/2; |
| 184 |
|
|
float half_h=i_height/2; |
| 185 |
nyatla |
854 |
this._ref_papplet.ortho(-half_w, half_w,-half_h,half_h,this._clip_near,this._clip_far+1); |
| 186 |
nyatla |
853 |
} |
| 187 |
|
|
/** |
| 188 |
nyatla |
820 |
* ������������������ARToolKit���������ProjectionMatrix���Processing������������������������ |
| 189 |
|
|
* ���������������������������Processing���ProjectionMatrix���ARToolKit��������������������������������������������������������������������������������������������������������������������� |
| 190 |
|
|
* Processing������������������Frustum���������������������{@link PGraphics3D#perspective()}������������������ |
| 191 |
|
|
* Frustum���������������������������{@link PGraphics3D#perspective()}���{@link PGraphics3D#perspective()}��������������������������������� |
| 192 |
nyatla |
854 |
* <p> |
| 193 |
|
|
* Version 1.1.0���������������projection matrix���������������������������������������projection matrix���������������������{@link PGraphics3D#projection}��������������������������������������� |
| 194 |
|
|
* </p> |
| 195 |
nyatla |
820 |
*/ |
| 196 |
nyatla |
853 |
public void setARPerspective() |
| 197 |
nyatla |
814 |
{ |
| 198 |
nyatla |
853 |
this.setPerspective(this._ps_projection); |
| 199 |
nyatla |
820 |
} |
| 200 |
|
|
/** |
| 201 |
|
|
* ������������������ProjectionMatrix���Processing������������������������ |
| 202 |
|
|
* @param i_projection |
| 203 |
|
|
* ������������ProjectionMatrix��������������������� |
| 204 |
nyatla |
839 |
* <p> |
| 205 |
|
|
* Processing/1.3������������������{@link PApplet#matrixMode}��������������������������������������������������������� |
| 206 |
|
|
* ������������������������frustum������ |
| 207 |
|
|
* </p> |
| 208 |
nyatla |
854 |
* <p> |
| 209 |
|
|
* Version 1.1.0���������������projection matrix���������������������������������������projection matrix���������������������{@link PGraphics3D#projection}��������������������������������������� |
| 210 |
|
|
* </p> |
| 211 |
nyatla |
820 |
*/ |
| 212 |
nyatla |
853 |
public void setPerspective(PMatrix3D i_projection) |
| 213 |
nyatla |
820 |
{ |
| 214 |
nyatla |
839 |
//Projection���frustum������������������ |
| 215 |
|
|
float far=i_projection.m23/(i_projection.m22+1); |
| 216 |
|
|
float near=i_projection.m23/(i_projection.m22-1); |
| 217 |
|
|
this._ref_papplet.frustum( |
| 218 |
|
|
(i_projection.m02-1)*near/i_projection.m00, |
| 219 |
|
|
(i_projection.m02+1)*near/i_projection.m00, |
| 220 |
|
|
(i_projection.m12-1)*near/i_projection.m11, |
| 221 |
|
|
(i_projection.m12+1)*near/i_projection.m11, |
| 222 |
|
|
near,far); |
| 223 |
nyatla |
853 |
return; |
| 224 |
nyatla |
820 |
} |
| 225 |
|
|
|
| 226 |
|
|
protected static void PMatrix2GLProjection(PMatrix3D i_in,float[] o_out) |
| 227 |
|
|
{ |
| 228 |
|
|
o_out[ 0]=i_in.m00; |
| 229 |
|
|
o_out[ 1]=i_in.m10; |
| 230 |
|
|
o_out[ 2]=i_in.m20; |
| 231 |
|
|
o_out[ 3]=i_in.m30; |
| 232 |
|
|
o_out[ 4]=i_in.m01; |
| 233 |
|
|
o_out[ 5]=i_in.m11; |
| 234 |
|
|
o_out[ 6]=i_in.m21; |
| 235 |
|
|
o_out[ 7]=i_in.m31; |
| 236 |
|
|
o_out[ 8]=i_in.m02; |
| 237 |
|
|
o_out[ 9]=i_in.m12; |
| 238 |
|
|
o_out[10]=i_in.m22; |
| 239 |
|
|
o_out[11]=i_in.m32; |
| 240 |
|
|
o_out[12]=i_in.m03; |
| 241 |
|
|
o_out[13]=i_in.m13; |
| 242 |
|
|
o_out[14]=i_in.m23; |
| 243 |
|
|
o_out[15]=i_in.m33; |
| 244 |
|
|
} |
| 245 |
|
|
protected static void PMatrix2GLProjection(PMatrix3D i_in,double[] o_out) |
| 246 |
|
|
{ |
| 247 |
|
|
o_out[ 0]=i_in.m00; |
| 248 |
|
|
o_out[ 1]=i_in.m10; |
| 249 |
|
|
o_out[ 2]=i_in.m20; |
| 250 |
|
|
o_out[ 3]=i_in.m30; |
| 251 |
|
|
o_out[ 4]=i_in.m01; |
| 252 |
|
|
o_out[ 5]=i_in.m11; |
| 253 |
|
|
o_out[ 6]=i_in.m21; |
| 254 |
|
|
o_out[ 7]=i_in.m31; |
| 255 |
|
|
o_out[ 8]=i_in.m02; |
| 256 |
|
|
o_out[ 9]=i_in.m12; |
| 257 |
|
|
o_out[10]=i_in.m22; |
| 258 |
|
|
o_out[11]=i_in.m32; |
| 259 |
|
|
o_out[12]=i_in.m03; |
| 260 |
|
|
o_out[13]=i_in.m13; |
| 261 |
|
|
o_out[14]=i_in.m23; |
| 262 |
|
|
o_out[15]=i_in.m33; |
| 263 |
|
|
} |
| 264 |
|
|
|
| 265 |
nyatla |
853 |
private static void arPerspectiveMat2Projection(NyARParam i_param,float i_near,float i_far,PMatrix3D o_projection,NyARFrustum o_frustum) |
| 266 |
nyatla |
820 |
{ |
| 267 |
nyatla |
814 |
NyARDoubleMatrix44 tmp=new NyARDoubleMatrix44(); |
| 268 |
nyatla |
853 |
NyARIntSize s=i_param.getScreenSize(); |
| 269 |
|
|
i_param.getPerspectiveProjectionMatrix().makeCameraFrustumRH(s.w,s.h,i_near,i_far,tmp); |
| 270 |
nyatla |
820 |
o_projection.m00=(float)(tmp.m00); |
| 271 |
|
|
o_projection.m01=(float)(tmp.m01); |
| 272 |
|
|
o_projection.m02=(float)(tmp.m02); |
| 273 |
|
|
o_projection.m03=(float)(tmp.m03); |
| 274 |
|
|
o_projection.m10=(float)(tmp.m10); |
| 275 |
|
|
o_projection.m11=(float)(tmp.m11); |
| 276 |
|
|
o_projection.m12=(float)(tmp.m12); |
| 277 |
|
|
o_projection.m13=(float)(tmp.m13); |
| 278 |
|
|
o_projection.m20=(float)(tmp.m20); |
| 279 |
|
|
o_projection.m21=(float)(tmp.m21); |
| 280 |
|
|
o_projection.m22=(float)(tmp.m22); |
| 281 |
|
|
o_projection.m23=(float)(tmp.m23); |
| 282 |
|
|
o_projection.m30=(float)(tmp.m30); |
| 283 |
|
|
o_projection.m31=(float)(tmp.m31); |
| 284 |
|
|
o_projection.m32=(float)(tmp.m32); |
| 285 |
|
|
o_projection.m33=(float)(tmp.m33); |
| 286 |
nyatla |
853 |
o_frustum.setValue(tmp, s.w, s.h); |
| 287 |
nyatla |
814 |
} |
| 288 |
nyatla |
420 |
protected static void matResult2GLArray(NyARTransMatResult i_src,double[] o_gl_array) |
| 289 |
|
|
{ |
| 290 |
|
|
o_gl_array[0 + 0 * 4] = i_src.m00; |
| 291 |
|
|
o_gl_array[0 + 1 * 4] = i_src.m01; |
| 292 |
|
|
o_gl_array[0 + 2 * 4] = i_src.m02; |
| 293 |
|
|
o_gl_array[0 + 3 * 4] = i_src.m03; |
| 294 |
|
|
o_gl_array[1 + 0 * 4] = -i_src.m10; |
| 295 |
|
|
o_gl_array[1 + 1 * 4] = -i_src.m11; |
| 296 |
|
|
o_gl_array[1 + 2 * 4] = -i_src.m12; |
| 297 |
|
|
o_gl_array[1 + 3 * 4] = -i_src.m13; |
| 298 |
|
|
o_gl_array[2 + 0 * 4] = -i_src.m20; |
| 299 |
|
|
o_gl_array[2 + 1 * 4] = -i_src.m21; |
| 300 |
|
|
o_gl_array[2 + 2 * 4] = -i_src.m22; |
| 301 |
|
|
o_gl_array[2 + 3 * 4] = -i_src.m23; |
| 302 |
|
|
o_gl_array[3 + 0 * 4] = 0.0; |
| 303 |
|
|
o_gl_array[3 + 1 * 4] = 0.0; |
| 304 |
|
|
o_gl_array[3 + 2 * 4] = 0.0; |
| 305 |
|
|
o_gl_array[3 + 3 * 4] = 1.0; |
| 306 |
|
|
} |
| 307 |
|
|
/** |
| 308 |
nyatla |
814 |
* ��������������������������� |
| 309 |
nyatla |
420 |
*/ |
| 310 |
nyatla |
853 |
private final static PMatrix3D _lh_mat=new PMatrix3D( |
| 311 |
|
|
-1,0,0,0, |
| 312 |
|
|
0,1,0,0, |
| 313 |
|
|
0,0,1,0, |
| 314 |
|
|
0,0,0,1); |
| 315 |
nyatla |
814 |
|
| 316 |
nyatla |
420 |
/** |
| 317 |
nyatla |
814 |
* ���������������Processing���Matrix��������������������� |
| 318 |
|
|
* @param i_src |
| 319 |
|
|
* @param i_mode |
| 320 |
|
|
* @param o_pmatrix |
| 321 |
nyatla |
420 |
*/ |
| 322 |
nyatla |
828 |
protected static void matResult2PMatrix3D(NyARDoubleMatrix44 i_src,int i_mode,PMatrix3D o_pmatrix) |
| 323 |
nyatla |
814 |
{ |
| 324 |
|
|
o_pmatrix.m00 = (float)i_src.m00; |
| 325 |
|
|
o_pmatrix.m01 = (float)i_src.m01; |
| 326 |
|
|
o_pmatrix.m02 = (float)i_src.m02; |
| 327 |
|
|
o_pmatrix.m03 = (float)i_src.m03; |
| 328 |
|
|
o_pmatrix.m10 = (float)i_src.m10;//mirror |
| 329 |
|
|
o_pmatrix.m11 = (float)i_src.m11;//mirror |
| 330 |
|
|
o_pmatrix.m12 = (float)i_src.m12;//mirror |
| 331 |
|
|
o_pmatrix.m13 = (float)i_src.m13;//mirror |
| 332 |
|
|
o_pmatrix.m20 = (float)-i_src.m20; |
| 333 |
|
|
o_pmatrix.m21 = (float)-i_src.m21; |
| 334 |
|
|
o_pmatrix.m22 = (float)-i_src.m22; |
| 335 |
|
|
o_pmatrix.m23 = (float)-i_src.m23; |
| 336 |
|
|
o_pmatrix.m30 = 0.0f; |
| 337 |
|
|
o_pmatrix.m31 = 0.0f; |
| 338 |
|
|
o_pmatrix.m32 = 0.0f; |
| 339 |
|
|
o_pmatrix.m33 = 1.0f; |
| 340 |
nyatla |
828 |
if(i_mode==NyAR4PsgConfig.CS_LEFT_HAND) |
| 341 |
nyatla |
814 |
{ |
| 342 |
|
|
o_pmatrix.apply(_lh_mat); |
| 343 |
|
|
} |
| 344 |
nyatla |
825 |
} |
| 345 |
|
|
/** |
| 346 |
nyatla |
881 |
* ���������������������������������������i_x,i_y��������������������������������������������� |
| 347 |
nyatla |
825 |
* @param i_mat |
| 348 |
|
|
* @param i_x |
| 349 |
|
|
* @param i_y |
| 350 |
|
|
* @return |
| 351 |
|
|
*/ |
| 352 |
|
|
protected PVector screen2MarkerCoordSystem(NyARDoubleMatrix44 i_mat,int i_x,int i_y) |
| 353 |
|
|
{ |
| 354 |
|
|
PVector ret=new PVector(); |
| 355 |
|
|
NyARDoublePoint3d tmp=new NyARDoublePoint3d(); |
| 356 |
|
|
this._frustum.unProjectOnMatrix(i_x, i_y,i_mat,tmp); |
| 357 |
|
|
ret.x=(float)tmp.x; |
| 358 |
|
|
ret.y=(float)tmp.y; |
| 359 |
|
|
ret.z=(float)tmp.z; |
| 360 |
nyatla |
828 |
if(this._config._coordinate_system==NyAR4PsgConfig.CS_LEFT_HAND){ |
| 361 |
nyatla |
825 |
ret.x*=-1; |
| 362 |
|
|
} |
| 363 |
|
|
return ret; |
| 364 |
nyatla |
828 |
} |
| 365 |
|
|
/** |
| 366 |
|
|
* PImage������������������������������������������������������ |
| 367 |
|
|
* @param i_mat |
| 368 |
|
|
* @param i_x1 |
| 369 |
|
|
* @param i_y1 |
| 370 |
|
|
* @param i_x2 |
| 371 |
|
|
* @param i_y2 |
| 372 |
|
|
* @param i_x3 |
| 373 |
|
|
* @param i_y3 |
| 374 |
|
|
* @param i_x4 |
| 375 |
|
|
* @param i_y4 |
| 376 |
|
|
* @param i_out_w_pix |
| 377 |
|
|
* @param i_out_h_pix |
| 378 |
|
|
* @return |
| 379 |
|
|
*/ |
| 380 |
|
|
protected PImage pickupMarkerImage(NyARDoubleMatrix44 i_mat,int i_x1,int i_y1,int i_x2,int i_y2,int i_x3,int i_y3,int i_x4,int i_y4,int i_out_w_pix,int i_out_h_pix) |
| 381 |
|
|
{ |
| 382 |
|
|
//WrapRaster��������������������� |
| 383 |
|
|
if(!this._src_raster.hasBuffer()){ |
| 384 |
|
|
this._ref_papplet.die("_rel_detector is null.(Function detect() was never called. )"); |
| 385 |
|
|
} |
| 386 |
|
|
PImage img=new PImage(i_out_w_pix,i_out_h_pix); |
| 387 |
|
|
img.parent=this._ref_papplet; |
| 388 |
|
|
try{ |
| 389 |
|
|
NyARDoublePoint3d[] pos=NyARDoublePoint3d.createArray(4); |
| 390 |
|
|
i_mat.transform3d(i_x1, i_y1,0, pos[1]); |
| 391 |
|
|
i_mat.transform3d(i_x2, i_y2,0, pos[0]); |
| 392 |
|
|
i_mat.transform3d(i_x3, i_y3,0, pos[3]); |
| 393 |
|
|
i_mat.transform3d(i_x4, i_y4,0, pos[2]); |
| 394 |
|
|
//4������������������ |
| 395 |
|
|
NyARDoublePoint2d[] pos2=NyARDoublePoint2d.createArray(4); |
| 396 |
|
|
for(int i=3;i>=0;i--){ |
| 397 |
|
|
this._frustum.project(pos[i],pos2[i]); |
| 398 |
|
|
} |
| 399 |
|
|
PImageRaster out_raster=new PImageRaster(i_out_w_pix,i_out_h_pix); |
| 400 |
|
|
out_raster.wrapBuffer(img); |
| 401 |
|
|
if(!this._preader.read4Point(this._src_raster,pos2,0,0,1,out_raster)) |
| 402 |
|
|
{ |
| 403 |
|
|
throw new Exception("this._preader.read4Point failed."); |
| 404 |
|
|
} |
| 405 |
|
|
return img; |
| 406 |
|
|
}catch(Exception e){ |
| 407 |
|
|
e.printStackTrace(); |
| 408 |
|
|
this._ref_papplet.die("Exception occurred at MultiARTookitMarker.pickupImage"); |
| 409 |
|
|
return null; |
| 410 |
|
|
} |
| 411 |
nyatla |
814 |
} |
| 412 |
nyatla |
420 |
/** |
| 413 |
nyatla |
814 |
* ������������������������������������������������������������������������������ |
| 414 |
|
|
* ��������������������������������������������������������������� |
| 415 |
|
|
* <p>������ - |
| 416 |
|
|
* ������������������gluUnproject������������������������������������������������������������������������������ |
| 417 |
|
|
* ��������������������������������������������� |
| 418 |
|
|
* http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml |
| 419 |
|
|
* ARToolKit���������������������������������������������OpenGL���unProject������ix,iy��������������������������������������������������������������������������������������� |
| 420 |
|
|
* </p> |
| 421 |
|
|
* @param ix |
| 422 |
|
|
* ��������������������������� |
| 423 |
|
|
* @param iy |
| 424 |
|
|
* ������������������ |
| 425 |
|
|
* @param o_point_on_screen |
| 426 |
|
|
* ��������������� |
| 427 |
nyatla |
420 |
*/ |
| 428 |
nyatla |
814 |
/* public final PVector unProject(double ix,double iy) |
| 429 |
|
|
{ |
| 430 |
|
|
double n=(this._frustum_rh.m23/(this._frustum_rh.m22-1)); |
| 431 |
|
|
NyARDoubleMatrix44 m44=this._inv_frustum_rh; |
| 432 |
|
|
double v1=(this._screen_size.w-ix-1)*2/this._screen_size.w-1.0;//ARToolKit���Frustram������������������ |
| 433 |
|
|
double v2=(this._screen_size.h-iy-1)*2/this._screen_size.h-1.0; |
| 434 |
|
|
double v3=2*n-1.0; |
| 435 |
|
|
double b=1/(m44.m30*v1+m44.m31*v2+m44.m32*v3+m44.m33); |
| 436 |
|
|
o_point_on_screen.x=(m44.m00*v1+m44.m01*v2+m44.m02*v3+m44.m03)*b; |
| 437 |
|
|
o_point_on_screen.y=(m44.m10*v1+m44.m11*v2+m44.m12*v3+m44.m13)*b; |
| 438 |
|
|
o_point_on_screen.z=(m44.m20*v1+m44.m21*v2+m44.m22*v3+m44.m23)*b; |
| 439 |
|
|
return; |
| 440 |
|
|
} |
| 441 |
|
|
*/ /** |
| 442 |
|
|
* ��������������������������������������������������������������������������������������������������������������������������������������������������������� |
| 443 |
|
|
* ��������������������������������������������� |
| 444 |
|
|
* @param ix |
| 445 |
|
|
* ��������������������������� |
| 446 |
|
|
* @param iy |
| 447 |
|
|
* ��������������������������� |
| 448 |
|
|
* @param i_mat |
| 449 |
|
|
* ������������������������������ |
| 450 |
|
|
* @param o_pos |
| 451 |
|
|
* ������������������������������������������������ |
| 452 |
nyatla |
420 |
*/ |
| 453 |
nyatla |
814 |
/* public final PVector unProjectOnCamera(double ix,double iy,PMatrix3D i_mat) |
| 454 |
|
|
{ |
| 455 |
|
|
//������������������ |
| 456 |
|
|
this.unProject(ix,iy,o_pos); |
| 457 |
|
|
//������������������������������ |
| 458 |
|
|
double nx=i_mat.m02; |
| 459 |
|
|
double ny=i_mat.m12; |
| 460 |
|
|
double nz=i_mat.m22; |
| 461 |
|
|
double mx=i_mat.m03; |
| 462 |
|
|
double my=i_mat.m13; |
| 463 |
|
|
double mz=i_mat.m23; |
| 464 |
|
|
double t=(nx*mx+ny*my+nz*mz)/(nx*o_pos.x+ny*o_pos.y+nz*o_pos.z); |
| 465 |
|
|
o_pos.x=t*o_pos.x; |
| 466 |
|
|
o_pos.y=t*o_pos.y; |
| 467 |
|
|
o_pos.z=t*o_pos.z; |
| 468 |
|
|
} |
| 469 |
|
|
*/ /** |
| 470 |
|
|
* ������������������������������������������������������������������������������������������������������������������������ |
| 471 |
|
|
* ARToolKit������P175��������������������������������� |
| 472 |
|
|
* @param ix |
| 473 |
|
|
* ��������������������������� |
| 474 |
|
|
* @param iy |
| 475 |
|
|
* ��������������������������� |
| 476 |
|
|
* @param i_mat |
| 477 |
|
|
* ������������������������������ |
| 478 |
|
|
* @param o_pos |
| 479 |
|
|
* ������������������������������������������������ |
| 480 |
|
|
* @return |
| 481 |
|
|
* ���������������������������true������������������ |
| 482 |
nyatla |
420 |
*/ |
| 483 |
nyatla |
814 |
/* public final PVector unProjectOnMatrix(double ix,double iy,PMatrix3D i_mat) |
| 484 |
nyatla |
420 |
{ |
| 485 |
nyatla |
814 |
//������������������������������������ |
| 486 |
|
|
unProjectOnCamera(ix,iy,i_mat,o_pos); |
| 487 |
|
|
//������������������ |
| 488 |
|
|
NyARDoubleMatrix44 m=new NyARDoubleMatrix44(); |
| 489 |
|
|
if(!m.inverse(i_mat)){ |
| 490 |
|
|
return false; |
| 491 |
nyatla |
420 |
} |
| 492 |
nyatla |
814 |
m.transform3d(o_pos, o_pos); |
| 493 |
|
|
return true; |
| 494 |
nyatla |
420 |
} |
| 495 |
nyatla |
814 |
*/ /** |
| 496 |
|
|
* ������������������������������������������������������������������������������ |
| 497 |
|
|
* @param i_x |
| 498 |
|
|
* ������������������������ |
| 499 |
|
|
* @param i_y |
| 500 |
|
|
* ������������������������ |
| 501 |
|
|
* @param i_z |
| 502 |
|
|
* ������������������������ |
| 503 |
|
|
* @param o_pos2d |
| 504 |
|
|
* ������������������������������������������������ |
| 505 |
nyatla |
420 |
*/ |
| 506 |
nyatla |
814 |
/* public final PVector project(double i_x,double i_y,double i_z) |
| 507 |
nyatla |
420 |
{ |
| 508 |
nyatla |
814 |
NyARDoubleMatrix44 m=this._frustum_rh; |
| 509 |
|
|
double v3_1=1/i_z*m.m32; |
| 510 |
|
|
double w=this._screen_size.w; |
| 511 |
|
|
double h=this._screen_size.h; |
| 512 |
|
|
o_pos2d.x=w-(1+(i_x*m.m00+i_z*m.m02)*v3_1)*w/2; |
| 513 |
|
|
o_pos2d.y=h-(1+(i_y*m.m11+i_z*m.m12)*v3_1)*h/2; |
| 514 |
nyatla |
420 |
return; |
| 515 |
|
|
} |
| 516 |
nyatla |
814 |
*/} |
| 517 |
nyatla |
420 |
|