2 * PROJECT: NyARToolkit Java3D utilities.
\r
3 * --------------------------------------------------------------------------------
\r
5 * Copyright (c) 2008 nyatla
\r
6 * airmail(at)ebony.plala.or.jp
\r
7 * http://nyatla.jp/nyartoolkit/
\r
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
10 * of this software and associated documentation files (the "Software"), to deal
\r
11 * in the Software without restriction, including without limitation the rights
\r
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
13 * copies of the Software, and to permit persons to whom the Software is
\r
14 * furnished to do so, subject to the following conditions:
\r
15 * The above copyright notice and this permission notice shall be included in
\r
16 * all copies or substantial portions of the Software.
\r
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
27 package jp.nyatla.nyartoolkit.java3d.utils;
\r
29 import jp.nyatla.nyartoolkit.core.*;
\r
30 import jp.nyatla.nyartoolkit.core.param.NyARParam;
\r
32 import javax.media.j3d.Transform3D;
\r
34 * NyARParamにJava3D向け関数を追加したもの
\r
36 public class J3dNyARParam extends NyARParam
\r
38 private double view_distance_min = 0.01;//1cm~10.0m
\r
40 private double view_distance_max = 10.0;
\r
42 private Transform3D m_projection = null;
\r
46 * @param i_new_value
\r
48 public void setViewDistanceMin(double i_new_value)
\r
50 m_projection = null;//キャッシュ済変数初期化
\r
51 view_distance_min = i_new_value;
\r
56 * @param i_new_value
\r
58 public void setViewDistanceMax(double i_new_value)
\r
60 m_projection = null;//キャッシュ済変数初期化
\r
61 view_distance_max = i_new_value;
\r
65 * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])
\r
71 public Transform3D getCameraTransform()
\r
73 //既に値がキャッシュされていたらそれを使う
\r
74 if (m_projection != null) {
\r
75 return m_projection;
\r
79 NyARMat trans_mat = new NyARMat(3, 4);
\r
80 NyARMat icpara_mat = new NyARMat(3, 4);
\r
81 double[][] p = new double[3][3], q = new double[4][4];
\r
82 double width, height;
\r
85 width = this._screen_size.w;
\r
86 height = this._screen_size.h;
\r
88 this.getPerspectiveProjectionMatrix().decompMat(icpara_mat, trans_mat);
\r
90 double[][] icpara = icpara_mat.getArray();
\r
91 double[][] trans = trans_mat.getArray();
\r
92 for (i = 0; i < 4; i++) {
\r
93 icpara[1][i] = (height - 1) * (icpara[2][i]) - icpara[1][i];
\r
96 for (i = 0; i < 3; i++) {
\r
97 for (j = 0; j < 3; j++) {
\r
98 p[i][j] = icpara[i][j] / icpara[2][2];
\r
101 //p[0][0],p[1][1]=n
\r
102 //p[0][2],p[1][2]=t+b
\r
105 q[0][0] = (2.0 * p[0][0] / (width - 1));
\r
106 q[0][1] = (2.0 * p[0][1] / (width - 1));
\r
107 q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);
\r
111 q[1][1] = -(2.0 * p[1][1] / (height - 1));
\r
112 q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);
\r
117 q[2][2] = (view_distance_max + view_distance_min) / (view_distance_min - view_distance_max);
\r
118 q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);
\r
125 q[2][2] = q[2][2] * -1;
\r
126 q[2][3] = q[2][3] * -1;
\r
128 double[] tmp_projection = new double[16];
\r
129 for (i = 0; i < 4; i++) { // Row.
\r
130 // First 3 columns of the current row.
\r
131 for (j = 0; j < 3; j++) { // Column.
\r
132 tmp_projection[i + j * 4] = (q[i][0] * trans[0][j] + q[i][1] * trans[1][j] + q[i][2] * trans[2][j]);
\r
134 // Fourth column of the current row.
\r
135 tmp_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
137 m_projection = new Transform3D(tmp_projection);
\r
138 m_projection.transpose();
\r
139 return m_projection;
\r