Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help with lookAt camera


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Aitorman   Members   -  Reputation: 126

Like
0Likes
Like

Posted 17 September 2012 - 12:23 PM

Hello there.
I'm trying to make a camera in OpenGL wich follows an object, and i have implemented it like this:
The camera stores a vector wich represent an "offset" from the object to the camera. For example, if that vector is (0,0,-5), the camera will be 5 units behind the object.
Then I assign the object's rot to the camera's rot (all rotations are in quaternions), then I rotate the offset vector with the object's rotation, and I add the rotated offset to the camera's pos. That works fine for the camera position relative to the object. For the rotation, I use a lookAt function that takes the origin as the camera's pos, and the inverse of the rotated offset vector as the target object. This works fine too, except for one little problem:
when the camera is almost exactly below (or above) the object, but a little to the left, it is like this:
Posted Image

and when it's also almost below, but a bit to the right, I want it to behave like this:
Posted Image

But instead, i get this:
Posted Image

And I can't solve this problem, I've thought of adding 180 degrees of rotation in the cameras look vector when it's needed (in the second case), but that generates a problem In other situtations, when the object is rotated in a way that requires the camera to behave in the third image's way. What solution do you think is better to solve this problem?

Sponsor:

#2 bmarci   Members   -  Reputation: 368

Like
0Likes
Like

Posted 18 September 2012 - 11:51 PM

Hi, this is mostly the problem with LookAt camera matrix, the roll angle is unpredictable along one axis, usualy vertically, depending on what you use as an up_vector.
If you want to have the camra to be fixed with regard to the object, use the object's rotation for the camera too.

#3 Aitorman   Members   -  Reputation: 126

Like
0Likes
Like

Posted 20 September 2012 - 06:57 AM

Yeah, I've tried that, but the object's rotation only works for the camera if the offset is for example (0,0,5), but if it is (0,5,5), it doesn't work because It has to point 45 degrees for on the x axis than the object. Anyways, I have changed to another camera system. When you specify the offset vector, you also have to specify an offset rotation quaternion, and the camera's rotation will be the object's rotation multiplied by the offset rotation. So, if you have this offset vector (0,5,5), the offset rotation will have to rotate the object 45 degrees along the x axis to have the camera pointing to the object always




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS