charliejay

05-04-2006, 05:01 AM

Despite much research on the topic, I have never been able to get gluLookat to work properly.

The problem is that with a fully dynamic camera, allowing the position to change produces what I can only describe as a drunken loss of control - everything starts off fine, but after a few seconds rotational input seems to have a spiral factor added to it, insofar as a pure roll input will seem to have a pitch component also. The position also seems to be updated incorrectly, but i'm at a loss to describe how, except that there's a sort of "drift"...

I don't have faulty code handy at the moment, but details of implementation as follows:

I have a left handed (x increases to the right) camera structure, with 3 axis vectors and a position (camera origin) vector.

Rotations about it's own axes on this structure work properly, i've used the same code in simple pure software tests.

Basic outline of setup code is below:

Update camera structure for next frame.

Select projection matrix

Load identity

Use gluPerspective(angle,-(aspect),1.0,100.0)

Select modelview matrix

Load identity

Use gluLookAt(

cam.O.x,cam.O.y,cam.O.z,

cam.Z.x,cam.Z.y,cam.Z.z,

cam.Y.x,cam.Y.y,cam.Y.z

)

Note the negation of aspect, which gives me x increasing to the right on the screen...

cam.O is the camera's origin, cam.Y is the camera's Y axis, cam.Z is the camera's Z axis, all in world coordinates.

That gives me the effect described above.

Initially, I was putting the gluLookAt on the projection matrix; I fixed that, but there was no difference.

I've tried doing away with gluPerspective and replaced it with glFrustum (can't remember if I did that so that x remained increasing to the right), but there was no difference.

Doing this makes it work perfectly, regardless of things like using glFrustum instead of gluPerspective:

Update camera structure for next frame.

Select projection matrix

Load identity

Use gluPerspective(angle,-(aspect),1.0,100.0)

Select modelview matrix

Load identity

glTranslatef(-cam.O.x,-cam.O.y,-cam.O.z)

Use gluLookAt(

0.0,0.0,0.0,

cam.Z.x,cam.Z.y,cam.Z.z,

cam.Y.x,cam.Y.y,cam.Y.z

)

Not sure if i've been putting the translate before or after the lookat - does it matter?

Anyone know what i'm doing wrong?

The problem is that with a fully dynamic camera, allowing the position to change produces what I can only describe as a drunken loss of control - everything starts off fine, but after a few seconds rotational input seems to have a spiral factor added to it, insofar as a pure roll input will seem to have a pitch component also. The position also seems to be updated incorrectly, but i'm at a loss to describe how, except that there's a sort of "drift"...

I don't have faulty code handy at the moment, but details of implementation as follows:

I have a left handed (x increases to the right) camera structure, with 3 axis vectors and a position (camera origin) vector.

Rotations about it's own axes on this structure work properly, i've used the same code in simple pure software tests.

Basic outline of setup code is below:

Update camera structure for next frame.

Select projection matrix

Load identity

Use gluPerspective(angle,-(aspect),1.0,100.0)

Select modelview matrix

Load identity

Use gluLookAt(

cam.O.x,cam.O.y,cam.O.z,

cam.Z.x,cam.Z.y,cam.Z.z,

cam.Y.x,cam.Y.y,cam.Y.z

)

Note the negation of aspect, which gives me x increasing to the right on the screen...

cam.O is the camera's origin, cam.Y is the camera's Y axis, cam.Z is the camera's Z axis, all in world coordinates.

That gives me the effect described above.

Initially, I was putting the gluLookAt on the projection matrix; I fixed that, but there was no difference.

I've tried doing away with gluPerspective and replaced it with glFrustum (can't remember if I did that so that x remained increasing to the right), but there was no difference.

Doing this makes it work perfectly, regardless of things like using glFrustum instead of gluPerspective:

Update camera structure for next frame.

Select projection matrix

Load identity

Use gluPerspective(angle,-(aspect),1.0,100.0)

Select modelview matrix

Load identity

glTranslatef(-cam.O.x,-cam.O.y,-cam.O.z)

Use gluLookAt(

0.0,0.0,0.0,

cam.Z.x,cam.Z.y,cam.Z.z,

cam.Y.x,cam.Y.y,cam.Y.z

)

Not sure if i've been putting the translate before or after the lookat - does it matter?

Anyone know what i'm doing wrong?