Multiple gl cameras (perspectives) in a scene

Hey all,

I’d like to create a 3d scene and put two different cameras in the scene, rotated 90 degrees apart (but otherwise at the same location).

Right now I’m pu

  glMatrixMode(GL_PROJECTION);  
  glPushMatrix();  

  glMatrixMode(GL_MODELVIEW);  
  glPushMatrix(); 

  fNear = 0.5f;  
  //fFov = tan(30 * PI / 360);  
  fFov = tan(90 * PI / 360.0 );
             
  float ratio = ofGetWidth() / ofGetHeight();  

  glMatrixMode(GL_PROJECTION);  
  glLoadIdentity();  
          
  glFrustum(fNear*(-fFov * ratio + mCameraDirection[0]),  
	    fNear*(fFov * ratio + mCameraDirection[0]),  
	    fNear*(-fFov + mCameraDirection[1]),  
	    fNear*(fFov + mCameraDirection[1]),  
	    fNear, mHorizonDistance);  
          
  glMatrixMode(GL_MODELVIEW);  
  glLoadIdentity();  

  gluLookAt(mCameraDirection[0]*mCameraDirection[2], 
	    mCameraDirection[1]*mCameraDirection[2], 
	    0, 
	    mCameraDirection[0]*mCameraDirection[2], 
	    mCameraDirection[1]*mCameraDirection[2], 
	    -1, 
	    0, 
	    1, 
	    0);

  glTranslatef(mPosition[0], mPosition[1], mPosition[2]);

  /***********
  * DRAW SCENE
  ************/

  glMatrixMode(GL_PROJECTION);  
  glPopMatrix();  
  glMatrixMode(GL_MODELVIEW);  
  glPopMatrix(); 

And that works fine. However, I’d like to add a second camera and I’m not sure how. The ‘obvious’ way seems to be to put the above in a fbo, and then draw the scene again in a different fbo with different parameters for mCameraDirection and mCameraPosition – however, that requires me to draw the same scene twice. Is there a way to draw the scene once and put multiple camera angles into different fbos, or do I need to actually draw the scene twice?

thanks!

Unfortunately, you’ll need to draw them twice. Take a look at the 3d/advanced3dExample that comes with OF.

Check out the ofCamera class that comes with OF.

http://openframeworks.cc/documentation/3d/ofCamera.html

You can set which parts of the screen you draw your scene to by providing a rectangle coordinates in the arguments of ofCamera::begin( ofRectangle(x, y, w, h) );

And control your camera and lookAt position too,

ofCamera::setPosition();
ofCamera::lookAt();

You’ll still need to draw your scene 2x tho – one for each camera perspective.

Thanks for the suggestions; I’ll take a look at the example. It’s good to know that I need multiple cameras.

Mantissa: thanks for the suggestion; I used glFrustrum manually because I needed a particular field of view / camera angle at all times, and found it easier to hardcode the frustrum parameters.

thanks again all!