PDA

View Full Version : gluLookAt vs glRotate glTranslate

m3ntol
07-31-2005, 11:04 PM
Hello,
I'm an experienced C/C++ programmer but newby to OpenGL.
I have followed NeHe tutorials (very good ones!!) and now I'm trying to make a simple programm which travelling the camera across a scene.
I think the best choice is the 'gluLookAt' function but some people said this function is very time cost, and a better choice is to use a combination of 'glRotate' and 'glTrasnlate'. Is this true?
If I use this functions I need to make a lot of matrix transformations. Can anyone explain me why gluLookAt is inefficient?

Javier Nieto

memfr0b
08-01-2005, 12:04 AM
Originally posted by m3ntol:
I think the best choice is the 'gluLookAt' function but some people said this function is very time cost, and a better choice is to use a combination of 'glRotate' and 'glTrasnlate'. Is this true?Use whatever makes your code simpler. This part of the code will run approximatly once per frame, which makes most cost differences negligible.

If I use this functions I need to make a lot of matrix transformations. Can anyone explain me why gluLookAt is inefficient?The only reason i can think of, is that gluLookAt has to calculate three orthogonal unit vectors which requires a few cross products and square roots. Depending on your input data, calculating the axis and rotation angle for your camera might be about as costly.

jide
08-01-2005, 03:56 AM
gluLookAt should be optimized. I'm really convinced that GLU is not a library for nothing :)

The main advantage in such an optimization would reside in the fact that gluLookAt uses a single matrix whereas your code (when using glTranslate and glRotate) will have at least two matrices (and generally four because of the 3 axis rotations). This will imply several matrix multiplications that is obviously less fast than a single one.
There are also several other reasons depending on your needs.

So, as long as you don't require special needs, you really should gluLookAt for helping you.

m3ntol
08-02-2005, 03:19 AM
OK,
thank you for both responses. Now I get a clear idea of the gluLookAt :)