# gluLookAt vs glRotate

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

## 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 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 on other sites
Quote:
 Original post by smitty1276Well, 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 on other sites
Quote:
 Original post by smitty1276Well, 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 on other sites
Quote:
Original post by oggialli
Quote:
 Original post by smitty1276Well, 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.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 11
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632652
• Total Posts
3007649
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!