Skip to main content
GameDev.net gamedev.net
🔒 Locked

gluLookAt() Performance

Started by python_regious Nov 29, 2001 at 4:06 PM 3 replies 850+ views
Original Post
python_regious
python_regious
I was wondering whether there is a performance benefit of translating and rotating the scene manually over using the above function?
If at first you don't succeed, redefine success.
Fruny
Fruny
Here the code for gluLookAt, from SGI''s Sample Implementation

  
void GLAPI
gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,
GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,
GLdouble upz)
{
int i;
float forward[3], side[3], up[3];
GLfloat m[4][4];

forward[0] = centerx - eyex;
forward[1] = centery - eyey;
forward[2] = centerz - eyez;

up[0] = upx;
up[1] = upy;
up[2] = upz;

normalize(forward);

/* Side = forward x up */
cross(forward, up, side);
normalize(side);

/* Recompute up as: up = side x forward */

cross(side, forward, up);

__gluMakeIdentityf(&m[0][0]);
m[0][0] = side[0];
m[1][0] = side[1];
m[2][0] = side[2];

m[0][1] = up[0];
m[1][1] = up[1];
m[2][1] = up[2];

m[0][2] = -forward[0];
m[1][2] = -forward[1];
m[2][2] = -forward[2];

glMultMatrixf(&m[0][0]);
glTranslated(-eyex, -eyey, -eyez);
}


So, if you don''t need the normalizations and have combined all you rotations in a single matrix, you MAY be a little faster, otherwise go for simplicity and use gluLookAt().
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
python_regious
python_regious
Thanks I think I''ll stay with gluLookAt().
If at first you don't succeed, redefine success.
Maximus
Maximus
I see no problem with just using glTranslatef and glRotatef without matrices
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
Fruny
Fruny
quote:
Original post by Maximus
I see no problem with just using glTranslatef and glRotatef without matrices


Gimbal lock ?
Ease of use ?

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.