Yaw + Pitch = Roll

Started by
12 comments, last by Fingers_ 14 years, 5 months ago
Quote:current orientation I tried tracking the cumulative angle changes but it got messy fast.
In that case, the accumulated roll is to be expected. If you don't want this, you'll need to implement some sort of autoleveling, or manage your vehicle's orientation in some other way.

It also looks to me like there might be some issues with your rotation function. Does the quaternion class that you're using use the standard convention for multiplication order? Or does it use the 'reversed' convention?
Advertisement
Being that I had the same issue using the XNA math lib. I will go with the nature of the beast explanation. As stated I had noticed that other games such as X3 have the exact same issue. It also looks like any attempt to correct for it is also not working as there are cases such as pass 90 degrees in the pitch axis where a 180 degree roll is normal. So I guess for now I shall leave and revisit it later. Thank you for your help.
David, if you set up a quaternion to pitch/yaw and, say, always pass the same axis angle, it won't work as you expect because those rotations happen in the (already rotated) model coordinate system, not in the world coordinate system. Here's how you can get a "non-rolling" result, I use this for a pitch-able and yaw-able camera.

// call these to change the pitch/yawpublic void pitch(float delta) {	pitch += delta;	if (pitch >= 360f) {		pitch -= 360f;	}	else if (pitch <= 0f) {		pitch += 360f;	}}public void yaw(float delta) {	yaw += delta;	if (yaw >= 360f) {		yaw -= 360f;	}	else if (yaw <= 0f) {		yaw += 360f;	}		}...// on each frame, update the camera:public void update() {	...	transform.resetOrientation();	transform.rotate(yaw, 0.0f, 1.0f, 0.0f);	transform.rotate(pitch, 1.0f, 0.0f, 0.0f);	...	//(the rest omitted for brevity)}
This is correct, desirable behavior. A real spaceship or plane will do the same thing. Any attempt to "fix" it with Euler angles etc will result in unrealistic and annoying gimbal lock behavior.

Consider the case of the plane pitching up 90 degrees, then yawing right 90 degrees. Model it by holding a miniature plane in your hand if you'd like. The only realistic result is that the plane ends up rolled 90 degrees right and pointed horizontally to the right. If you used absolute yaw/pitch angles, changing the yaw angle when pointed up would result in the plane rolling rather than yawing from the pilot's point of view, making it feel like the plane is "stuck" pointing upward.

This topic is closed to new replies.

Advertisement