PDA

View Full Version : red/green stereo with orthognal projection



hjl
10-18-2002, 10:21 AM
Hi, all,

I'm writing one red/green 3D display program based on the demo program "pulsar". I want to use orthogonal projection instead of perspective projection used in the demo program. I made the modifications as follows (use glOrtho() to replace glFrustum()), but there was no disparity any more. Could you please help me out on this issue? I'm wondering whether I should change the equation related to camera positions somehow. Million thanks.

if (stereo) {

/* Misc stuff */
ratio = camera.screenwidth / (double)camera.screenheight;
radians = DTOR * camera.aperture / 2;
wd2 = here * tan(radians);
ndfl = here / camera.focallength;
/* Derive the two eye positions */
CROSSPROD(camera.vd,camera.vu,r);
Normalise(&r);
r.x *= camera.eyesep / 2.0;
r.y *= camera.eyesep / 2.0;
r.z *= camera.eyesep / 2.0;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
left = - ratio * wd2 - 0.5 * camera.eyesep * ndfl;
right = ratio * wd2 - 0.5 * camera.eyesep * ndfl;
top = wd2;
bottom = - wd2;
// glFrustum(left,right,bottom,top,here,there);
glOrtho(left,right,bottom,top,here,there);

glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_LEFT);
glLoadIdentity();
gluLookAt(camera.vp.x + r.x,camera.vp.y + r.y,camera.vp.z + r.z,
camera.vp.x + r.x + camera.vd.x,
camera.vp.y + r.y + camera.vd.y,
camera.vp.z + r.z + camera.vd.z,
camera.vu.x,camera.vu.y,camera.vu.z);

/* Write only the red component */
glColor4f(0.5, 0.0, 0.0, 0.0);
glColorMask ( 1, 0, 0, 0 ) ;
//MakeLighting();
MakeGeometry();

/* Clear depth buffer to get proper color blending*/
glClear(GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
left = - ratio * wd2 + 0.5 * camera.eyesep * ndfl;
right = ratio * wd2 + 0.5 * camera.eyesep * ndfl;
top = wd2;
bottom = - wd2;
// glFrustum(left,right,bottom,top,here,there);
glOrtho(left,right,bottom,top,here,there);

glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_LEFT);
glLoadIdentity();
gluLookAt(camera.vp.x - r.x,camera.vp.y - r.y,camera.vp.z - r.z,
camera.vp.x - r.x + camera.vd.x,
camera.vp.y - r.y + camera.vd.y,
camera.vp.z - r.z + camera.vd.z,
camera.vu.x,camera.vu.y,camera.vu.z);

/* Write only the green component */
glColor4f(0.0,0.5, 0.0, 0.0);
glColorMask ( 0, 1, 0, 0 ) ;
//MakeLighting();
MakeGeometry();

}