Stereo viewing
From Processing
| Versions: | 1.0+ |
| Contributors: | johng |
| Started: | 2006-03-01 |
This is a way to create a stereoscopic view of a scene, i.e. one which gives an illusion of depth on the screen.
The theory is fairly simple, to create a stereo image you need to render the scene twice, once for each eye. Then you need to be able to display both views simultaneously in such a way taht a person looking at the image gets a sense of depth that doesn't really exist.
There are 2 common methods to achieve this, red/green images, where you need a pair of tinted glasses and the resultant image is created as a pair of monochrome images, tinted the same as the glasses. The second method is to render both eyes in full color, and place them side by side and get the viewer to try to look through the image so that each eye only sees one of the two images, and the superimpose to create the impression of depth.
Source Code
/** * stereo viewing taken from http://wiki.processing.org/index.php?title=Stereo_viewing * @author John Gilbertson */ import processing.opengl.*; import javax.media.opengl.*; GL gl; float rotation; void setup() { size(500,300,OPENGL); gl=((PGraphicsOpenGL)g).gl; //We need this to set some OPENGL options perspective(PI/3.0,1,0.1,1000); //this is needed ot stop the images being squashed noStroke(); rotation=0; } void draw() { rotation+=0.01; //you can vary the speed of rotation by altering this value ambientLight(64,64,64); //some lights to aid the effect pointLight(128,128,128,0,20,-50); background(0); fill(255); // Left Eye // Using Camera gives us much more control over the eye position camera(-10,0,-100,0,0,0,0,-1,0); // This means anything we draw will be limited to the left half of the screen gl.glViewport(50,50,200,200); pushMatrix(); rotateX(rotation); rotateY(rotation/2.3); box(30); translate(0,0,30); box(10); popMatrix(); // Right Eye camera(10,0,-100,0,0,0,0,-1,0); gl.glViewport(250,50,200,200); pushMatrix(); rotateX(rotation); rotateY(rotation/2.3); box(30); translate(0,0,30); box(10); popMatrix(); }