问题
How can I move a model (in 3D space) forward relative to his rotation? For example:
rotation = new Vector3(0, MathHelper.ToRadians(90), 0);
obj.Move(Vector3.Forward);
The function move has to move the object one unit to the left instade of one unit forward. I tried:
Matrix rotation = Matrix.CreateFromYawPitchRoll(rotation.x, rotation.y, 0);
Vector3 translation = Vector3.Transform(Vector3.Forward, rotation);
this.position += translation;
translation = Vector3.Zero;
But for some reason it moves the model up.
回答1:
Your vector3 component 'rotation.Y' implies you want to Yaw (rotate about the Y axis) 90 degrees.
The Matrix.CreateFromYawPitchRoll() wants that info (rotation.Y) as the 1st in parameter. You have it listed as the 2nd parameter.
Just remember to place the params in the same order they are named in the function: Yaw, Pitch, then Roll. You have it pitch, yaw, roll.
来源:https://stackoverflow.com/questions/11690691/move-model-forward-relative-to-his-rotation-xna