相对于他的旋转XNA向前移动模型 [英] Move model forward relative to his rotation XNA

查看:63
本文介绍了相对于他的旋转XNA向前移动模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何相对于模型的旋转向前移动模型(在3D空间中)? 例如:

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.

推荐答案

您的vector3分量"rotation.Y"表示您希望偏航(绕Y轴旋转)90度.

Your vector3 component 'rotation.Y' implies you want to Yaw (rotate about the Y axis) 90 degrees.

Matrix.CreateFromYawPitchRoll()希望该信息(rotation.Y)作为参数中的第一个.您已将其列为第二个参数.

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.

这篇关于相对于他的旋转XNA向前移动模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