I'd like to know if it's possible (or if there is a contributed library that would help) to display 3 views from 3 cameras pointing the same "object"?
import processing.opengl.*;
import javax.media.opengl.*;
GL gl;
float a = 0.0;
boolean bFlush = true;
public void setup() {
size(600, 600, OPENGL);
// noStroke();
colorMode(RGB,1);
frameRate(60);
}
public void draw() {
println(frameRate);
background(0);
// bottom Left port - FRONT View
gl = ((PGraphicsOpenGL)g).beginGL();
gl.glViewport (0, 0, 300, 300);
((PGraphicsOpenGL)g).endGL();
perspective(PI/6f, 1f, 10, 1000);
camera(0,0,600, 0,0,0, 0,1,0);
renderGeometry();
if (bFlush) {
gl.glFlush();
}
((PGraphicsOpenGL)g).endGL();
// bottom right viewport - BACK View
gl = ((PGraphicsOpenGL)g).beginGL();
gl.glViewport(300, 0, 300, 300);
((PGraphicsOpenGL)g).endGL();
perspective(PI/6f, 1f, 10, 1000);
camera(0,0,-600, 0,0,0, 0,1,0);
renderGeometry();
if (bFlush) {
gl.glFlush();
}
((PGraphicsOpenGL)g).endGL();
// top left port - LEFT Viewport
gl = ((PGraphicsOpenGL)g).beginGL();
gl.glViewport (0, 300, 300, 300);
((PGraphicsOpenGL)g).endGL();
perspective(PI/6f, 1f, 10, 1000);
camera(-600,0,0, 0,0,0, 0,1,0);
renderGeometry();
if (bFlush) {
gl.glFlush();
}
((PGraphicsOpenGL)g).endGL();
// top right port - RIGHT Viewport
gl = ((PGraphicsOpenGL)g).beginGL();
gl.glViewport(300, 300, 300, 300);
((PGraphicsOpenGL)g).endGL();
perspective(PI/6f, 1f, 10, 1000);
camera(600,0,0, 0,0,0, 0,1,0);
renderGeometry();
if (bFlush) {
gl.glFlush();
}
((PGraphicsOpenGL)g).endGL();
a += 0.005;
}
void renderGeometry() {
lights();
rotateX(a*1);
rotateY(a*1);
pushMatrix();
translate(50, 50);
scale(60);
beginShape(QUADS);
fill(0, 1, 1);
vertex(-1, 1, 1);
fill(1, 1, 1);
vertex( 1, 1, 1);
fill(1, 0, 1);
vertex( 1, -1, 1);
fill(0, 0, 1);
vertex(-1, -1, 1);
fill(1, 1, 1);
vertex( 1, 1, 1);
fill(1, 1, 0);
vertex( 1, 1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);
fill(1, 0, 1);
vertex( 1, -1, 1);
fill(1, 1, 0);
vertex( 1, 1, -1);
fill(0, 1, 0);
vertex(-1, 1, -1);
fill(0, 0, 0);
vertex(-1, -1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);
fill(0, 1, 0);
vertex(-1, 1, -1);
fill(0, 1, 1);
vertex(-1, 1, 1);
fill(0, 0, 1);
vertex(-1, -1, 1);
fill(0, 0, 0);
vertex(-1, -1, -1);
fill(0, 1, 0);
vertex(-1, 1, -1);
fill(1, 1, 0);
vertex( 1, 1, -1);
fill(1, 1, 1);
vertex( 1, 1, 1);
fill(0, 1, 1);
vertex(-1, 1, 1);
fill(0, 0, 0);
vertex(-1, -1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);
fill(1, 0, 1);
vertex( 1, -1, 1);
fill(0, 0, 1);
vertex(-1, -1, 1);
endShape();
popMatrix();
}
void keyPressed() {
if (key == 'f') {
bFlush = !bFlush;
}
}
The correct aspect is width/height, hard coding that value is not safe, besides who has a square monitor ;-) Also you don't want the znear clipping plane so high. It will clip away much of your scene. So to get something more like the Processing perspective use (similar to my adaped code line 26):However, I did had some trouble setting the perspective. I'm not sure exactly why, but using a strange proportion (like the one from my screen, /3 non-square) I had to change the perspective's "aspect" parameter accordingly - and as I don't know the math behind it, I just tried out proportions until I got it!