PDA

View Full Version : gluLookAt() vs glRotated() and glTranslated()



robertmachardy
05-05-2009, 08:47 AM
Why would the following render a cube at the orgin differently?
Note, the results look very similar, the cube has the same size and orientation, but it appears closer to the top of the viewport using the glRotated() and glTranslated() approach.


gluLookAt(1, 1, 1,
0, 0, 0,
0, 1, 0);

and


// rotate around the y axis
glRotated(-45, 0, 1, 0);

// rotate around the "rotated" x axis
glRotated(45, cos(radians(45)), 0.0, -sin(radians(45)));

glTranslated(1, 1, 1);

dletozeun
05-05-2009, 09:50 AM
Why would the following render a cube at the orgin differently?


I want to say, becausee it is not the same transformations. :)

You have to move the world the the camera origin first. So it should be:

glTranslated(-1, -1, -1);

robertmachardy
05-05-2009, 10:00 AM
Sorry, that was a typo.
I am actually using glTranslated(-1, -1, -1)

robertmachardy
05-05-2009, 11:06 AM
Just to clarify, I was calling glTranslated() correctly, and I am still having this issue.

dletozeun
05-05-2009, 12:50 PM
I did not looked at the camera orientation computation at first sight but I think you should invert the two glRotated calls:



// rotate around the "rotated" x axis
glRotated(45, cos(radians(45)), 0.0, -sin(radians(45)));

// rotate around the y axis
glRotated(-45, 0, 1, 0);

glTranslated(1, 1, 1);


Assuming signs are correct. But why do you bother with this particular case?