Jump to content
  • Advertisement
Sign in to follow this  
psycoding

camera lookat "jumps" around

This topic is 3871 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

I need to align my cam with a vector, and can't update the right and up vectors by rotating them. If I use the normal way of doing this right=cross(world_up,look) up=cross(look,right) It fails if the look vector is near to the worlds up vector. So I tried to use another axis if this was the case up=cross(look,world_right) right=cross(up,look) , but no matter what I do, it always jumps from one viewpoint to another if cam rotation uses x _and_ y axis _and_ if it uses the other axis for calculating up and right vectors. I have no clue why it doesn't work. please help me out of this situation. some lookat code with a short explanation would be nice.

Share this post


Link to post
Share on other sites
Advertisement
I am not sure how you are calculating your vectors when things rotate, but maybe it has something to do with the limits in which sin and cos are valid. (assuming you are using trig functions to get your vectors).

Share this post


Link to post
Share on other sites
Quote:
Original post by psycoding
I have no clue why it doesn't work.

Well, think about it this way. Suppose the world_up vector is +Y, and the look vector is -Y. Which way should it look? Is that valid under all circumstances?

Share this post


Link to post
Share on other sites
This is how I do it. It should work, but I've not yet extensively tested it.

if(eye == target)
{
Identity();
return; //eye and target are the same
}

vector4<T> z(target - eye);
z.Normalize();

vector4<T> u(up);
if(IsZero(z.x) && !IsZero(z.y) && IsZero(z.z)) u = vector4<T>(T(0), T(0), T(1));

vector4<T> x = z.Cross(up);
x.Normalize();

const vector4<T> y = z.Cross(x);



I'm in a right handed coordinate frame, if that matters...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!