# Newbie question - gluLookAt

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

## Recommended Posts

Hello! I'd like to rotate spherically the camera around an object but I'd like to know how to calculate the UP Vector, at the beginning my Up Vector is (0,0,1) but I need to know how to recalculate it so that when I'm on the very top of the object (when X, Y are zero) something different than (0,0,1).... I hope it makes sense heehe.. I'd really appreciate your help!!

##### Share on other sites
I would recommend a different rotation system instead of gluLookAt. Since Iassume you have angles already (the angles on the sphere from which you want to look) you should use a rotation system than is based on those angles instead of manually calculating something that is native in another rotation system.

What system to use depends a little bit on what you have and what you wan to achieve. For example, if you specify angles as absolute longitudal and latitudal coordinates on the sphere, then two glRotate calls with the angles and a glTranslate to get the radius will do. If you need a trackball like behaviour with arbitrary incremental axis/angle pairs, then a quaternion system would be more appropriate.

##### Share on other sites
Quote:
 Original post by Brother BobI would recommend a different rotation system instead of gluLookAt. Since Iassume you have angles already (the angles on the sphere from which you want to look) you should use a rotation system than is based on those angles instead of manually calculating something that is native in another rotation system.What system to use depends a little bit on what you have and what you wan to achieve. For example, if you specify angles as absolute longitudal and latitudal coordinates on the sphere, then two glRotate calls with the angles and a glTranslate to get the radius will do. If you need a trackball like behaviour with arbitrary incremental axis/angle pairs, then a quaternion system would be more appropriate.

Thanks man, I had started already to take a look at quaternions... they seem... let's say 'interesting' and a little bit difficult... Thanks!

##### Share on other sites
Quaternions aren't as difficult or mystical as they seem, once you learn what they are. They seem to be attractive to noobies, because it conjures images of "quantum physics" and such... :) It is just a different way of representing rotations.

If you are trying to rotate around an object, it is possible to do so by manipulating the up vector, but it is kind of unintuitive to do so.

For reference, the lookat function looks like this:
(camera position, lookat position, up vector)

Imagine the up vector as if you are standing somewhere, and point straight "up" at the sky. If you are standing on flat ground, your arm will be parallel to your head. If you are standing at an angle, you will still be pointing in the same direction, but your arm will be at a different angle from your head.

Now that we have a concept of the camera position and up vector, lets "look at" something. Suppose you are standing on the same plane that an object is on (ie, the same floor of a building). You point your arm straight up, and you have the up vector. Now suppose you walk up some steps, and stand on a balcony, and look at the object. Now you are looking down on the object (ie, you rotated around it), but when you point your arm up, it is still pointing in the same direction!

If you want to rotate the camera around the object, change the camera position, not the up vector. An example of changing the up vector would be if you are laying on a bed with your upper body and head hanging over, such that your head is upside down. The room looks like it is upside down -- basically, the "up vector" of your eyes was reversed.

Usually you want to up vector to remain the same, unless you are doing something like prey, where you can walk on the walls and ceiling.

The goal of computer graphics is to represent the world, and the way we perceive it -- so if you are having trouble visualizing something, try to visualize it in terms of the real world.

I am currently working on a skeletal animation system, so when I am thinking about it in class, I will be moving my arms and legs in various ways -- my classmates may thing I'm insane but.. gotta do something to fill boring lectures!

##### Share on other sites
Quote:

That was a very good explanation! Thank you very much...

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015437
×