camera lookat "jumps" around

Started by
2 comments, last by cignox1 16 years, 2 months ago
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.
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).

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?
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...

This topic is closed to new replies.

Advertisement