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.
IndexProgramming Questions & HelpSyntax Questions › lookAt vs. camera
Page Index Toggle Pages: 1
lookAt vs. camera (Read 2077 times)
lookAt vs. camera
Apr 20th, 2005, 4:00am
 
Do the following snippets of code do the same thing?

Code:

beginCamera();
resetMatrix();
lookat(ex,ey,ez,cx,cy,cz,ux,uy,uz);
endCamera();


Code:

camera(ex,ey,ez,cx,cy,cz,ux,uy,uz);



I ask because I am trying to figure out if the new camera object can handle movement around a 3D space but still focus on a specified x, y, and z point.  I was previously doing it with translate combined with some rotateX, rotateY, and rotateZ trickery.  

Re: lookAt vs. camera
Reply #1 - Apr 20th, 2005, 4:29am
 
yup.

although a late-breaking bug was that we might have camera set up a bit backwards.. simon is looking into it. moving the camera around should be very intuitive right now, but if it's not, we broke something (and it sounds like we may have).

(edit) wasn't making sense
Re: lookAt vs. camera
Reply #2 - Apr 21st, 2005, 10:46pm
 
The camera setup is unfortunately, quite screwy.

The following code should, in my intepretation fo the reference, make a camera pan around the centre object (a ball with 3 axes), in a smooth circle.
However it does something weird, and I'm not quite sure how it's interpreting the values passed to it.

Code:

float a;

void setup()
{
size(600,600,P3D);
a=0;
}

void draw()
{
a+=0.01;
background(128);
//set camera "eye" x and y positions so they follow a circle radius 400 around point 0,0,0
//set camera "scene centre" to be 0,0,0
//set camrea "up" to be 0,1,0 , i.e. positive Y value = up;
camera(400.0*cos(a),0,400.0*sin(a),0.0,0.0,0.0,0.0,1.0,0.0);
//draw a sphere at 0,0,0 (no translate, so I assume 0,0,0...
noStroke();
fill(255);
sphere(10);
//draw 3 axes, form 0,0,0 along x, y and z axes.
beginShape(LINES);
stroke(255,0,0);
vertex(0,0,0);
vertex(100,0,0);
stroke(0,255,0);
vertex(0,0,0);
vertex(0,100,0);
stroke(0,0,255);
vertex(0,0,0);
vertex(0,0,100);
endShape();
//end result should, I think, be that the camera pans aroudn the ball and axes, keeping them centred.
}
Re: lookAt vs. camera
Reply #3 - Apr 22nd, 2005, 2:09am
 
lookat() and subsequently camera() are currently working somewhat backwards. The P5 dev crew is aware of the issue and they're currently sorting it out.

at the moment it's working more like the following (but not really):
Code:

lookat(centerX, centerY, eyeZ, eyeX, eyeY, centerZ, upX, upY, upZ);
Re: lookAt vs. camera
Reply #4 - May 2nd, 2005, 6:41am
 
Camera has been fixed in v86! lookAt and camera were too close in functionality to survive together, so only camera is left. It works just like gluLookat except that Y is reversed as in all things Processing. The code above now does what it was supposed to.
Re: lookAt vs. camera
Reply #5 - May 2nd, 2005, 12:35pm
 
Hot dog! I'll take a look at the CVS right away. Thanks Simon!

<< Scratch that... I'll take a look at the shiney new 86 >>

By the way, when you say that camera works just like gluLookat does that mean we'll have code that looks like this:

Code:
beginCamera();
resetMatrix();
camera(ex, ey, ez, cx, cy, cz, ux, uy, uz);
endCamera();


or this?

Code:
camera(ex, ey, ez, cx, cy, cz, ux, uy, uz); 

Re: lookAt vs. camera
Reply #6 - May 2nd, 2005, 2:38pm
 
I mean that the actual call is like gluLookat.

Here's the real skinny on what does what:

Code:

camera(); or
camera(ex, ey, ez, cx, cy, cz, ux, uy, uz);


do not need to be called from with beginCamera();/endCamera(); That's because they always apply to the camera transformation, and they always totally replace it. That means that any coordinate transforms done before camera(); in draw() will be wiped out. It also means that camera() always operates in untransformed world coordinates. Therefore it is always redundant to call resetMatrix(); before camera(); This isn't technically true of gluLookat, but it's pretty much how it's used.

Now, beginCamera(); and endCamera(); are useful if you want to move the camera around using transforms like translate(), etc. They will wipe out any coordinate system transforms that occur before them in draw(), but they will not automatically wipe out the camera transform. This means that they should be at the top of draw(). It also means that the following:

Code:

beginCamera();
rotateY(PI/80);
endCamera();


will result in a camera that spins without stopping. If you want to just rotate a small constant amount, try this:

Code:

beginCamera();
camera(); // sets up the default view
rotateY(PI/80);
endCamera();


That will rotate a little off of the default view. Note that this is entirely equivalent to

Code:

camera(); // sets up the default view
beginCamera();
rotateY(PI/80);
endCamera();


because camera() doesn't care whether or not it's inside a begin/end clause.

Basically it's safe to use camera() or camera(ex,ey,ez,cx,cy,cz,ux,uy,uz) as naked calls because they do all the matrix resetting automatically.
Page Index Toggle Pages: 1