OSDN Git Service

NyARToolkit for Java
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Tue, 30 Nov 2010 01:51:35 +0000 (01:51 +0000)
committerAtsuo Igarashi <atsuoigarashi@ubuntu.(none)>
Tue, 5 Apr 2011 04:12:48 +0000 (13:12 +0900)
3.0.0の反映作業

git-svn-id: http://svn.sourceforge.jp/svnroot/nyartoolkit/NyARToolkit/trunk@653 7cac0a50-4618-4814-88d0-24b83990f816

sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JpegSimpleLite.java [deleted file]
utils/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java
utils/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
utils/jmf/src/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDevice.java
utils/jmf/src/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
utils/jmf/src/jp/nyatla/nyartoolkit/jmf/utils/sample/LabelingViewer.java [moved from sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/LabelingViewer.java with 99% similarity]
utils/jmf/src/jp/nyatla/nyartoolkit/jmf/utils/sample/NyarToolkitLinkTest.java [moved from sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java with 99% similarity]
utils/jogl/src/jp/nyatla/nyartoolkit/jogl/utils/NyARGLDrawUtil.java [new file with mode: 0644]
utils/jogl/src/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java

diff --git a/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JpegSimpleLite.java b/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JpegSimpleLite.java
deleted file mode 100644 (file)
index 1b1cfd5..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-/* \r
- * PROJECT: NyARToolkit JOGL sample program.\r
- * --------------------------------------------------------------------------------\r
- * The MIT License\r
- * Copyright (c) 2008 nyatla\r
- * airmail(at)ebony.plala.or.jp\r
- * http://nyatla.jp/nyartoolkit/\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a copy\r
- * of this software and associated documentation files (the "Software"), to deal\r
- * in the Software without restriction, including without limitation the rights\r
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
- * copies of the Software, and to permit persons to whom the Software is\r
- * furnished to do so, subject to the following conditions:\r
- * The above copyright notice and this permission notice shall be included in\r
- * all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
- * THE SOFTWARE.\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.jogl.sample;\r
-\r
-import java.awt.event.*;\r
-import java.awt.*;\r
-import javax.media.Buffer;\r
-import javax.media.opengl.*;\r
-import com.sun.opengl.util.*;\r
-import jp.nyatla.nyartoolkit.*;\r
-import jp.nyatla.nyartoolkit.core.*;\r
-import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.transmat.*;\r
-import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
-import jp.nyatla.nyartoolkit.detector.*;\r
-import jp.nyatla.nyartoolkit.jogl.utils.*;\r
-import javax.imageio.*;\r
-import java.awt.image.*;\r
-import java.io.*;\r
-import jp.nyatla.nyartoolkit.utils.j2se.*;\r
-\r
-/**\r
- * simpleLiteと同じようなテストプログラム 出来る限りARToolKitのサンプルと似せて作ってあります。 最も一致する"Hiro"マーカーを一つ選択して、その上に立方体を表示します。\r
- * \r
- */\r
-public class JpegSimpleLite implements GLEventListener\r
-{\r
-       private Animator _animator;\r
-\r
-       private NyARRgbRaster_RGB _src_image;\r
-\r
-       private GL _gl;\r
-\r
-       private NyARGLUtil _glnya;\r
-\r
-       // NyARToolkit関係\r
-       private NyARSingleDetectMarker _nya;\r
-\r
-       private NyARParam _ar_param;\r
-\r
-       private Object _sync_object=new Object();\r
-       private double[] _camera_projection = new double[16];\r
-\r
-       /**\r
-        * 立方体を書く\r
-        * \r
-        */\r
-       void drawCube()\r
-       {\r
-               // Colour cube data.\r
-               int polyList = 0;\r
-               float fSize = 0.5f;// マーカーサイズに対して0.5倍なので、4cmの立方体\r
-               int f, i;\r
-               float[][] cube_vertices = new float[][] { { 1.0f, 1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, { -1.0f, -1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, { -1.0f, -1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f } };\r
-               float[][] cube_vertex_colors = new float[][] { { 1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } };\r
-               int cube_num_faces = 6;\r
-               short[][] cube_faces = new short[][] { { 3, 2, 1, 0 }, { 2, 3, 7, 6 }, { 0, 1, 5, 4 }, { 3, 0, 4, 7 }, { 1, 2, 6, 5 }, { 4, 5, 6, 7 } };\r
-\r
-               if (polyList == 0) {\r
-                       polyList = _gl.glGenLists(1);\r
-                       _gl.glNewList(polyList, GL.GL_COMPILE);\r
-                       _gl.glBegin(GL.GL_QUADS);\r
-                       for (f = 0; f < cube_num_faces; f++)\r
-                               for (i = 0; i < 4; i++) {\r
-                                       _gl.glColor3f(cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);\r
-                                       _gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
-                               }\r
-                       _gl.glEnd();\r
-                       _gl.glColor3f(0.0f, 0.0f, 0.0f);\r
-                       for (f = 0; f < cube_num_faces; f++) {\r
-                               _gl.glBegin(GL.GL_LINE_LOOP);\r
-                               for (i = 0; i < 4; i++)\r
-                                       _gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
-                               _gl.glEnd();\r
-                       }\r
-                       _gl.glEndList();\r
-               }\r
-\r
-               _gl.glPushMatrix(); // Save world coordinate system.\r
-               _gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.\r
-               _gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.\r
-               _gl.glDisable(GL.GL_LIGHTING); // Just use colours.\r
-               _gl.glCallList(polyList); // Draw the cube.\r
-               _gl.glPopMatrix(); // Restore world coordinate system.\r
-\r
-       }\r
-\r
-       public JpegSimpleLite(NyARParam i_param, NyARCode i_ar_code,BufferedImage i_image) throws NyARException,IOException\r
-       {\r
-               this._ar_param = i_param;\r
-\r
-               Frame frame = new Frame("Jpeg reader demo");\r
-               // GL対応のRGBラスタオブジェクト\r
-               this._src_image = new NyARRgbRaster_RGB(i_image.getWidth(),i_image.getHeight(),true);\r
-               NyARRasterImageIO.copy(i_image, this._src_image);\r
-               \r
-               \r
-               // NyARToolkitの準備\r
-               this._ar_param.changeScreenSize(i_image.getWidth(),i_image.getHeight());\r
-               this._nya = new NyARSingleDetectMarker(this._ar_param, i_ar_code, 80.0,this._src_image.getBufferType());\r
-               this._nya.setContinueMode(false);// ここをtrueにすると、transMatContinueモード(History計算)になります。\r
-               \r
-               // 3Dを描画するコンポーネント\r
-               GLCanvas canvas = new GLCanvas();\r
-               frame.add(canvas);\r
-               canvas.addGLEventListener(this);\r
-               frame.addWindowListener(new WindowAdapter() {\r
-                       public void windowClosing(WindowEvent e)\r
-                       {\r
-                               System.exit(0);\r
-                       }\r
-               });\r
-\r
-               frame.setVisible(true);\r
-               Insets ins = frame.getInsets();\r
-               frame.setSize(i_image.getWidth() + ins.left + ins.right, i_image.getHeight() + ins.top + ins.bottom);\r
-               canvas.setBounds(ins.left, ins.top, i_image.getWidth(), i_image.getHeight());\r
-       }\r
-\r
-       public void init(GLAutoDrawable drawable)\r
-       {\r
-               this._gl = drawable.getGL();\r
-               this._gl.glEnable(GL.GL_DEPTH_TEST);\r
-               this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);\r
-               // NyARToolkitの準備\r
-               try {\r
-                       // NyARToolkit用の支援クラス\r
-                       _glnya = new NyARGLUtil(_gl);\r
-                       // キャプチャ開始\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-               }\r
-               // カメラパラメータの計算\r
-               this._glnya.toCameraFrustumRH(this._ar_param,this._camera_projection);\r
-               this._animator = new Animator(drawable);\r
-               this._animator.start();\r
-               return;\r
-       }\r
-\r
-       public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)\r
-       {\r
-               _gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);\r
-               _gl.glViewport(0, 0, width, height);\r
-\r
-               // 視体積の設定\r
-               _gl.glMatrixMode(GL.GL_PROJECTION);\r
-               _gl.glLoadIdentity();\r
-               // 見る位置\r
-               _gl.glMatrixMode(GL.GL_MODELVIEW);\r
-               _gl.glLoadIdentity();\r
-       }\r
-\r
-       private boolean _is_marker_exist=false;\r
-       private NyARTransMatResult __display_transmat_result = new NyARTransMatResult();\r
-\r
-       private double[] __display_wk = new double[16];\r
-\r
-       public void display(GLAutoDrawable drawable)\r
-       {\r
-               NyARTransMatResult transmat_result = __display_transmat_result;\r
-               // 背景を書く\r
-               this._gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.\r
-               try{\r
-                       this._is_marker_exist=this._nya.detectMarkerLite(this._src_image);\r
-                       this._glnya.drawBackGround(this._src_image, 1.0);\r
-                       synchronized(this._sync_object){\r
-                               // マーカーがあれば、立方体を描画\r
-                               if (this._is_marker_exist){\r
-                                       System.out.println(this._nya.getConfidence());\r
-                                       // マーカーの一致度を調査するならば、ここでnya.getConfidence()で一致度を調べて下さい。\r
-                                       // Projection transformation.\r
-                                       _gl.glMatrixMode(GL.GL_PROJECTION);\r
-                                       _gl.glLoadMatrixd(_camera_projection, 0);\r
-                                       _gl.glMatrixMode(GL.GL_MODELVIEW);\r
-                                       // Viewing transformation.\r
-                                       _gl.glLoadIdentity();\r
-                                       // 変換行列を取得\r
-                                       _nya.getTransmationMatrix(transmat_result);\r
-                                       // 変換行列をOpenGL形式に変換\r
-                                       _glnya.toCameraViewRH(transmat_result, __display_wk);\r
-                                       _gl.glLoadMatrixd(__display_wk, 0);\r
-               \r
-                                       // All other lighting and geometry goes here.\r
-                                       drawCube();\r
-                               }\r
-                       }\r
-                       Thread.sleep(1);// タスク実行権限を一旦渡す\r
-               }catch(Exception e){\r
-                       e.printStackTrace();\r
-               }\r
-\r
-       }\r
-       public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)\r
-       {\r
-       }\r
-\r
-       private final static String CARCODE_FILE = "../../Data/patt.hiro";\r
-\r
-       private final static String PARAM_FILE = "../../Data/camera_para.dat";\r
-       private final static String SAMPLE_FILES = "../../Data/staticimage_sample.png";\r
-\r
-       public static void main(String[] args)\r
-       {\r
-               try {\r
-                       NyARParam param = new NyARParam();\r
-                       param.loadARParamFromFile(PARAM_FILE);\r
-                       NyARCode code = new NyARCode(16, 16);\r
-                       code.loadARPattFromFile(CARCODE_FILE);\r
-                       BufferedImage src_image = ImageIO.read(new File(SAMPLE_FILES));\r
-\r
-                       new JpegSimpleLite(param, code,src_image);\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-               }\r
-               return;\r
-       }\r
-}\r
index 266634d..d3a333a 100644 (file)
@@ -28,6 +28,7 @@ package jp.nyatla.nyartoolkit.java3d.utils;
 \r
 import jp.nyatla.nyartoolkit.core.*;\r
 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix44;\r
 \r
 import javax.media.j3d.Transform3D;\r
 /**\r
@@ -73,69 +74,17 @@ public class J3dNyARParam extends NyARParam
                //既に値がキャッシュされていたらそれを使う\r
                if (m_projection != null) {\r
                        return m_projection;\r
-               }\r
+               }               \r
                //無ければ計算\r
+               NyARDoubleMatrix44 tmp=new NyARDoubleMatrix44();\r
+               this.makeCameraFrustumRH(view_distance_min, view_distance_max,tmp);\r
+               this.m_projection =new Transform3D(new double[]{\r
+                       tmp.m00,tmp.m01,tmp.m02,tmp.m03,\r
+                       tmp.m10,tmp.m11,tmp.m12,tmp.m13,\r
+                       -tmp.m20,-tmp.m21,-tmp.m22,-tmp.m23,\r
+                       tmp.m30,tmp.m31,tmp.m32,tmp.m33\r
+                       });\r
 \r
-               NyARMat trans_mat = new NyARMat(3, 4);\r
-               NyARMat icpara_mat = new NyARMat(3, 4);\r
-               double[][] p = new double[3][3], q = new double[4][4];\r
-               double width, height;\r
-               int i, j;\r
-\r
-               width = this._screen_size.w;\r
-               height = this._screen_size.h;\r
-\r
-               this.getPerspectiveProjectionMatrix().decompMat(icpara_mat, trans_mat);\r
-\r
-               double[][] icpara = icpara_mat.getArray();\r
-               double[][] trans = trans_mat.getArray();\r
-               for (i = 0; i < 4; i++) {\r
-                       icpara[1][i] = (height - 1) * (icpara[2][i]) - icpara[1][i];\r
-               }\r
-\r
-               for (i = 0; i < 3; i++) {\r
-                       for (j = 0; j < 3; j++) {\r
-                               p[i][j] = icpara[i][j] / icpara[2][2];\r
-                       }\r
-               }\r
-               //p[0][0],p[1][1]=n\r
-               //p[0][2],p[1][2]=t+b\r
-\r
-               //Projectionの計算\r
-               q[0][0] = (2.0 * p[0][0] / (width - 1));\r
-               q[0][1] = (2.0 * p[0][1] / (width - 1));\r
-               q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);\r
-               q[0][3] = 0.0;\r
-\r
-               q[1][0] = 0.0;\r
-               q[1][1] = -(2.0 * p[1][1] / (height - 1));\r
-               q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);\r
-               q[1][3] = 0.0;\r
-\r
-               q[2][0] = 0.0;\r
-               q[2][1] = 0.0;\r
-               q[2][2] = (view_distance_max + view_distance_min) / (view_distance_min - view_distance_max);\r
-               q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);\r
-\r
-               q[3][0] = 0.0;\r
-               q[3][1] = 0.0;\r
-               q[3][2] = -1.0;\r
-               q[3][3] = 0.0;\r
-\r
-               q[2][2] = q[2][2] * -1;\r
-               q[2][3] = q[2][3] * -1;\r
-\r
-               double[] tmp_projection = new double[16];\r
-               for (i = 0; i < 4; i++) { // Row.\r
-                       // First 3 columns of the current row.\r
-                       for (j = 0; j < 3; j++) { // Column.\r
-                               tmp_projection[i + j * 4] = (q[i][0] * trans[0][j] + q[i][1] * trans[1][j] + q[i][2] * trans[2][j]);\r
-                       }\r
-                       // Fourth column of the current row.\r
-                       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
-               }\r
-               m_projection = new Transform3D(tmp_projection);\r
-               m_projection.transpose();\r
                return m_projection;\r
        }\r
 }\r
index b715bbd..b4fe1ba 100644 (file)
@@ -215,11 +215,22 @@ class NyARBehavior extends Behavior
                                                final NyARTransMatResult src = this.trans_mat_result;\r
                                                related_nya.getTransmationMatrix(src);\r
 //                                             Matrix4d matrix = new Matrix4d(src.m00, -src.m10, -src.m20, 0, -src.m01, src.m11, src.m21, 0, -src.m02, src.m12, src.m22, 0, -src.m03, src.m13, src.m23, 1);\r
+/*                                             Matrix4d matrix = new Matrix4d(\r
+                                                                src.m00, src.m01, src.m02, src.m03,\r
+                                                               -src.m10, -src.m11, -src.m12, -src.m13,\r
+                                                               -src.m20, -src.m21, -src.m22, -src.m23,\r
+                                                               0,0,0, 1.0);*/\r
+/*                                             Matrix4d matrix2 = new Matrix4d(\r
+                                               -src.m00, -src.m01, -src.m02, -src.m03,\r
+                                               -src.m10, -src.m11, -src.m12, -src.m13,\r
+                                                src.m20,  src.m21,  src.m22,  src.m23,\r
+                                                  0,        0,        0,        1);\r
+                                               */\r
                                                Matrix4d matrix = new Matrix4d(\r
                                                                -src.m00, -src.m10, src.m20, 0,\r
                                                                -src.m01, -src.m11, src.m21, 0,\r
                                                                -src.m02, -src.m12, src.m22, 0,\r
-                                                          -src.m03,-src.m13, src.m23, 1);\r
+                                                           -src.m03,-src.m13, src.m23, 1);\r
                                                matrix.transpose();\r
                                                t3d = new Transform3D(matrix);\r
                                                if (trgroup != null) {\r
index 4001edf..92fd34d 100644 (file)
@@ -8,6 +8,10 @@ import javax.media.format.*;
 import javax.media.protocol.*;\r
 import jp.nyatla.nyartoolkit.*;\r
 \r
+/**\r
+ * 1個のキャプチャデバイスを管理するクラスです。\r
+ * キャプチャデバイスの走査(開始・停止)、プロパティの取得・設定機能を提供します。\r
+ */\r
 public class JmfCaptureDevice\r
 {\r
        private JmfCaptureListener _capture_listener;\r
@@ -28,20 +32,27 @@ public class JmfCaptureDevice
        /**\r
         * サポートしているフォーマットの一覧を返します。\r
         * @return\r
+        * サポートしているフォーマットを格納した配列。\r
         */\r
        public Format[] getSupportFormats()\r
        {\r
                return this._info.getFormats();\r
        }\r
-\r
+       /**\r
+        * 現在のキャプチャフォーマットを返します。\r
+        * @return\r
+        * 現在設定してあるフォーマット。\r
+        */\r
        public final VideoFormat getCaptureFormat()\r
        {\r
                return this._capture_format;\r
        }\r
 \r
        /**\r
-        * このキャプチャデバイスの提供する、i_index番目のフォーマットをキャプチャフォーマットに指定します。\r
+        * 現在のキャプチャフォーマットを、指定したインデクス番号のフォーマットに指定します。\r
+        * インデクス番号は、getSupportFormatsで得られるフォーマットの一覧の番号に対応します。\r
         * @param i_index\r
+        * サポートしているフォーマットのインデクス番号。\r
         */\r
        public void setCaptureFormat(int i_index)\r
        {\r
index d1eddff..20ec159 100644 (file)
@@ -50,42 +50,21 @@ public class JmfNyARRaster_RGB implements INyARRgbRaster
 {\r
        private JmfRGB24RasterHolder _holder;\r
        protected NyARIntSize _size;\r
-\r
-       public JmfNyARRaster_RGB(NyARParam i_param,VideoFormat i_fmt) throws NyARException\r
-       {\r
-               initMember(i_param.getScreenSize().w,i_param.getScreenSize().h,i_fmt);\r
-       }       \r
        /**\r
-        * i_fmtに一致する画素フォーマットのRasterを作成します。\r
+        * コンストラクタ。i_fmtに合致するバッファを持つインスタンスを作成します。\r
         * このコンストラクタで作成したクラスは、hasBuffer()がfalseを返すことがあります。\r
-        * @param i_width\r
-        * @param i_height\r
         * @param i_fmt\r
         * @throws NyARException\r
         */\r
-       public JmfNyARRaster_RGB(int i_width,int i_height,VideoFormat i_fmt) throws NyARException\r
+       public JmfNyARRaster_RGB(VideoFormat i_fmt) throws NyARException\r
        {\r
-               initMember(i_width,i_height,i_fmt);\r
-       }\r
-       /**\r
-        * i_fmtに一致する画素フォーマットのRasterを作成します。\r
-        * このコンストラクタで作成したクラスは、hasBuffer()がfalseを返すことがあります。\r
-        * @param i_size\r
-        * @param i_fmt\r
-        * @throws NyARException\r
-        */\r
-       public JmfNyARRaster_RGB(NyARIntSize i_size,VideoFormat i_fmt) throws NyARException\r
-       {\r
-               initMember(i_size.w,i_size.h,i_fmt);\r
-       }\r
-       private void initMember(int i_width,int i_height,VideoFormat i_fmt) throws NyARException\r
+               initMember(i_fmt);\r
+       }       \r
+\r
+       private void initMember(VideoFormat i_fmt) throws NyARException\r
        {\r
-               this._size= new NyARIntSize(i_width,i_height);\r
-               // データサイズの確認\r
                final Dimension s = i_fmt.getSize();\r
-               if (!this._size.isEqualSize(s.width,s.height)) {\r
-                       throw new NyARException();\r
-               }\r
+               this._size= new NyARIntSize(s.width,s.height);\r
                // データ配列の確認\r
                if(i_fmt instanceof YUVFormat){\r
                        //YUVフォーマット\r
@@ -145,15 +124,6 @@ public class JmfNyARRaster_RGB implements INyARRgbRaster
        {\r
                NyARException.notImplement();\r
        }\r
-       /**\r
-        *      @deprecated hasBuffer()関数を使ってください。\r
-        * \r
-        */\r
-       final public boolean hasData()\r
-       {\r
-               return this.hasBuffer();\r
-       }\r
-\r
 }\r
 \r
 \r
@@ -270,6 +240,10 @@ class NyARGLPixelReader_RGB24 extends JmfRGB24RasterHolder
        {\r
                NyARException.notImplement();           \r
        }\r
+       public void setPixel(int iX, int iY, int iR, int iG, int iB)throws NyARException\r
+       {\r
+               NyARException.notImplement();           \r
+       }       \r
        public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException\r
        {\r
                NyARException.notImplement();           \r
@@ -377,9 +351,14 @@ class NyARGLPixelReader_YUV extends JmfRGB24RasterHolder
        {\r
                NyARException.notImplement();           \r
        }\r
-       public void switchBuffer(Object i_ref_object) throws NyARException\r
+       public void setPixel(int iX, int iY, int iR, int iG, int iB)throws NyARException\r
        {\r
                NyARException.notImplement();           \r
        }       \r
+       public void switchBuffer(Object i_ref_object) throws NyARException\r
+       {\r
+               NyARException.notImplement();           \r
+       }\r
+\r
 }\r
 \r
diff --git a/utils/jogl/src/jp/nyatla/nyartoolkit/jogl/utils/NyARGLDrawUtil.java b/utils/jogl/src/jp/nyatla/nyartoolkit/jogl/utils/NyARGLDrawUtil.java
new file mode 100644 (file)
index 0000000..ffb78a7
--- /dev/null
@@ -0,0 +1,216 @@
+package jp.nyatla.nyartoolkit.jogl.utils;\r
+\r
+import java.awt.Color;\r
+import java.awt.Font;\r
+import java.nio.ByteBuffer;\r
+import java.nio.IntBuffer;\r
+\r
+import javax.media.opengl.GL;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.INyARRaster;\r
+import jp.nyatla.nyartoolkit.core.types.NyARBufferType;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+\r
+import com.sun.opengl.util.j2d.TextRenderer;\r
+import com.sun.opengl.util.texture.Texture;\r
+\r
+/**\r
+ * OpenGL向けの描画関数を提供します。\r
+ */\r
+public class NyARGLDrawUtil\r
+{\r
+       private static TextRenderer _tr=new TextRenderer(new Font("SansSerif", Font.PLAIN, 10));\r
+       /**\r
+        * 立方体を描画します。\r
+        * @param i_gl\r
+        * OpenGLインスタンス\r
+        * @param i_size_per_mm\r
+        * 立方体の辺の長さを[mm単位]\r
+        */\r
+       public static void drawColorCube(GL i_gl,float i_size_per_mm)\r
+       {\r
+               // Colour cube data.\r
+               int polyList = 0;\r
+               float fSize =i_size_per_mm/2f;\r
+               int f, i;\r
+               float[][] cube_vertices = new float[][] { { 1.0f, 1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, { -1.0f, -1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, { -1.0f, -1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f } };\r
+               float[][] cube_vertex_colors = new float[][] { { 1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } };\r
+               int cube_num_faces = 6;\r
+               short[][] cube_faces = new short[][] { { 3, 2, 1, 0 }, { 2, 3, 7, 6 }, { 0, 1, 5, 4 }, { 3, 0, 4, 7 }, { 1, 2, 6, 5 }, { 4, 5, 6, 7 } };\r
+\r
+               if (polyList == 0) {\r
+                       polyList = i_gl.glGenLists(1);\r
+                       i_gl.glNewList(polyList, GL.GL_COMPILE);\r
+                       i_gl.glBegin(GL.GL_QUADS);\r
+                       for (f = 0; f < cube_num_faces; f++)\r
+                               for (i = 0; i < 4; i++) {\r
+                                       i_gl.glColor3f(cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);\r
+                                       i_gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
+                               }\r
+                       i_gl.glEnd();\r
+                       i_gl.glColor3f(0.0f, 0.0f, 0.0f);\r
+                       for (f = 0; f < cube_num_faces; f++) {\r
+                               i_gl.glBegin(GL.GL_LINE_LOOP);\r
+                               for (i = 0; i < 4; i++)\r
+                                       i_gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
+                               i_gl.glEnd();\r
+                       }\r
+                       i_gl.glEndList();\r
+               }\r
+               i_gl.glCallList(polyList); // Draw the cube.\r
+       }\r
+       /**\r
+        * フォントカラーをセットします。\r
+        * @param i_c\r
+        */\r
+       public static void setFontColor(Color i_c)\r
+       {\r
+               NyARGLDrawUtil._tr.setColor(i_c);\r
+       }\r
+       /**\r
+        * フォントスタイルをセットします。\r
+        * @param i_font_name\r
+        * @param i_font_style\r
+        * @param i_size\r
+        */\r
+       public static void setFontStyle(String i_font_name,int i_font_style,int i_size)\r
+       {\r
+               NyARGLDrawUtil._tr=new TextRenderer(new Font(i_font_name,i_font_style, i_size));\r
+       }\r
+       /**\r
+        * 現在のフォントで、文字列を描画します。\r
+        * @param i_str\r
+        * @param i_scale\r
+        */\r
+       public static void drawText(String i_str,float i_scale)\r
+       {\r
+               NyARGLDrawUtil._tr.begin3DRendering();\r
+               NyARGLDrawUtil._tr.draw3D(i_str, 0f,0f,0f,i_scale);\r
+               NyARGLDrawUtil._tr.end3DRendering();\r
+               return;\r
+       }\r
+       /**\r
+        * INyARRasterの内容を現在のビューポートへ描画します。\r
+        * @param i_gl\r
+        * @param i_raster\r
+        * @param i_zoom\r
+        * @throws NyARException\r
+        */\r
+       public static void drawBackGround(javax.media.opengl.GL i_gl,INyARRaster i_raster, double i_zoom) throws NyARException\r
+       {\r
+               IntBuffer texEnvModeSave = IntBuffer.allocate(1);\r
+               boolean lightingSave;\r
+               boolean depthTestSave;\r
+               final NyARIntSize rsize=i_raster.getSize();\r
+               // Prepare an orthographic projection, set camera position for 2D drawing, and save GL state.\r
+               i_gl.glGetTexEnviv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave); // Save GL texture environment mode.\r
+               if (texEnvModeSave.array()[0] != GL.GL_REPLACE) {\r
+                       i_gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);\r
+               }\r
+               lightingSave = i_gl.glIsEnabled(GL.GL_LIGHTING); // Save enabled state of lighting.\r
+               if (lightingSave == true) {\r
+                       i_gl.glDisable(GL.GL_LIGHTING);\r
+               }\r
+               depthTestSave = i_gl.glIsEnabled(GL.GL_DEPTH_TEST); // Save enabled state of depth test.\r
+               if (depthTestSave == true) {\r
+                       i_gl.glDisable(GL.GL_DEPTH_TEST);\r
+               }\r
+               //ProjectionMatrixとModelViewMatrixを初期化\r
+               i_gl.glMatrixMode(GL.GL_PROJECTION);\r
+               i_gl.glPushMatrix();\r
+               i_gl.glLoadIdentity();\r
+               i_gl.glOrtho(0.0,rsize.w, 0.0,rsize.h,0,1);\r
+               i_gl.glMatrixMode(GL.GL_MODELVIEW);\r
+               i_gl.glPushMatrix();\r
+               i_gl.glLoadIdentity();\r
+               arglDispImageStateful(i_gl,rsize,i_raster.getBuffer(),i_raster.getBufferType(),i_zoom);\r
+               //ProjectionMatrixとModelViewMatrixを回復\r
+               i_gl.glMatrixMode(GL.GL_PROJECTION);\r
+               i_gl.glPopMatrix();\r
+               i_gl.glMatrixMode(GL.GL_MODELVIEW);\r
+               i_gl.glPopMatrix();\r
+               if (depthTestSave) {\r
+                       i_gl.glEnable(GL.GL_DEPTH_TEST); // Restore enabled state of depth test.\r
+               }\r
+               if (lightingSave) {\r
+                       i_gl.glEnable(GL.GL_LIGHTING); // Restore enabled state of lighting.\r
+               }\r
+               if (texEnvModeSave.get(0) != GL.GL_REPLACE) {\r
+                       i_gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave.get(0)); // Restore GL texture environment mode.\r
+               }\r
+               i_gl.glEnd();\r
+       }\r
+\r
+       /**\r
+        * arglDispImageStateful関数モドキ\r
+        * @param image\r
+        * @param zoom\r
+        */\r
+       private static void arglDispImageStateful(GL gl,NyARIntSize i_size,Object i_buffer,int i_buffer_type, double zoom) throws NyARException\r
+       {\r
+               float zoomf;\r
+               IntBuffer params = IntBuffer.allocate(4);\r
+               zoomf = (float) zoom;\r
+               gl.glDisable(GL.GL_TEXTURE_2D);\r
+               gl.glGetIntegerv(GL.GL_VIEWPORT, params);\r
+               gl.glPixelZoom(zoomf * ((float) (params.get(2)) / (float) i_size.w), -zoomf * ((float) (params.get(3)) / (float) i_size.h));\r
+               gl.glWindowPos2f(0.0f, (float) i_size.h);\r
+               gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);\r
+               //BufferTypeの変換\r
+               switch(i_buffer_type)\r
+               {\r
+               case NyARBufferType.BYTE1D_B8G8R8_24:\r
+                       gl.glDrawPixels(i_size.w,i_size.h,GL.GL_BGR, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[])i_buffer));\r
+                       break;\r
+               case NyARBufferType.BYTE1D_R8G8B8_24:\r
+                       gl.glDrawPixels(i_size.w,i_size.h,GL.GL_RGB, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[])i_buffer));\r
+                       break;\r
+               case NyARBufferType.BYTE1D_B8G8R8X8_32:\r
+                       gl.glDrawPixels(i_size.w,i_size.h,GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[])i_buffer));\r
+                       break;\r
+               case NyARBufferType.INT1D_GRAY_8:\r
+                       /** @bug don't work*/\r
+                       gl.glDrawPixels(i_size.w,i_size.h,GL.GL_LUMINANCE, GL.GL_UNSIGNED_INT, IntBuffer.wrap((int[])i_buffer));\r
+                       break;\r
+               default:\r
+                       throw new NyARException();\r
+               }\r
+       }\r
+       /**\r
+        * スクリーン座標系をOpenGLにロードします。この関数は、PROJECTIONとMODELVIEWスタックをそれぞれ1づつpushします。\r
+        * スクリーン座標系を使用し終わったら、endScreenCoordinateSystemを呼び出してください。\r
+        * @param i_gl\r
+        * @param i_width\r
+        * @param i_height\r
+        * @param i_revers_y_direction\r
+        * Y軸の反転フラグです。trueならばtop->bottom、falseならばbottom->top方向になります。\r
+        */\r
+       public static void beginScreenCoordinateSystem(GL i_gl,int i_width,int i_height,boolean i_revers_y_direction)\r
+       {\r
+               i_gl.glMatrixMode(GL.GL_PROJECTION);\r
+               i_gl.glPushMatrix(); // Save world coordinate system.\r
+               i_gl.glLoadIdentity();\r
+               if(i_revers_y_direction){\r
+                       i_gl.glOrtho(0.0,i_width,i_height,0,-1,1);\r
+               }else{\r
+                       i_gl.glOrtho(0.0,i_width,0,i_height,-1,1);\r
+               }\r
+               i_gl.glMatrixMode(GL.GL_MODELVIEW);\r
+               i_gl.glPushMatrix(); // Save world coordinate system.\r
+               i_gl.glLoadIdentity();\r
+               return;\r
+       }\r
+       /**\r
+        * ロードしたスクリーン座標系を元に戻します。{@link #beginScreenCoordinateSystem}の後に呼び出してください。\r
+        * @param i_gl\r
+        */\r
+       public static void endScreenCoordinateSystem(GL i_gl)\r
+       {\r
+               i_gl.glMatrixMode(GL.GL_PROJECTION);\r
+               i_gl.glPopMatrix();\r
+               i_gl.glMatrixMode(GL.GL_MODELVIEW);             \r
+               i_gl.glPopMatrix();\r
+               return;\r
+       }       \r
+}\r
index 899fb34..4ab92b5 100644 (file)
  */\r
 package jp.nyatla.nyartoolkit.jogl.utils;\r
 \r
