| 28 |
package jp.nyatla.nyar4psg; |
package jp.nyatla.nyar4psg; |
| 29 |
|
|
| 30 |
|
|
|
import javax.media.opengl.*; |
|
|
|
|
| 31 |
import processing.core.*; |
import processing.core.*; |
|
import processing.opengl.*; |
|
|
|
|
| 32 |
|
|
| 33 |
import jp.nyatla.nyartoolkit.*; |
import jp.nyatla.nyartoolkit.*; |
| 34 |
import jp.nyatla.nyartoolkit.core.param.*; |
import jp.nyatla.nyartoolkit.core.param.*; |
| 52 |
* バージョン文字列です。 |
* バージョン文字列です。 |
| 53 |
* NyAR4psgのバージョン情報を示します。 |
* NyAR4psgのバージョン情報を示します。 |
| 54 |
*/ |
*/ |
| 55 |
public final static String VERSION = "NyAR4psg/1.0.1;NyARToolkit for java/3.0.0+;ARToolKit/2.72.1"; |
public final static String VERSION = "NyAR4psg/1.0.3;NyARToolkit for java/3.0.0+;ARToolKit/2.72.1"; |
| 56 |
/** 参照するAppletのインスタンスです。*/ |
/** 参照するAppletのインスタンスです。*/ |
| 57 |
protected PApplet _ref_papplet; |
protected PApplet _ref_papplet; |
| 58 |
/** ProcessingスタイルのProjectionMatrixです。*/ |
/** ProcessingスタイルのProjectionMatrixです。*/ |
| 66 |
protected PImageRaster _src_raster; |
protected PImageRaster _src_raster; |
| 67 |
/** 画像抽出用のオブジェクトです。{@link #_src_raster}を参照します。*/ |
/** 画像抽出用のオブジェクトです。{@link #_src_raster}を参照します。*/ |
| 68 |
protected NyARPerspectiveRasterReader _preader; |
protected NyARPerspectiveRasterReader _preader; |
|
private int _g_type; |
|
| 69 |
/** |
/** |
| 70 |
* コンストラクタです。 |
* コンストラクタです。 |
| 71 |
*/ |
*/ |
| 79 |
this._src_raster=new PImageRaster(i_width,i_height); |
this._src_raster=new PImageRaster(i_width,i_height); |
| 80 |
this._preader=new NyARPerspectiveRasterReader(this._src_raster.getBufferType()); |
this._preader=new NyARPerspectiveRasterReader(this._src_raster.getBufferType()); |
| 81 |
try{ |
try{ |
|
this._g_type=getGraphicsType(parent.g); |
|
| 82 |
this._ar_param.loadARParam(this._ref_papplet.createInput(i_cparam_file)); |
this._ar_param.loadARParam(this._ref_papplet.createInput(i_cparam_file)); |
| 83 |
this._ar_param.changeScreenSize(i_width, i_height); |
this._ar_param.changeScreenSize(i_width, i_height); |
| 84 |
|
|
| 89 |
} |
} |
| 90 |
return; |
return; |
| 91 |
} |
} |
| 92 |
private final static double view_distance_min = 100; |
private final static float view_distance_min = 100; |
| 93 |
private final static double view_distance_max = 100000; |
private final static float view_distance_max = 100000; |
|
private final static int GT_P3D=0; |
|
|
private final static int GT_OPENGL=1; |
|
|
/** |
|
|
* {@link PGraphics}をグラフィクス定数に変換します。 |
|
|
* @param i_g |
|
|
* @return |
|
|
* @throws NyARException |
|
|
*/ |
|
|
private static int getGraphicsType(PGraphics i_g) throws NyARException |
|
|
{ |
|
|
String n=i_g.getClass().getName(); |
|
|
if(n.compareTo("processing.opengl.PGraphicsOpenGL")==0){ |
|
|
return GT_OPENGL; |
|
|
}else if(n.compareTo("processing.core.PGraphics3D")==0){ |
|
|
return GT_P3D; |
|
|
} |
|
|
throw new NyARException("Unknown Graphics"); |
|
|
|
|
|
} |
|
| 94 |
|
|
| 95 |
|
|
|
private float[] _tmpf=new float[16]; |
|
|
|
|
| 96 |
/** |
/** |
| 97 |
* この関数は、ARToolKit準拠のProjectionMatrixをProcessingにセットします。 |
* この関数は、ARToolKit準拠のProjectionMatrixをProcessingにセットします。 |
| 98 |
* 関数を実行すると、ProcessingのProjectionMatrixがARToolKitのカメラパラメータのものに変わり、映像にマッチした描画ができるようになります。 |
* 関数を実行すると、ProcessingのProjectionMatrixがARToolKitのカメラパラメータのものに変わり、映像にマッチした描画ができるようになります。 |
| 111 |
* 設定するProjectionMatrixを指定します。 |
* 設定するProjectionMatrixを指定します。 |
| 112 |
* @return |
* @return |
| 113 |
* 置き換えら得る前のprojectionMatrixを返します。 |
* 置き換えら得る前のprojectionMatrixを返します。 |
| 114 |
|
* |
| 115 |
|
* <p> |
| 116 |
|
* Processing/1.3になったら、{@link PApplet#matrixMode}使ってきちんと使えるようになると思う。 |
| 117 |
|
* 今は無理なので、frustum経由 |
| 118 |
|
* </p> |
| 119 |
*/ |
*/ |
| 120 |
public PMatrix3D setPerspective(PMatrix3D i_projection) |
public PMatrix3D setPerspective(PMatrix3D i_projection) |
| 121 |
{ |
{ |
| 126 |
//現在のProjectionMatrixを保存する。 |
//現在のProjectionMatrixを保存する。 |
| 127 |
PMatrix3D ret=new PMatrix3D(); |
PMatrix3D ret=new PMatrix3D(); |
| 128 |
ret.set(g.projection); |
ret.set(g.projection); |
| 129 |
//ProjectionMatrixの設定 |
//Projectionをfrustum経由で設定。 |
| 130 |
g.projection.set(i_projection); |
float far=i_projection.m23/(i_projection.m22+1); |
| 131 |
//OpenGLの時はちょっと細工 |
float near=i_projection.m23/(i_projection.m22-1); |
| 132 |
if(this._g_type==GT_OPENGL) |
this._ref_papplet.frustum( |
| 133 |
{ |
(i_projection.m02-1)*near/i_projection.m00, |
| 134 |
GL gl=((PGraphicsOpenGL)g).gl; |
(i_projection.m02+1)*near/i_projection.m00, |
| 135 |
gl.glMatrixMode(GL.GL_PROJECTION); |
(i_projection.m12-1)*near/i_projection.m11, |
| 136 |
PMatrix2GLProjection(i_projection,_tmpf); |
(i_projection.m12+1)*near/i_projection.m11, |
| 137 |
gl.glLoadMatrixf(_tmpf,0); |
near,far); |
|
} |
|
| 138 |
return ret; |
return ret; |
| 139 |
} |
} |
| 140 |
|
|