* HITLab, University of Washington, Seattle\r
* http://www.hitl.washington.edu/artoolkit/\r
*\r
- * The NyARToolkit is Java version ARToolkit class library.\r
- * Copyright (C)2008 R.Iizuka\r
+ * The NyARToolkit is Java edition ARToolKit class library.\r
+ * Copyright (C)2008-2009 Ryo Iizuka\r
*\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
* \r
* This program is distributed in the hope that it will be useful,\r
* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
* GNU General Public License for more details.\r
- * \r
+ *\r
* You should have received a copy of the GNU General Public License\r
- * along with this framework; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
* \r
* For further information please contact.\r
* http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp>\r
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
* \r
*/\r
package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;\r
import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
import jp.nyatla.nyartoolkit.core.types.*;\r
import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix33;\r
* 回転行列計算用の、3x3行列\r
*\r
*/\r
-public abstract class NyARRotMatrix extends NyARDoubleMatrix33\r
-{ \r
+public class NyARRotMatrix extends NyARDoubleMatrix33\r
+{\r
/**\r
- * NyARTransMatResultの内容からNyARRotMatrixを復元します。\r
- * @param i_prev_result\r
+ * インスタンスを準備します。\r
+ * \r
+ * @param i_param\r
*/\r
- public abstract void initRotByPrevResult(NyARTransMatResult i_prev_result);\r
- public abstract void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException;\r
+ public NyARRotMatrix(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException\r
+ {\r
+ this.__initRot_vec1=new NyARRotVector(i_matrix);\r
+ this.__initRot_vec2=new NyARRotVector(i_matrix);\r
+ return;\r
+ }\r
+ final private NyARRotVector __initRot_vec1;\r
+ final private NyARRotVector __initRot_vec2;\r
/**\r
- * int arGetAngle( double rot[3][3], double *wa, double *wb, double *wc )\r
- * Optimize:2008.04.20:STEP[481→433]\r
- * 3x3変換行列から、回転角を復元して返します。\r
- * @param o_angle\r
- * @return\r
+ * NyARTransMatResultの内容からNyARRotMatrixを復元します。\r
+ * @param i_prev_result\r
*/\r
- public abstract void getAngle(final NyARDoublePoint3d o_angle);\r
+ public final void initRotByPrevResult(NyARTransMatResult i_prev_result)\r
+ {\r
+\r
+ this.m00=i_prev_result.m00;\r
+ this.m01=i_prev_result.m01;\r
+ this.m02=i_prev_result.m02;\r
+\r
+ this.m10=i_prev_result.m10;\r
+ this.m11=i_prev_result.m11;\r
+ this.m12=i_prev_result.m12;\r
+\r
+ this.m20=i_prev_result.m20;\r
+ this.m21=i_prev_result.m21;\r
+ this.m22=i_prev_result.m22;\r
+ return;\r
+ } \r
/**\r
- * 回転角から回転行列を計算してセットします。\r
- * @param i_x\r
- * @param i_y\r
- * @param i_z\r
+ * \r
+ * @param i_linear\r
+ * @param i_sqvertex\r
+ * @throws NyARException\r
*/\r
- public abstract void setAngle(final double i_x, final double i_y, final double i_z);\r
+ public void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException\r
+ {\r
+ final NyARRotVector vec1=this.__initRot_vec1;\r
+ final NyARRotVector vec2=this.__initRot_vec2;\r
+\r
+ //向かい合った辺から、2本のベクトルを計算\r
+ \r
+ //軸1\r
+ vec1.exteriorProductFromLinear(i_linear[0], i_linear[2]);\r
+ vec1.checkVectorByVertex(i_sqvertex[0], i_sqvertex[1]);\r
+\r
+ //軸2\r
+ vec2.exteriorProductFromLinear(i_linear[1], i_linear[3]);\r
+ vec2.checkVectorByVertex(i_sqvertex[3], i_sqvertex[0]);\r
+\r
+ //回転の最適化?\r
+ NyARRotVector.checkRotation(vec1,vec2);\r
+\r
+ this.m00 =vec1.v1;\r
+ this.m10 =vec1.v2;\r
+ this.m20 =vec1.v3;\r
+ this.m01 =vec2.v1;\r
+ this.m11 =vec2.v2;\r
+ this.m21 =vec2.v3;\r
+ \r
+ //最後の軸を計算\r
+ final double w02 = vec1.v2 * vec2.v3 - vec1.v3 * vec2.v2;\r
+ final double w12 = vec1.v3 * vec2.v1 - vec1.v1 * vec2.v3;\r
+ final double w22 = vec1.v1 * vec2.v2 - vec1.v2 * vec2.v1;\r
+ final double w = Math.sqrt(w02 * w02 + w12 * w12 + w22 * w22);\r
+ this.m02 = w02/w;\r
+ this.m12 = w12/w;\r
+ this.m22 = w22/w;\r
+ return;\r
+ }\r
/**\r
* i_in_pointを変換行列で座標変換する。\r
* @param i_in_point\r
* @param i_out_point\r
- */ \r
- public abstract void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point);\r
+ */\r
+ public final void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point)\r
+ {\r
+ final double x=i_in_point.x;\r
+ final double y=i_in_point.y;\r
+ final double z=i_in_point.z;\r
+ i_out_point.x=this.m00 * x + this.m01 * y + this.m02 * z;\r
+ i_out_point.y=this.m10 * x + this.m11 * y + this.m12 * z;\r
+ i_out_point.z=this.m20 * x + this.m21 * y + this.m22 * z;\r
+ return;\r
+ }\r
/**\r
* 複数の頂点を一括して変換する\r
* @param i_in_point\r
* @param i_out_point\r
* @param i_number_of_vertex\r
*/\r
- public abstract void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex);\r
+ public final void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex)\r
+ {\r
+ for(int i=i_number_of_vertex-1;i>=0;i--){\r
+ final NyARDoublePoint3d out_ptr=i_out_point[i];\r
+ final NyARDoublePoint3d in_ptr=i_in_point[i];\r
+ final double x=in_ptr.x;\r
+ final double y=in_ptr.y;\r
+ final double z=in_ptr.z;\r
+ out_ptr.x=this.m00 * x + this.m01 * y + this.m02 * z;\r
+ out_ptr.y=this.m10 * x + this.m11 * y + this.m12 * z;\r
+ out_ptr.z=this.m20 * x + this.m21 * y + this.m22 * z;\r
+ }\r
+ return;\r
+ }\r
}\r