+import java.awt.Font;\r
 import java.nio.*;\r
 import javax.media.opengl.GL;\r
-import javax.media.opengl.glu.GLU;\r
+\r
+import com.sun.opengl.util.j2d.TextRenderer;\r
 \r
 import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.*;\r
-import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
+import jp.nyatla.nyartoolkit.core.raster.INyARRaster;\r
 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
-import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
+import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
+import jp.nyatla.nyartoolkit.core.types.matrix.*;\r
 /**\r
- * NyARToolkit用のJOGL支援関数群\r
+ * OpenGL向けの形式変換変換関数を提供します。\r
+ * 描画系関数は{@link NyARGLDrawUtil}を参照してください。\r
  */\r
 public class NyARGLUtil\r
 {\r
-       private javax.media.opengl.GL _gl;\r
-\r
-       private javax.media.opengl.glu.GLU _glu;\r
-\r
-       public NyARGLUtil(javax.media.opengl.GL i_gl)\r
-       {\r
-               this._gl = i_gl;\r
-               this._glu = new GLU();\r
-       }\r
        /**\r
-        * ラスタのGLタイプを取得する。\r
-        * @param i_buffer_type\r
-        * @return\r
-        * @throws NyARException\r
+        * NyARToolKit 2.53以前のコードと互換性を持たせるためのスケール値。{@link #toCameraFrustumRH}のi_scaleに設定することで、\r
+        * 以前のバージョンの数値系と互換性を保ちます。\r
         */\r
-       final static private int getGlPixelFormat(int i_buffer_type) throws NyARException\r
-       {\r
-               switch(i_buffer_type){\r
-               case NyARBufferType.BYTE1D_B8G8R8_24:\r
-                       return GL.GL_BGR;\r
-               case NyARBufferType.BYTE1D_R8G8B8_24:\r
-                       return GL.GL_RGB;\r
-               default:\r
-                       throw new NyARException();\r
-               }\r
-       }\r
-       \r
+       public final static double SCALE_FACTOR_toCameraFrustumRH_NYAR2=1.0;\r
        /**\r
-        * GLNyARRaster_RGBをバックグラウンドに書き出す。\r
-        * @param image\r
-        * @param zoom\r
+        * NyARToolKit 2.53以前のコードと互換性を持たせるためのスケール値。{@link #toCameraViewRH}のi_scaleに設定することで、\r
+        * 以前のバージョンの数値系と互換性を保ちます。\r
         */\r
-       public void drawBackGround(INyARRgbRaster i_raster, double i_zoom) throws NyARException\r
-       {\r
-               IntBuffer texEnvModeSave = IntBuffer.allocate(1);\r
-               boolean lightingSave;\r
-               boolean depthTestSave;\r
-               javax.media.opengl.GL gl = this._gl;\r
-               final NyARIntSize rsize=i_raster.getSize();\r
+       public final static double SCALE_FACTOR_toCameraViewRH_NYAR2=1/0.025;\r
 \r
-               // Prepare an orthographic projection, set camera position for 2D drawing, and save GL state.\r
-               gl.glGetTexEnviv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave); // Save GL texture environment mode.\r
-               if (texEnvModeSave.array()[0] != GL.GL_REPLACE) {\r
-                       gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);\r
-               }\r
-               lightingSave = gl.glIsEnabled(GL.GL_LIGHTING); // Save enabled state of lighting.\r
-               if (lightingSave == true) {\r
-                       gl.glDisable(GL.GL_LIGHTING);\r
-               }\r
-               depthTestSave = gl.glIsEnabled(GL.GL_DEPTH_TEST); // Save enabled state of depth test.\r
-               if (depthTestSave == true) {\r
-                       gl.glDisable(GL.GL_DEPTH_TEST);\r
-               }\r
-               gl.glMatrixMode(GL.GL_PROJECTION);\r
-               gl.glPushMatrix();\r
-               gl.glLoadIdentity();\r
-               _glu.gluOrtho2D(0.0,rsize.w, 0.0,rsize.h);\r
-               gl.glMatrixMode(GL.GL_MODELVIEW);\r
-               gl.glPushMatrix();\r
-               gl.glLoadIdentity();\r
-               arglDispImageStateful(i_raster, i_zoom);\r
-\r
-               // Restore previous projection, camera position, and GL state.\r
-               gl.glMatrixMode(GL.GL_PROJECTION);\r
-               gl.glPopMatrix();\r
-               gl.glMatrixMode(GL.GL_MODELVIEW);\r
-               gl.glPopMatrix();\r
-               if (depthTestSave) {\r
-                       gl.glEnable(GL.GL_DEPTH_TEST); // Restore enabled state of depth test.\r
-               }\r
-               if (lightingSave) {\r
-                       gl.glEnable(GL.GL_LIGHTING); // Restore enabled state of lighting.\r
-               }\r
-               if (texEnvModeSave.get(0) != GL.GL_REPLACE) {\r
-                       gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave.get(0)); // Restore GL texture environment mode.\r
-               }\r
-               gl.glEnd();\r
-       }\r
+       \r
 \r
