OSDN Git Service

6a885ce07eafb6759d57b4ab817142d06c294707
[nyartoolkit-and/nyartoolkit-and.git] / utils / jogl / src / jp / nyatla / nyartoolkit / jogl / utils / NyARGLUtil.java
1 /* \r
2  * PROJECT: NyARToolkit JOGL utilities.\r
3  * --------------------------------------------------------------------------------\r
4  * This work is based on the original ARToolKit developed by\r
5  *   Hirokazu Kato\r
6  *   Mark Billinghurst\r
7  *   HITLab, University of Washington, Seattle\r
8  * http://www.hitl.washington.edu/artoolkit/\r
9  *\r
10  * The NyARToolkit is Java edition ARToolKit class library.\r
11  * Copyright (C)2008-2009 Ryo Iizuka\r
12  *\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
17  * \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
22  *\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
25  * \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
29  * \r
30  */\r
31 package jp.nyatla.nyartoolkit.jogl.utils;\r
32 \r
33 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
34 import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;\r
35 import jp.nyatla.nyartoolkit.core.types.*;\r
36 import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
37 /**\r
38  * OpenGL向けの形式変換変換関数を提供します。\r
39  * 描画系関数は{@link NyARGLDrawUtil}を参照してください。\r
40  */\r
41 public class NyARGLUtil\r
42 {\r
43         /**\r
44          * NyARToolKit 2.53以前のコードと互換性を持たせるためのスケール値。{@link #toCameraFrustumRH}のi_scaleに設定することで、\r
45          * 以前のバージョンの数値系と互換性を保ちます。\r
46          */\r
47         public final static double SCALE_FACTOR_toCameraFrustumRH_NYAR2=1.0;\r
48         /**\r
49          * NyARToolKit 2.53以前のコードと互換性を持たせるためのスケール値。{@link #toCameraViewRH}のi_scaleに設定することで、\r
50          * 以前のバージョンの数値系と互換性を保ちます。\r
51          */\r
52         public final static double SCALE_FACTOR_toCameraViewRH_NYAR2=1/0.025;\r
53 \r
54     private NyARGLUtil()\r
55     {//生成の禁止\r
56     }   \r
57 \r
58         \r
59         /**\r
60          * ARToolKitスタイルのカメラパラメータから、 CameraFrustamを計算します。\r
61          * @param i_arparam\r
62          * @param i_scale\r
63          * スケール値を指定します。1=1mmです。10ならば1=1cm,1000ならば1=1mです。\r
64          * 2.53以前のNyARToolkitと互換性を持たせるときは、{@link #SCALE_FACTOR_toCameraFrustumRH_NYAR2}を指定してください。\r
65          * @param i_near\r
66          * 視錐体のnearPointを指定します。単位は、i_scaleに設定した値で決まります。\r
67          * @param i_far\r
68          * 視錐体のfarPointを指定します。単位は、i_scaleに設定した値で決まります。\r
69          * @param o_gl_projection\r
70          */\r
71         public static void toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)\r
72         {\r
73                 toCameraFrustumRH(i_arparam.getPerspectiveProjectionMatrix(),i_arparam.getScreenSize(),i_scale,i_near,i_far,o_gl_projection);\r
74                 return;\r
75         }\r
76         /**\r
77          * ARToolKitスタイルのProjectionMatrixから、 CameraFrustamを計算します。\r
78          * @param i_promat\r
79          * @param i_size\r
80          * スクリーンサイズを指定します。\r
81          * @param i_scale\r
82          * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。\r
83          * @param i_near\r
84          * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。\r
85          * @param i_far\r
86          * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。\r
87          * @param o_gl_projection\r
88          * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。\r
89          */\r
90         public static void toCameraFrustumRH(NyARPerspectiveProjectionMatrix i_promat,NyARIntSize i_size,double i_scale,double i_near,double i_far,double[] o_gl_projection)\r
91         {\r
92                 NyARDoubleMatrix44 m=new NyARDoubleMatrix44();\r
93                 i_promat.makeCameraFrustumRH(i_size.w,i_size.h,i_near*i_scale,i_far*i_scale,m);\r
94                 m.getValueT(o_gl_projection);\r
95                 return;\r
96         }\r
97         /**\r
98          * NyARTransMatResultをOpenGLの行列へ変換します。\r
99          * @param mat\r
100          * 変換元の行列\r
101          * @param i_scale\r
102          * 座標系のスケール値を指定します。1=1mmです。10ならば1=1cm,1000ならば1=1mです。\r
103          * 2.53以前のNyARToolkitと互換性を持たせるときは、{@link #SCALE_FACTOR_toCameraViewRH_NYAR2}を指定してください。\r
104          * @param o_gl_result\r
105          */\r
106         public static void toCameraViewRH(NyARDoubleMatrix44 mat,double i_scale, double[] o_gl_result)\r
107         {\r
108                 o_gl_result[0 + 0 * 4] = mat.m00; \r
109                 o_gl_result[1 + 0 * 4] = -mat.m10;\r
110                 o_gl_result[2 + 0 * 4] = -mat.m20;\r
111                 o_gl_result[3 + 0 * 4] = 0.0;\r
112                 o_gl_result[0 + 1 * 4] = mat.m01;\r
113                 o_gl_result[1 + 1 * 4] = -mat.m11;\r
114                 o_gl_result[2 + 1 * 4] = -mat.m21;\r
115                 o_gl_result[3 + 1 * 4] = 0.0;\r
116                 o_gl_result[0 + 2 * 4] = mat.m02;\r
117                 o_gl_result[1 + 2 * 4] = -mat.m12;\r
118                 o_gl_result[2 + 2 * 4] = -mat.m22;\r
119                 o_gl_result[3 + 2 * 4] = 0.0;\r
120                 \r
121                 double scale=1/i_scale;\r
122                 o_gl_result[0 + 3 * 4] = mat.m03*scale;\r
123                 o_gl_result[1 + 3 * 4] = -mat.m13*scale;\r
124                 o_gl_result[2 + 3 * 4] = -mat.m23*scale;\r
125                 o_gl_result[3 + 3 * 4] = 1.0;\r
126                 return;\r
127         }\r
128 \r
129 \r
130         \r
131 }\r