Hi,
I am working on some spatial augmented reality project. Therefore I have some c++/opengl code which exports both the projection and modelview matrices needed for an accurate projection of the scene onto a real world model . Based on the exported modelview and projection matrix, I would like to use Processing to create a nice scene. I am able to do this with the following code, making use of jogl.
Code:
import javax.media.opengl.*;
import processing.opengl.*;
import java.nio.FloatBuffer;
float[] modelview = {
0.670984f, 0.250691f, 0.674993f, 0, -0.288247f,
0.966749f, -0.137371f, 0f, -0.68315f, -0.0505059f, 0.720934f, 0f,
0.164808f, 2.1425f, 32.9616f, 1f };
float[] proj = {
0.78125f, 0, 0, 0, 0, 1.04167f, 0, 0, 0, 0, -1.0002f, -1, 0,
0, -2.0002f, 0 };
FloatBuffer mvbuf;
FloatBuffer projbuf;
void setup() {
size(1024,768, OPENGL);
mvbuf = FloatBuffer.wrap(modelview);
projbuf= FloatBuffer.wrap(proj);
}
void draw() {
background(0);
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; // g may change
GL gl = pgl.beginGL(); // always use the GL object returned by beginGL
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glLoadMatrixf(projbuf);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glLoadMatrixf(mvbuf);
drawGrid(100,10,gl);
pgl.endGL();
}
void drawGrid(float len, float offset,GL g){
int nr_lines = (int)(len/offset);
g.glColor3f(1,1,1);
g.glBegin(g.GL_LINES);
for(int i=-nr_lines; i<nr_lines;i++){
g.glVertex3f(i*offset,0,-nr_lines*offset);
g.glVertex3f(i*offset,0,nr_lines*offset);
}
for(int i=-nr_lines; i<nr_lines;i++){
g.glVertex3f(-nr_lines*offset,0,i*offset);
g.glVertex3f(nr_lines*offset,0,i*offset);
}
g.glEnd();
}
But I would like to use pure Processing to draw my scene, using
beginShape(); texture(img); ... endShape(); instead being forced to use jogl and having to write
gl.glBegin(gl.GL_QUADS); ... gl.glEnd();I tried to figure out how I can translate the style used by Opengl (with modelview and projection matrix only) to Processing (where there seems to be an additional camera matrix).
I know how the Opengl rendering pipeline works, but I am a bit confused with the Processing pipeline.
I don't really see how I can build an equivalent scene in Processing based on the exported projection and modelview matrix from Opengl without using jogl.
Any suggestions?