# camera lookat "jumps" around

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

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

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 21
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013367
×