2013-02-28 82 views
0

如果我有起始位置vector3和旋轉vector3,如何獲得指示行進方向的矢量?我得到了一個標準化的矢量來表明它是如何旋轉的,但是當然這隻表示它如何旋轉而不是移動的方向。即,如果我在y上旋轉會影響x和z上的行進方向,而不是在y上旋轉的向量的normailzing會做什麼,這將表明它只是表示它已經在y上旋轉了。xna得到正確的方向3d

回答

1

在某些情況下,您可能會採用'旋轉Vector3'並從中創建一個Matrix。該矩陣具有Vector3屬性(Matrix.Forward),該屬性是對應於'旋轉Vector3'的方向。如果你不想混淆你已有的矩陣,這種方法應該可以完成這項工作。

Vector3 DirectionToTravel(bool rotationVecIsInRadians, Vector3 rotationVec)//rotation vec must not be normalized at this point 
{ 
    Vector3 result; 

    if (!rotationVecIsInRadians) 
    { 
     rotationVec *= MathHelper.Pi/180f; 
    } 

    float angle = rotationVec.Length(); 
    rotationVec /= angle; //normalizes rotation vec 

    result = Matrix.CreateFromAxisAngle(rotationVec, angle).Forward; 

    return result; 
}