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


gluLookAt() Performance

Recommended Posts

Fruny    1658
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;


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

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

cross(side, forward, up);

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];

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().

Share this post

Link to post
Share on other sites
Fruny    1658
Original post by Maximus
I see no problem with just using glTranslatef and glRotatef without matrices

Gimbal lock ?
Ease of use ?

Share this post

Link to post
Share on other sites