Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.opengl.*;
- import stereo.*;
- import saito.objloader.*;
- import javax.media.opengl.*;
- // declare that we need a OBJModel and we'll be calling it "model"
- OBJModel model;
- float rotX;
- float rotY;
- Stereo stereo = null;
- // these booleans will be used to turn on and off bits of the OBJModel
- boolean bTexture = true;
- boolean bStroke = false;
- boolean bMaterial = true;
- float cx = 0f; float cy = 0f; float cz = 10f;
- void setup()
- {
- size(600, 600, "stereo.PassiveStereoView");
- float eyeSep = (float) (999.999 / 30f); //?????
- eyeSep = .1f;
- frameRate(60);
- stereo = new Stereo(this, eyeSep, 45f, .1f, 1000f, Stereo.StereoType.ANAGLYPH_REDLEFT_CYANRIGHT);
- // making an object called "model" that is a new instance of OBJModel
- model = new OBJModel(this, "cassini.obj", "relative", TRIANGLES);
- // turning on the debug output (it's all the stuff that spews out in the black box down the bottom)
- model.enableDebug();
- model.scale(8);
- noStroke();
- }
- void draw()
- {
- background(32);
- lights();
- //this will do nothing until the model material is turned off
- fill(255,0,255);
- PassiveStereoView pgl = (PassiveStereoView) g;
- GL gl = pgl.beginGL();
- {
- // only needs to be called repeatedly if you are
- // changing camera position
- stereo.start(gl,
- cx, cy, cz,
- 0f, 0f, -1f,
- 0f, 1f, 0f);
- stereo.right(gl); // right eye rendering
- pushMatrix();
- translate(width/2, height/2, 0);
- rotateX(rotY);
- rotateY(rotX);
- render(gl);
- popMatrix();
- stereo.left(gl); // left eye rendering
- pushMatrix();
- translate(width/2, height/2, 0);
- rotateX(rotY);
- rotateY(rotX);
- render(gl);
- popMatrix();
- // only needed for anaglyph
- stereo.end(gl);
- }
- pgl.endGL();
- }
- void render(GL gl)
- {
- gl.glColor4f(1f,0f,1f,1f);
- gl.glTranslatef(0f,0f,-10f);
- model.draw();
- }
- void keyPressed() {
- // turns on and off the texture listed in .mtl file
- if(key == 't') {
- if(!bTexture) {
- model.enableTexture();
- bTexture = true;
- }
- else {
- model.disableTexture();
- bTexture = false;
- }
- }
- else if(key == 'm') {
- // turns on and off the material listed in .mtl file
- if(!bMaterial) {
- model.enableMaterial();
- bMaterial = true;
- }
- else {
- model.disableMaterial();
- bMaterial = false;
- }
- }
- else if(key == 's') {
- if(!bStroke) {
- stroke(10, 10, 10);
- bStroke = true;
- }
- else {
- noStroke();
- bStroke = false;
- }
- }
- // the follwing changes the render modes
- // POINTS mode is a little flakey in OPENGL (known processing bug)
- // the best one to use is the one you exported the obj as
- // when in doubt try TRIANGLES or POLYGON
- else if(key=='1') {
- stroke(10, 10, 10);
- bStroke = true;
- model.shapeMode(POINTS);
- }
- else if(key=='2') {
- stroke(10, 10, 10);
- bStroke = true;
- model.shapeMode(LINES);
- }
- else if(key=='3') {
- model.shapeMode(TRIANGLES);
- }
- else if(key=='4') {
- model.shapeMode(POLYGON);
- }
- else if(key=='5') {
- model.shapeMode(TRIANGLE_STRIP);
- }
- else if(key=='6') {
- model.shapeMode(QUADS);
- }
- else if(key=='7') {
- model.shapeMode(QUAD_STRIP);
- }
- if (key == 'a')
- {
- cz += .1f;
- }
- if (key == 'z')
- {
- cz -= .1f;
- }
- if(keyCode == LEFT) stereo.eyeSeperation -= .01;
- if(keyCode == RIGHT) stereo.eyeSeperation += .01;
- }
- void mouseDragged()
- {
- rotX += (mouseX - pmouseX) * 0.01;
- rotY -= (mouseY - pmouseY) * 0.01;
- }
Advertisement
Add Comment
Please, Sign In to add comment