Sign in to follow this  

gluLookAt vs glRotate

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

say i want my viewport to be always looking at a certiain position in 3d space. what are the differences /pros/cons of using gluLookAt and have the camera move around a sphere or using glRotate to rotate to basically rotate the scene and keep the camera at the same spot thanks

Share this post


Link to post
Share on other sites
Well, depending on how you are rotating, gluLookAt may be more efficient, since it just creates a single camera transformation matrix from 3 basis vectors. If you are actually calling glRotate, you may be doing a separate rotation for each axis, which requires 3 matrix multiplies per vertex.

Share this post


Link to post
Share on other sites
Quote:
Original post by smitty1276
Well, depending on how you are rotating, gluLookAt may be more efficient, since it just creates a single camera transformation matrix from 3 basis vectors. If you are actually calling glRotate, you may be doing a separate rotation for each axis, which requires 3 matrix multiplies per vertex.
IMO it's more a difference in functionality than performance (setting up your camera is unlikely to be a bottleneck, no matter how you do it).
Quote:
say i want my viewport to be always looking at a certiain position in 3d space. what are the differences /pros/cons of using gluLookAt and have the camera move around a sphere or using glRotate to rotate to basically rotate the scene and keep the camera at the same spot
gluLookAt() is a convenience function that hides the details of positioning and orienting the camera and inverting the matrix. It is most useful when you have a specific position and target in mind. However, people sometimes use it just to do the work of loading a coordinate system (derived in one way or another) into an OpenGL matrix, and inverting it.

I'm not entirely clear on what you have in mind, but it sounds like you want a camera that is always looking at the same target but can be positioned anywhere on the surface of a sphere that is centered on that target. If so, spherical coordinates along with gluLookAt() is a reasonable way to do it, and is probably easier than using glRotate*() and glTranslate*().

Share this post


Link to post
Share on other sites
Quote:
Original post by smitty1276
Well, depending on how you are rotating, gluLookAt may be more efficient, since it just creates a single camera transformation matrix from 3 basis vectors. If you are actually calling glRotate, you may be doing a separate rotation for each axis, which requires 3 matrix multiplies per vertex.


Absolutely false. There is no per vertex cost differences associated to different ways to set up the transforms. Granted when setting up the matrix it might be a bit faster to use gluLookAt - or then again it might not, but still, the point is, there is no added per vertex cost from glRotate.

Share this post


Link to post
Share on other sites
Quote:
Original post by oggialli
Quote:
Original post by smitty1276
Well, depending on how you are rotating, gluLookAt may be more efficient, since it just creates a single camera transformation matrix from 3 basis vectors. If you are actually calling glRotate, you may be doing a separate rotation for each axis, which requires 3 matrix multiplies per vertex.


Absolutely false. There is no per vertex cost differences associated to different ways to set up the transforms. Granted when setting up the matrix it might be a bit faster to use gluLookAt - or then again it might not, but still, the point is, there is no added per vertex cost from glRotate.


This is true. The vertices will get multiplied by the matrices anyway, so the PER vertex cost is the same, no matter how you get the matrix. gluLookAt() for me is usually better, unless you use your own camera class with quaternions, which I don't do very often.

Share this post


Link to post
Share on other sites

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this