Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /nyar4psg/trunk/examples/withOpenGL/withOpenGL.pde

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (hide annotations) (download)
Tue Jan 6 07:38:11 2015 UTC (9 years, 3 months ago) by nyatla
File size: 2456 byte(s)
パッケージ構成をProcessing2.0向けに更新

1 nyatla 1158 /**
2     NyARToolkit for proce55ing/1.0.0
3     (c)2008-2011 nyatla
4     airmail(at)ebony.plala.or.jp
5    
6     OpenGLAPIで使用する例です。
7     OpenGLにAPIを集約することで、Processing行列スタックとの衝突を回避します。
8    
9     This sample uses OpenGL API only.
10     This sample avoids the matrix processing conflict of Processing and OpenGL.
11    
12     */
13     import processing.video.*;
14     import jp.nyatla.nyar4psg.*;
15     import processing.opengl.*;
16     import javax.media.opengl.*;
17    
18     Capture cam;
19     MultiMarker nya;
20    
21     float[] gl_projection=new float[16];
22    
23     void setup() {
24     size(640,480,OPENGL);
25     colorMode(RGB, 100);
26     println(MultiMarker.VERSION);
27     cam=new Capture(this,640,480);
28     nya=new MultiMarker(this,width,height,"camera_para.dat",NyAR4PsgConfig.CONFIG_PSG);
29     nya.addARMarker("patt.hiro",80);//id=0
30    
31     //ProjectionMatrixOpenGLスタイルの行列で得る
32     PMatrix3D m=nya.getProjectionMatrix().get();
33     m.transpose();
34     m.get(gl_projection);
35     cam.start();
36    
37     }
38    
39    
40     void draw()
41     {
42     float[] mv=new float[16];
43    
44     if (cam.available() !=true) {
45     return;
46     }
47     cam.read();
48     nya.detect(cam);
49     background(0);
50     nya.drawBackground(cam);//frustumを考慮した背景描画
51    
52     PGraphicsOpenGL pg = (PGraphicsOpenGL) g;
53     GL2 gl = pg.beginPGL().gl.getGL().getGL2();
54    
55     //matrixmodeの退避
56     int current_mode=getCurrentMatrixMode(gl);
57    
58     for(int i=0;i<1;i++){
59     if((!nya.isExistMarker(i))){
60     continue;
61     }
62    
63     //projectionMarixの適応
64     gl.glMatrixMode(gl.GL_PROJECTION);
65     gl.glLoadMatrixf(gl_projection, 0 );
66    
67     //ModelView行列の適応
68     PMatrix3D m=nya.getMarkerMatrix(i);
69     m.transpose();
70     m.get(mv);
71     gl.glMatrixMode( gl.GL_MODELVIEW );
72     gl.glLoadIdentity();
73    
74     gl.glScalef( 1.0, -1.0, 1.0 );
75     gl.glMultMatrixf(mv,0);
76    
77    
78     //OpenGLオブジェクトの描画
79     drawGLObject(gl);
80     }
81    
82     //matrixmodeの復帰
83     gl.glMatrixMode(current_mode);
84     pg.endPGL();
85     }
86    
87     //現在のMatrixmodeを取得する。
88     int getCurrentMatrixMode(GL2 i_gl)
89     {
90     int[] tmp=new int[1];
91     i_gl.glGetIntegerv(GL2.GL_MATRIX_MODE,tmp,0);
92     return tmp[0];
93     }
94    
95     void drawGLObject(GL2 i_gl)
96     {
97     // 座標軸の描画
98     i_gl.glBegin(GL2.GL_LINES);
99     i_gl.glColor4f(1, 0, 0, 1);
100     i_gl.glVertex3f(0,0,0);
101     i_gl.glVertex3f(100,0,0);
102     i_gl.glColor4f(0, 1, 0, 1);
103     i_gl.glVertex3f(0,0,0);
104     i_gl.glVertex3f(0,100,0);
105     i_gl.glColor4f(0, 0, 1, 1);
106     i_gl.glVertex3f(0,0,0);
107     i_gl.glVertex3f(0,0,100);
108     i_gl.glEnd();
109     }
110    
111    
112    

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26