2 * PROJECT: NyARToolkit
\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 edition ARToolKit class library.
\r
11 * Copyright (C)2008-2009 Ryo Iizuka
\r
13 * This program is free software: you can redistribute it and/or modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or
\r
16 * (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 program. If not, see <http://www.gnu.org/licenses/>.
\r
26 * For further information please contact.
\r
27 * http://nyatla.jp/nyatoolkit/
\r
28 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
31 package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
\r
33 import jp.nyatla.nyartoolkit.NyARException;
\r
34 import jp.nyatla.nyartoolkit.core.types.*;
\r
35 import jp.nyatla.nyartoolkit.core.param.*;
\r
40 public class NyARRotMatrix_ARToolKit extends NyARRotMatrix
\r
47 public NyARRotMatrix_ARToolKit(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
\r
50 this._angle=new NyARDoublePoint3d();
\r
53 final protected NyARDoublePoint3d _angle;
\r
57 public final void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException
\r
59 super.initRotBySquare(i_linear,i_sqvertex);
\r
61 this.updateAngleFromMatrix();
\r
64 public final NyARDoublePoint3d refAngle()
\r
69 * 回転角から回転行列を計算してセットします。
\r
74 public void setAngle(final double i_x, final double i_y, final double i_z)
\r
76 final double sina = Math.sin(i_x);
\r
77 final double cosa = Math.cos(i_x);
\r
78 final double sinb = Math.sin(i_y);
\r
79 final double cosb = Math.cos(i_y);
\r
80 final double sinc = Math.sin(i_z);
\r
81 final double cosc = Math.cos(i_z);
\r
83 final double CACA = cosa * cosa;
\r
84 final double SASA = sina * sina;
\r
85 final double SACA = sina * cosa;
\r
86 final double SASB = sina * sinb;
\r
87 final double CASB = cosa * sinb;
\r
88 final double SACACB = SACA * cosb;
\r
90 this.m00 = CACA * cosb * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
\r
91 this.m01 = -CACA * cosb * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
\r
93 this.m10 = SACACB * cosc - SACA * cosc + SASA * cosb * sinc + CACA * sinc;
\r
94 this.m11 = -SACACB * sinc + SACA * sinc + SASA * cosb * cosc + CACA * cosc;
\r
96 this.m20 = -CASB * cosc - SASB * sinc;
\r
97 this.m21 = CASB * sinc - SASB * cosc;
\r
99 updateAngleFromMatrix();
\r
103 * 現在のMatrixからangkeを復元する。
\r
106 private final void updateAngleFromMatrix()
\r
109 double sina, cosa, sinb,cosb,sinc, cosc;
\r
111 if (this.m22 > 1.0) {// <Optimize/>if( rot[2][2] > 1.0 ) {
\r
112 cosb = 1.0;// <Optimize/>rot[2][2] = 1.0;
\r
113 } else if (this.m22 < -1.0) {// <Optimize/>}else if( rot[2][2] < -1.0 ) {
\r
114 cosb = -1.0;// <Optimize/>rot[2][2] = -1.0;
\r
116 cosb =this.m22;// <Optimize/>cosb = rot[2][2];
\r
118 b = Math.acos(cosb);
\r
120 final double rot02=this.m02;
\r
121 final double rot12=this.m12;
\r
122 if (b >= 0.000001 || b <= -0.000001) {
\r
123 cosa = rot02 / sinb;// <Optimize/>cosa = rot[0][2] / sinb;
\r
124 sina = rot12 / sinb;// <Optimize/>sina = rot[1][2] / sinb;
\r
141 a = Math.acos(cosa);
\r
145 final double tmp = (rot02 * rot02 + rot12 * rot12);
\r
146 sinc = (this.m21 * rot02 - this.m20 * rot12) / tmp;
\r
147 cosc = -(rot02 * this.m20 + rot12 * this.m21) / tmp;
\r
165 c = Math.acos(cosc);
\r
173 cosc=this.m00;//cosc = rot[0];// <Optimize/>cosc = rot[0][0];
\r
174 sinc=this.m01;//sinc = rot[1];// <Optimize/>sinc = rot[1][0];
\r
191 c = Math.acos(cosc);
\r
197 this._angle.x = a;// wa.value=a;//*wa = a;
\r
198 this._angle.y = b;// wb.value=b;//*wb = b;
\r
199 this._angle.z = c;// wc.value=c;//*wc = c;
\r