+       \r
        /**\r
-        * arglDispImageStateful関数モドキ\r
-        * @param image\r
-        * @param zoom\r
+        * ARToolKitスタイルのカメラパラメータから、 CameraFrustamを計算します。\r
+        * @param i_arparam\r
+        * @param i_scale\r
+        * スケール値を指定します。1=1mmです。10ならば1=1cm,1000ならば1=1mです。\r
+        * 2.53以前のNyARToolkitと互換性を持たせるときは、{@link #SCALE_FACTOR_toCameraFrustumRH_NYAR2}を指定してください。\r
+        * @param i_near\r
+        * 視錐体のnearPointを指定します。単位は、i_scaleに設定した値で決まります。\r
+        * @param i_far\r
+        * 視錐体のfarPointを指定します。単位は、i_scaleに設定した値で決まります。\r
+        * @param o_gl_projection\r
         */\r
-       private void arglDispImageStateful(INyARRgbRaster i_raster, double zoom) throws NyARException\r
-       {\r
-               javax.media.opengl.GL gl_ = this._gl;\r
-               final NyARIntSize rsize = i_raster.getSize();\r
-               float zoomf;\r
-               IntBuffer params = IntBuffer.allocate(4);\r
-               zoomf = (float) zoom;\r
-               gl_.glDisable(GL.GL_TEXTURE_2D);\r
-               gl_.glGetIntegerv(GL.GL_VIEWPORT, params);\r
-               gl_.glPixelZoom(zoomf * ((float) (params.get(2)) / (float) rsize.w), -zoomf * ((float) (params.get(3)) / (float) rsize.h));\r
-               gl_.glWindowPos2f(0.0f, (float) rsize.h);\r
-               gl_.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);\r
-               ByteBuffer buf = ByteBuffer.wrap((byte[])i_raster.getBuffer());\r
-               gl_.glDrawPixels(rsize.w,rsize.h,getGlPixelFormat(i_raster.getBufferType()), GL.GL_UNSIGNED_BYTE, buf);\r
-       }\r
-       \r
-       private double view_scale_factor = 0.025;\r
-       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
-       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
-\r
-       public void setScaleFactor(double i_new_value)\r
-       {\r
-               this.view_scale_factor = i_new_value;\r
-       }\r
-\r
-       public void setViewDistanceMin(double i_new_value)\r
+       public static void toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)\r
        {\r
-               this.view_distance_min = i_new_value;\r
-       }\r
-\r
-       public void setViewDistanceMax(double i_new_value)\r
-       {\r
-               this.view_distance_max = i_new_value;\r
+               toCameraFrustumRH(i_arparam.getPerspectiveProjectionMatrix(),i_arparam.getScreenSize(),i_scale,i_near,i_far,o_gl_projection);\r
+               return;\r
        }\r
