Archived

This topic is now archived and is closed to further replies.

goatgruff

Moving Objects Per Yaw/Pitch/Roll

Recommended Posts

Hello everyone, This is giving me a headache, I''m hoping someone can clarify. I have a model (A), it tracks Yaw, Pitch and Roll locally in its class. It also has a velocity, which is regularly updated based on speed changes etc. What I would like to know is this: How do I rotate the model based on its Yaw/Pitch/Roll (I can do this easily), BUT, how do I apply the velocity so that it always moves in the right direction in 3D space based on these values? I built a D3D camera class, and so I can fly around freely using the cursor keys and can rotate/yaw/move forward. I took a lot of this code out of the SDK, so the camera velocity, moves the camera forward with the Z value of the velocity vector, regardless of the angle the camera is at. I tried to take this over and do the same with models, so that when I change the Z value of its velocity, it moves through the world space based on its yaw/pitch/roll values? This would be very helpful, its giving me a headache. What am I missing? Warmest Regards to all, Goatie

Share this post


Link to post
Share on other sites
If you wish to move along the vector derived from your yaw, pitch, roll, then just create a yaw, pitch, roll rotation matrix, apply it to some standard forward vector (<0,0,1> or something similar), take the resulting vector, make sure it''s normalized, and move your object along that.

i.e. (in C#)

float velocity;
Vector3 Position;

Matrix rot = Matrix.RotationYawPitchRoll(yaw, pitch, roll)
Vector3 stdForward = new Vector3(0,0,1);
stdForward.TransformCoordinate(rot);
stdForward.Normalize();
Position += stdForward * velocity;

Share this post


Link to post
Share on other sites