Archived

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

krs-one

gluLookAt() vs. glTranslatef()

Recommended Posts

krs-one    122
I was reading in the OpenGL Game Programming book and it told about functions gluLookAt() and glTranslatef(). It said that the gluLookAt() function merely moves the camera around the plane, while the glTranslatef() function actually moves the plane around the camera, in a sense. First, are they right with this? I assume they are since they did, after all, write the book. And two, wouldn''t glTranslatef() cause a huge performance problem with huge scenes that have to move around the camera rather than the camera moving around them. Is gluLookAt() more efficient than glTranslatef()? Thanks, -Vic

Share this post


Link to post
Share on other sites
jwblair    122
Actually gluLookAt() and glTranslatef() do the same thing. The only difference is the programming style. Anytime that the camera moves, it is actually the environment that is moving, not the camera. So, no there will not be a performamce hit in using glTranslatef(). gluLookAt() does all the translations for you, so that you dont have to calculate them.

Hope this helps.....

Share this post


Link to post
Share on other sites
Dactylos    122
gluLookat also rotates the scene (if appropriate), so it does more work than glTranslate (meaning that you can''t really substitue one for the other, without a little extra work).

Share this post


Link to post
Share on other sites
khawk    2925
Right, the point of saying what I said in OGLGP was so you think of glTranslatef() as the scene moving, and gluLookAt() as moving the camera. That''s effectively what is happening, at least when you think of it on a higher level, which I try to do throughout the book to simplify concepts.

If you get MesaGL and look at the gluLookAt() code, you''ll see how they use the glTranslate() and glRotate() functions to "move" the camera.

Kevin

Share this post


Link to post
Share on other sites
brettporter    122
www.mesa3d.org

I can''t believe you didn''t put the view transformation in the book Kevin! I think it took me a couple of weeks to get my head around it the first time I saw it. Our lecturer used the whole room to get his point across. IIRC it is 6 transformations. But if all you are doing is looking across the X-Y plane, use glTranslatef

~~~
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