-\r
        /**\r
-        * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])\r
-        * 関数の置き換え\r
-        * NyARParamからOpenGLのProjectionを作成します。\r
-        * @param i_arparam\r
+        * ARToolKitスタイルのProjectionMatrixから、 CameraFrustamを計算します。\r
+        * @param i_promat\r
+        * @param i_size\r
+        * スクリーンサイズを指定します。\r
+        * @param i_scale\r
+        * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。\r
+        * @param i_near\r
+        * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。\r
+        * @param i_far\r
+        * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。\r
         * @param o_gl_projection\r
-        * double[16]を指定して下さい\r
+        * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照\r
         */\r
-       public void toCameraFrustumRH(NyARParam i_arparam,double[] o_gl_projection)\r
+       public static void toCameraFrustumRH(NyARPerspectiveProjectionMatrix i_promat,NyARIntSize i_size,double i_scale,double i_near,double i_far,double[] o_gl_projection)\r
        {\r
-               NyARMat trans_mat = new NyARMat(3, 4);\r
-               NyARMat icpara_mat = new NyARMat(3, 4);\r
-               double[][] p = new double[3][3], q = new double[4][4];\r
-               int i, j;\r
-\r
-               final NyARIntSize size=i_arparam.getScreenSize();\r
-               final int width = size.w;\r
-               final int height = size.h;\r
-               \r
-               i_arparam.getPerspectiveProjectionMatrix().decompMat(icpara_mat, trans_mat);\r
-\r
-               double[][] icpara = icpara_mat.getArray();\r
-               double[][] trans = trans_mat.getArray();\r
-               for (i = 0; i < 4; i++) {\r
-                       icpara[1][i] = (height - 1) * (icpara[2][i]) - icpara[1][i];\r
-               }\r
-\r
-               for (i = 0; i < 3; i++) {\r
-                       for (j = 0; j < 3; j++) {\r
-                               p[i][j] = icpara[i][j] / icpara[2][2];\r
-                       }\r
-               }\r
-               q[0][0] = (2.0 * p[0][0] / (width - 1));\r
-               q[0][1] = (2.0 * p[0][1] / (width - 1));\r
-               q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);\r
-               q[0][3] = 0.0;\r
-\r
-               q[1][0] = 0.0;\r
-               q[1][1] = -(2.0 * p[1][1] / (height - 1));\r
-               q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);\r
-               q[1][3] = 0.0;\r
-\r
-               q[2][0] = 0.0;\r
-               q[2][1] = 0.0;\r
-               q[2][2] = (view_distance_max + view_distance_min) / (view_distance_min - view_distance_max);\r
-               q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);\r
-\r
-               q[3][0] = 0.0;\r
-               q[3][1] = 0.0;\r
-               q[3][2] = -1.0;\r
-               q[3][3] = 0.0;\r
-\r
-               for (i = 0; i < 4; i++) { // Row.\r
-                       // First 3 columns of the current row.\r
-                       for (j = 0; j < 3; j++) { // Column.\r
-                               o_gl_projection[i + j * 4] = q[i][0] * trans[0][j] + q[i][1] * trans[1][j] + q[i][2] * trans[2][j];\r
-                       }\r
-                       // Fourth column of the current row.\r
-                       o_gl_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
-               }\r
+               NyARDoubleMatrix44 m=new NyARDoubleMatrix44();\r
+               i_promat.makeCameraFrustumRH(i_size.w,i_size.h,i_near*i_scale,i_far*i_scale,m);\r
+               m.getValueT(o_gl_projection);\r
                return;\r
        }\r
