Archived

This topic is now archived and is closed to further replies.

Lord FlatHead

glTranslatef or gluLookAt ?

Recommended Posts

I noticed that in NeHe''s ''world loading'' tutorials (#10 and #23, I think), camera movement is done by just rotating all vertices in the scene based on the player''s movement. So the ''camera'' or viewpoint stays at 0,0,0 and the entire world gets rotated and translated with glTranslatef and glRotatef. Why not just use gluLookAt ? You can simply specify the ''camera'' position and where it is pointing at, and not worry about rotating and translating all vertexes in the world to give the illusion of player movement. Which method are you guys using in your stuff ? Is there any benefit to using translation/rotation that I don''t know of ? And why am I still up at 4:16 AM ? _________ "Maybe this world is another planet''''s hell." -- Aldous Huxley

Share this post


Link to post
Share on other sites
Both are acceptable, as they both do exactly the same thing. The camera is simply treated as a virtual object in OpenGL, and we specify its tranformation ("placing it in the scene") first (hence using glRotate/glTranslate on it as we do on other objects).

gluLookAt just provides a different format to specify the transformation of the camera (which is actually just implemented as the first transform applied to all geometry). A lot of people use vector representations for their camera, so this is a more convenient method for that case. Others may want to use Euler angles (for some reason ), so using glRotate/glTranslate may be more useful. Other gluttons for punishment may use quaternions, but to use these in OpenGL, we have to convert back to a matrix, or axis-angle (used in glRotate) representation.

Essentially, they both specify a transformation that is applied to all the geometry.

[End repetitive drivel]

Share this post


Link to post
Share on other sites
just to clarify...

the camera isn''t really an object in a scene - you do the transform first so that everything else moves. The camera stays where it is

While you can achieve gluLookAt with glRotate/glTranslate, its fairly complicated (about 6 transforms IIRC from uni). But you don''t have to use it if you are doing simple or well defined movement (like roll/yaw/pitch for flight).

You can also combine both - I often gluLookAt and then immediately rotate the scene

~~~
Cheers!
Brett Porter
PortaLib3D : A portable 3D game/demo libary for OpenGL
Community Service Announcement: Read How to ask questions the smart way before posting!

Share this post


Link to post
Share on other sites