We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
camera offset ? (Read 374 times)
camera offset ?
Jan 24th, 2008, 4:45pm
 
When using camera(), the "eyes" of the camera are centered on the screen. Is there a way to move that center point?

I need that because I'm working with 3D navigation, and I want to add a sidebar on the right of the screen, for the GUI, which means the 3D view has to be moved to the left.

Here's an example to illustrate. Here the cube is centered. What I need is to see the exact same 3d view, same perspective and same everything, but moved to the left.

Code:


void setup() {
size(800, 400, P3D);
fill(204);
}

void draw() {
lights();
background(0);
// Change height of the camera with mouseY
camera(0.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
0.0, 0.0, 0.0, // centerX, centerY, centerZ
0.0, 1.0, 0.0); // upX, upY, upZ
noStroke();
box(90);
stroke(255);
line(-100, 0, 0, 100, 0, 0);
line(0, -100, 0, 0, 100, 0);
line(0, 0, -100, 0, 0, 100);
}



Re: camera offset ?
Reply #1 - Jan 24th, 2008, 5:34pm
 
Try something like:

Code:
import javax.media.opengl.*;

// setup

draw()
{
GL gl=((PGraphicsOpenGL)g).beginGL();
gl.glViewport(leftOffset,0,width-leftOffset,height);
((PGraphicsOpenGL)g).endGL();
//draw 3D stuff

gl=((PGraphicsOpenGL)g).beginGL();
gl.glViewport(0,0,width,height);
((PGraphicsOpenGL)g).endGL();
//draw left menu
}
Re: camera offset ?
Reply #2 - Jan 24th, 2008, 5:49pm
 
thanks !

it's workin, except I'm getting GL_STACK_OVERFLOW ?

here's the code I got:

Code:

import processing.opengl.*;
import javax.media.opengl.*;

void setup() {
size(800, 400, OPENGL);
fill(204);
}

void draw() {
int leftOffset = -150;

lights();
background(0);
GL gl=((PGraphicsOpenGL)g).beginGL();
gl.glViewport(leftOffset,0,width,height);

// Change height of the camera with mouseY
camera(0.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
0.0, 0.0, 0.0, // centerX, centerY, centerZ
0.0, 1.0, 0.0); // upX, upY, upZ
noStroke();
box(90);
stroke(255);
line(-100, 0, 0, 100, 0, 0);
line(0, -100, 0, 0, 100, 0);
line(0, 0, -100, 0, 0, 100);

gl=((PGraphicsOpenGL)g).beginGL();
gl.glViewport(0,0,width,height);
}




also, the view is now different. Is it because this is overriding the PGraphics defaults? Can I somehow get back to them? I have various weeks of coding based on them..

Re: camera offset ?
Reply #3 - Jan 24th, 2008, 6:03pm
 
You need the endGL() line to stop the overflow thing.
The view differenceis a perspective thing, processing thinks that the window is "width" wide, but GL thinks it's not.

This seems to do what you want: (press mouse to enable so you can check that it looks how you expect)

Code:
import processing.opengl.*;
import javax.media.opengl.*;

void setup() {
size(800, 400, OPENGL);
fill(204);
}

void draw() {
int leftOffset = 150;

lights();
background(0);
GL gl=((PGraphicsOpenGL)g).beginGL();
if(mousePressed)
gl.glViewport(leftOffset,0,width,height);
((PGraphicsOpenGL)g).endGL();
// Change height of the camera with mouseY
camera(0.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
0.0, 0.0, 0.0, // centerX, centerY, centerZ
0.0, 1.0, 0.0); // upX, upY, upZ
noStroke();
box(90);
stroke(255);
line(-100, 0, 0, 100, 0, 0);
line(0, -100, 0, 0, 100, 0);
line(0, 0, -100, 0, 0, 100);

gl=((PGraphicsOpenGL)g).beginGL();
gl.glViewport(0,0,width,height);
((PGraphicsOpenGL)g).endGL();
}


Re: camera offset ?
Reply #4 - Jan 24th, 2008, 11:51pm
 
beautiful.. it works perfectly.. thanks so much! you saved my life !

Page Index Toggle Pages: 1