2012-07-27 33 views
0

如何將模型(在3D空間中)相對於他的旋轉向前移動? 例如:相對於他的旋轉向前移動模型XNA

rotation = new Vector3(0, MathHelper.ToRadians(90), 0); 
obj.Move(Vector3.Forward); 

Move函數具有與對象的一個​​單元移動到前進一個單位的左instade。 我嘗試過:

Matrix rotation = Matrix.CreateFromYawPitchRoll(rotation.x, rotation.y, 0); 

Vector3 translation = Vector3.Transform(Vector3.Forward, rotation); 
this.position += translation; 
translation = Vector3.Zero; 

但由於某種原因,它將模型向上移動。

回答

3

您的vector3組件'rotation.Y'意味着您要偏轉(圍繞Y軸旋轉90度)。

Matrix.CreateFromYawPitchRoll()需要info(rotation.Y)作爲參數中的第一個參數。您將它列爲第二個參數。

只要記住將params按照它們在函數中命名的順序放置:Yaw,Pitch,然後Roll。你有它的俯仰,偏航,滾動。