2 * NyARParamにOpenGL向け関数を追加したもの
\r
3 * (c)2008 A虎@nyatla.jp
\r
4 * airmail(at)ebony.plala.or.jp
\r
7 package jp.nyatla.nyartoolkit.jogl.utils;
\r
9 import jp.nyatla.nyartoolkit.core.*;
\r
10 public class GLNyARParam extends NyARParam
\r
12 private double view_distance_min=0.1;//#define VIEW_DISTANCE_MIN 0.1 // Objects closer to the camera than this will not be displayed.
\r
13 private double view_distance_max=100.0;//#define VIEW_DISTANCE_MAX 100.0 // Objects further away from the camera than this will not be displayed.
\r
14 private double[] m_projection=null;
\r
15 public void setViewDistanceMin(double i_new_value)
\r
17 m_projection=null;//キャッシュ済変数初期化
\r
18 view_distance_min=i_new_value;
\r
20 public void setViewDistanceMax(double i_new_value)
\r
22 m_projection=null;//キャッシュ済変数初期化
\r
23 view_distance_max=i_new_value;
\r
26 * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])
\r
32 public double[] getCameraFrustumRH()
\r
34 //既に値がキャッシュされていたらそれを使う
\r
35 if(m_projection!=null){
\r
36 return m_projection;
\r
39 m_projection=new double[16];
\r
40 NyARMat trans_mat=new NyARMat(3,4);
\r
41 NyARMat icpara_mat=new NyARMat(3,4);
\r
42 double[][] p=new double[3][3], q=new double[4][4];
\r
49 decompMat(icpara_mat,trans_mat);
\r
51 double[][] icpara=icpara_mat.getArray();
\r
52 double[][] trans=trans_mat.getArray();
\r
53 for (i = 0; i < 4; i++) {
\r
54 icpara[1][i] = (height - 1)*(icpara[2][i]) - icpara[1][i];
\r
57 for(i = 0; i < 3; i++) {
\r
58 for(j = 0; j < 3; j++) {
\r
59 p[i][j] = icpara[i][j] / icpara[2][2];
\r
62 q[0][0] = (2.0 * p[0][0] / (width - 1));
\r
63 q[0][1] = (2.0 * p[0][1] / (width - 1));
\r
64 q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);
\r
68 q[1][1] = -(2.0 * p[1][1] / (height - 1));
\r
69 q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);
\r
74 q[2][2] = (view_distance_max + view_distance_min)/(view_distance_min - view_distance_max);
\r
75 q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);
\r
82 for (i = 0; i < 4; i++) { // Row.
\r
83 // First 3 columns of the current row.
\r
84 for (j = 0; j < 3; j++) { // Column.
\r
85 m_projection[i + j*4] =
\r
86 q[i][0] * trans[0][j] +
\r
87 q[i][1] * trans[1][j] +
\r
88 q[i][2] * trans[2][j];
\r
90 // Fourth column of the current row.
\r
91 m_projection[i + 3*4]=
\r
92 q[i][0] * trans[0][3] +
\r
93 q[i][1] * trans[1][3] +
\r
94 q[i][2] * trans[2][3] +
\r
97 return m_projection;
\r