2 * PROJECT: NyARToolkit JOGL utilities.
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.nyartoolkit.jogl.utils;
\r
34 import jp.nyatla.nyartoolkit.core.*;
\r
35 import jp.nyatla.nyartoolkit.core.param.NyARParam;
\r
38 * NyARParamにOpenGL向け関数を追加したもの
\r
40 public class GLNyARParam extends NyARParam
\r
42 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
44 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
46 private double[] m_projection = null;
\r
48 public void setViewDistanceMin(double i_new_value)
\r
50 m_projection = null;//キャッシュ済変数初期化
\r
51 view_distance_min = i_new_value;
\r
54 public void setViewDistanceMax(double i_new_value)
\r
56 m_projection = null;//キャッシュ済変数初期化
\r
57 view_distance_max = i_new_value;
\r
61 * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])
\r
67 public double[] getCameraFrustumRH()
\r
69 //既に値がキャッシュされていたらそれを使う
\r
70 if (m_projection != null) {
\r
71 return m_projection;
\r
74 m_projection = new double[16];
\r
75 NyARMat trans_mat = new NyARMat(3, 4);
\r
76 NyARMat icpara_mat = new NyARMat(3, 4);
\r
77 double[][] p = new double[3][3], q = new double[4][4];
\r
81 final int width = this._screen_size.w;
\r
82 final int height = this._screen_size.h;
\r
84 this.getPerspectiveProjectionMatrix().decompMat(icpara_mat, trans_mat);
\r
86 double[][] icpara = icpara_mat.getArray();
\r
87 double[][] trans = trans_mat.getArray();
\r
88 for (i = 0; i < 4; i++) {
\r
89 icpara[1][i] = (height - 1) * (icpara[2][i]) - icpara[1][i];
\r
92 for (i = 0; i < 3; i++) {
\r
93 for (j = 0; j < 3; j++) {
\r
94 p[i][j] = icpara[i][j] / icpara[2][2];
\r
97 q[0][0] = (2.0 * p[0][0] / (width - 1));
\r
98 q[0][1] = (2.0 * p[0][1] / (width - 1));
\r
99 q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);
\r
103 q[1][1] = -(2.0 * p[1][1] / (height - 1));
\r
104 q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);
\r
109 q[2][2] = (view_distance_max + view_distance_min) / (view_distance_min - view_distance_max);
\r
110 q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);
\r
117 for (i = 0; i < 4; i++) { // Row.
\r
118 // First 3 columns of the current row.
\r
119 for (j = 0; j < 3; j++) { // Column.
\r
120 m_projection[i + j * 4] = q[i][0] * trans[0][j] + q[i][1] * trans[1][j] + q[i][2] * trans[2][j];
\r
122 // Fourth column of the current row.
\r
123 m_projection[i + 3 * 4] = q[i][0] * trans[0][3] + q[i][1] * trans[1][3] + q[i][2] * trans[2][3] + q[i][3];
\r
125 return m_projection;
\r