Move model forward relative to his rotation XNA

白昼怎懂夜的黑 提交于 2019-12-13 05:59:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!