The transformations needed for correct stereo viewing are simple translations and off-axis projections . Computationally, the stereo viewing transforms happen last, after the viewing transform has been applied to put the viewer at the origin. Since the matrix order is the reverse of the order of operations, the viewing matrices should be applied to the modelview matrix first.
The order of matrix operations should be:
Assuming that the identity matrix is on the modelview stack and that we want to look at the origin from a distance of EYE_BACK:
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* the default matrix */ glPushMatrix() glDrawBuffer(GL_BACK_LEFT) gluLookAt(-IOD/2.0, 0.0, EYE_BACK, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); <viewing transforms> <modeling transforms> draw() glPopMatrix(); glPushMatrix() glDrawBuffer(GL_BACK_RIGHT) gluLookAt(IOD/2.0, 0.0, EYE_BACK, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); <viewing transforms> <modeling transforms> draw() glPopMatrix()
This method of implementing stereo transforms changes the viewing transform directly using a separate call to gluLookAt() for each eye view. Move fusion distance along the viewing direction from the viewer position, and use that point for the center of interest of both eyes. Translate the eye position to the appropriate eye, then render the stereo view for the corresponding buffer. This method is quite simple when real-world measurements are used.
An alternative, but less correct, method of implementing stereo transforms is to translate the views left and right by half of the interocular distance, then rotate by the inverse tangent of the ratio between the fusion distance and half of the interocular distance: With this method, each viewpoint is rotated towards the centerline halfway between the two viewpoints.