-       \r
-       \r
-       \r
        /**\r
         * NyARTransMatResultをOpenGLの行列へ変換します。\r
-        * @param i_ny_result\r
+        * @param mat\r
+        * 変換元の行列\r
+        * @param i_scale\r
+        * 座標系のスケール値を指定します。1=1mmです。10ならば1=1cm,1000ならば1=1mです。\r
+        * 2.53以前のNyARToolkitと互換性を持たせるときは、{@link #SCALE_FACTOR_toCameraViewRH_NYAR2}を指定してください。\r
         * @param o_gl_result\r
-        * @throws NyARException\r
         */\r
-       public void toCameraViewRH(NyARTransMatResult i_ny_result, double[] o_gl_result) throws NyARException\r
+       public static void toCameraViewRH(NyARDoubleMatrix44 mat,double i_scale, double[] o_gl_result)\r
        {\r
-               o_gl_result[0 + 0 * 4] = i_ny_result.m00; \r
-               o_gl_result[0 + 1 * 4] = i_ny_result.m01;\r
-               o_gl_result[0 + 2 * 4] = i_ny_result.m02;\r
-               o_gl_result[0 + 3 * 4] = i_ny_result.m03;\r
-               o_gl_result[1 + 0 * 4] = -i_ny_result.m10;\r
-               o_gl_result[1 + 1 * 4] = -i_ny_result.m11;\r
-               o_gl_result[1 + 2 * 4] = -i_ny_result.m12;\r
-               o_gl_result[1 + 3 * 4] = -i_ny_result.m13;\r
-               o_gl_result[2 + 0 * 4] = -i_ny_result.m20;\r
-               o_gl_result[2 + 1 * 4] = -i_ny_result.m21;\r
-               o_gl_result[2 + 2 * 4] = -i_ny_result.m22;\r
-               o_gl_result[2 + 3 * 4] = -i_ny_result.m23;\r
+               o_gl_result[0 + 0 * 4] = mat.m00; \r
+               o_gl_result[1 + 0 * 4] = -mat.m10;\r
+               o_gl_result[2 + 0 * 4] = -mat.m20;\r
                o_gl_result[3 + 0 * 4] = 0.0;\r
+               o_gl_result[0 + 1 * 4] = mat.m01;\r
+               o_gl_result[1 + 1 * 4] = -mat.m11;\r
+               o_gl_result[2 + 1 * 4] = -mat.m21;\r
                o_gl_result[3 + 1 * 4] = 0.0;\r
+               o_gl_result[0 + 2 * 4] = mat.m02;\r
+               o_gl_result[1 + 2 * 4] = -mat.m12;\r
+               o_gl_result[2 + 2 * 4] = -mat.m22;\r
                o_gl_result[3 + 2 * 4] = 0.0;\r
+               \r
+               double scale=1/i_scale;\r
+               o_gl_result[0 + 3 * 4] = mat.m03*scale;\r
+               o_gl_result[1 + 3 * 4] = -mat.m13*scale;\r
+               o_gl_result[2 + 3 * 4] = -mat.m23*scale;\r
                o_gl_result[3 + 3 * 4] = 1.0;\r
-               if (view_scale_factor != 0.0) {\r
-                       o_gl_result[12] *= view_scale_factor;\r
-                       o_gl_result[13] *= view_scale_factor;\r
-                       o_gl_result[14] *= view_scale_factor;\r
-               }\r
                return;\r
-       }       \r
+       }\r
+\r
+\r
        \r
 }\r