We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › two cameras in 3d sketch
Page Index Toggle Pages: 1
two cameras in 3d sketch (Read 1981 times)
two cameras in 3d sketch
Mar 24th, 2008, 5:55pm
 
Is is possible to have a sketch with multiple cameras, one pointed 180 degrees away from the other? This would be projected on two separate screens. I've looked at the 'most pixels ever' library, but this uses multiple screens for one large flat drawing area.

I suspect it's not possible within a regular processing sketch - any suggestions on where to look for that sort of thing?
Re: two cameras in 3d sketch
Reply #1 - Mar 24th, 2008, 7:43pm
 
You can do it with a bit of OpenGL hacking (google for "opengl multiple viewport" or similar) but you'll also have to sort of fake out Processing's built-in draw loop mechanism to render twice.  Something like this:  (non-kosher hackery provided *AS IS*)

Quote:


import processing.opengl.*;
import javax.media.opengl.*;
GL gl;
float rotx, roty;

void setup() {
 size(600,300,OPENGL);
 colorMode(HSB);
}

void draw() {
 background(0);
 // left viewport - front view
 g.beginDraw();
 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();
 g.endDraw();
 // right viewport - back view
 g.beginDraw();
 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();
 g.endDraw();
}

void renderGeometry() {
 lights();
 rotateX(rotx);
 rotateY(roty);
 randomSeed(0);
 for (int i=0; i<50; i++) {
   float x = random(-100,100);
   float y = random(-100,100);
   float z = random(-100,100);
   pushMatrix();
   translate(x,y,z);
   fill(random(256), 255, 255);
   box(i+1);
   popMatrix();
 }
}

void mouseDragged() {
 if (mouseButton==LEFT) {
   float dx = mouseX-pmouseX;
   float dy = mouseY-pmouseY;
   rotx += -dy * 0.01;
   roty += dx * 0.01;
 }
}


Re: two cameras in 3d sketch
Reply #2 - Mar 24th, 2008, 7:44pm
 
Right now I'm working on a project that needed to have two cameras, precisely because of two screens. The MPE library wasn't helpful for me, so what I did was create two classes, Projector and Touchscreen, that would draw things next to each other, in the same sketch, such that I can position the window exactly in the middle of the desktop, and the video card would do the rest (just make sure your vidcard supports 2 monitors fullscreen and with OpenGL. I found that some ATI cards won't support this setting, so when going fullscreen you would get a cloned image, instead of extending the desktop).

I needed to display some 2D stuff (menus, buttons and such) and 3D stuff. I asked somewhere in the forum for 2 cameras to no avail.

My solution: Just before drawing the 3D stuff, call camera() with the desired parameters, and when you are finished, call camera() again with the other parameters.

If the fps are high enough, you sould be able to display stuff with two different camera positions correctly.

I'm not sure if this is the correct or optimal approach, but it's working for me quite good. I display images and stuff in the touchscreen while at the same time displaying moving 3D stuff in the projector screen.

Just try to make the camera() calls as close to the drawing code as possible, so you get less delay.

Did I explain myself?

Re: two cameras in 3d sketch
Reply #3 - Feb 11th, 2010, 4:13pm
 
hi
i am trying the code above but there is a java error and cannot work with it. i would like to is as it may be helpful for a project i am doing

any help will be great

thanks in advance
Page Index Toggle Pages: 1