+++ /dev/null
-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
-\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
+++ /dev/null
-/* \r
- * PROJECT: NyARToolkit JOGL utilities.\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- * Hirokazu Kato\r
- * Mark Billinghurst\r
- * HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\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 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
- * You should have received a copy of the GNU General Public License\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> or <nyatla(at)nyatla.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.jogl.utils;\r
-\r
-import jp.nyatla.nyartoolkit.core.param.NyARParam;\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
- * OpenGL向けの形式変換変換関数を提供します。\r
- * 描画系関数は{@link NyARGLDrawUtil}を参照してください。\r
- */\r
-public class NyARGLUtil\r
-{\r
- /**\r
- * NyARToolKit 2.53以前のコードと互換性を持たせるためのスケール値。{@link #toCameraFrustumRH}のi_scaleに設定することで、\r
- * 以前のバージョンの数値系と互換性を保ちます。\r
- */\r
- public final static double SCALE_FACTOR_toCameraFrustumRH_NYAR2=1.0;\r
- /**\r
- * NyARToolKit 2.53以前のコードと互換性を持たせるためのスケール値。{@link #toCameraViewRH}のi_scaleに設定することで、\r
- * 以前のバージョンの数値系と互換性を保ちます。\r
- */\r
- public final static double SCALE_FACTOR_toCameraViewRH_NYAR2=1/0.025;\r
-\r
- private NyARGLUtil()\r
- {//生成の禁止\r
- } \r
-\r
- \r
- /**\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
- public static void toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)\r
- {\r
- toCameraFrustumRH(i_arparam.getPerspectiveProjectionMatrix(),i_arparam.getScreenSize(),i_scale,i_near,i_far,o_gl_projection);\r
- return;\r
- }\r
- /**\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
- * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。\r
- */\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
- 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
- * NyARTransMatResultをOpenGLの行列へ変換します。\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
- */\r
- public static void toCameraViewRH(NyARDoubleMatrix44 mat,double i_scale, double[] o_gl_result)\r
- {\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
- return;\r
- }\r
-\r
-\r
- \r
-}\r