gluLookAt() vs. glTranslatef()

Started by
5 comments, last by krs-one 22 years, 5 months ago
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
===www.cnunited.com===
Advertisement
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.....
Thanks!John William Blair "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee."
http://members.home.com/chucklez/wtc/index.html
Alright, thanks a lot! The book failed to make that clear to me.

Thanks,
-Vic
===www.cnunited.com===
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).
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

Admin for GameDev.net.

What''s MesaGL and where can I get it?
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!
~~~Cheers!Brett PorterPortaLib3D : A portable 3D game/demo libary for OpenGLCommunity Service Announcement: Read How to ask questions the smart way before posting!

This topic is closed to new replies.

Advertisement