yaw+pitch = roll?

Started by
6 comments, last by qesbit 19 years, 2 months ago
I dont understand why the camera rotates around the Z axis, when both lookAt.X and lookAt.Y are > 0: pos is the change in position, lookAt represents the angles we're rotating by.

Matrix matT, matR;
Quaternion qR;
matT = Matrix.Translation( pos );
matPos = Matrix.Multiply( matT, matPos );	
qR = Quaternion.RotationYawPitchRoll( lookAt.X, lookAt.Y, 0 );								
matR = Matrix.RotationQuaternion( qR );						
matPos = Matrix.Multiply( matR, matPos );						
device.Transform.View = Matrix.Invert( matPos );		
pos = lookAt = new Vector3();

Advertisement
while a game like a 3D FPS may not NEED to rotate in the z axis, yaw+pitch != roll. Imagine tilting your head over to the side at an angle, that is roll, and you can't do it by a combination of turning and lifting your head.

There are two basic ways to define a camera. You can define the location of the camera, the point that the camera is looking at, and the direction of "up" for the camera, or you can define the location of the camera, the yaw and pitch (which define the direction that the camera is looking at), and the roll (which defines "up" for the camera).

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Oh sorry, I guess I did not explain my problem properly. I know yaw+pitch != roll.
What I want to know is, why the above code rotates the camera about the Z axis. Even though roll is always 0. If yaw and pitch are both above 0 (lookAt.X and lookAt.Y) the camera rotates about the all 3 axes. Can someone please explain to me, why that is happening?
uhm, perhaps it's because your lookat vector is the EXACT SAME vector as your position vector

"pos = lookAt = new Vector3();"

this creates ONE Vector3 and assigns the memory address of that object to pos and lookAt. You need two different vectors.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Nope. This is c# and managed directx. Vector3 is a value type (struct) all that new Vector3 does is set x,y,z to 0.
A few things:

What is matPos initialized to?
I believe the order of the Matrix.Multiply parameters might be wrong.
Why do you convert to a quaternion first? Is there no Matrix.RotationYawPitchRoll?
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Yes there is a Matrix.RotationYawPitchRoll replacing the quaternion with it does not make any change.
matPos.Translate( 0.0f, 0.0f, -500.0f );
Switching the parameters in Matrix.Multiply does not help.
Might be a bug in your math code.

This topic is closed to new replies.

Advertisement