PDA

View Full Version : gluLookAt transformation



ulric
02-15-2004, 02:40 AM
Hi,

according to Nate Robins Tutorial transformation I wanted to raise up the viewpoint along the y axis.

The view should look like using an elevator outside of a building and looking onto the
front of the building at the opposite side of the street.


Beginning at gluLookAt(0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) I wanted to raise the "camera" along the y-axis. It should look like a view out of an elevator. The next step was gluLookAt( 0.0, 0.6, 2.0, 0.0, 0.6, 0.0, 0.0, 1.0, 0.0). But I was astonished that the line between the "camera" (0.0, 0.6, 2.0) and the aim (0.0, 0.6, 0.0) wasn't parallel to the z-axis.
The "camera" was looking down to the aim.
Can anybody explain me why or what I have done wrong.


Thanks in advance
Ulric

Jared
02-15-2004, 04:40 AM
sometimes im surprised what comes up in the advanced coding section.

you called loadidentity before lookat, that that before anything else (except clearing the buffers etc.) and never called identity again after that?

also lookat might be handy for 3rd person cams but its kind of useless for anything else once you know how to do it yourself.

ignore the rest if you want to stick with lookat for now.

its easier to set the camera yourself. your typical matrix is quite simple (ignoring scaling):
indices 0-3 are your local x-axis
5-7 local y, 8-11 local z and 12-15 the position.

to set the view we need the inverse, in that case (without scaling) just transpose the first part and use the negative dot product of the position with the axes as new position:
float viewMat[16]={
1,0,0,0, //Xx, Yx, Zx, 0
0,1,0,0, //Xy, Yy, Zy, 0
0,0,1,0, //Xz, Yz, Zz, 0
0,-0.6,0,1}; //-dot(P,X), -dot(P,Y), -dot(P,Z), 1

ulric
02-15-2004, 05:26 AM
Hi Jared

>[QUOTE]Originally posted by Jared:
>[B]sometimes im surprised what comes up in >the advanced coding section.

I posted it there because there were some similar topics.

>you called loadidentity before lookat, >that that before anything else (except >clearing the buffers etc.) and never >called identity again after that?

I did it. I know a little bit about OpenGL programming.

>also lookat might be handy for 3rd person >cams but its kind of useless for anything >else once you know how to do it yourself.

I just want'd to know, whether that is a correct behaviour of gluLookAt.

I didn't decide to use or not to use it.

But nevertheless thank's for your reply

Ysaneya
02-15-2004, 05:39 AM
It's not a correct behavior, but since it's unlikely a bug in gluLookAt, it's likely a bug in your code. Post your code or double check that your matrix is the modelview one, and that you're setting it to identity before calling gluLookAt.

Y.