【问题标题】:xna get correct direction 3dxna 获得正确的方向 3d
【发布时间】:2013-03-01 00:32:25
【问题描述】:

如果我有一个起始位置vector3和旋转vector3,我如何获得指示行进方向的矢量?我得到一个归一化向量来指示它是如何旋转的,但当然这仅指示它是如何旋转的,而不是行进方向。即,如果我在 y 上旋转应该会影响在 x 和 z 上的行进方向,而不是对在 y 上旋转的向量进行归一化,这将表明它已在 y 上旋转。

【问题讨论】:

    标签: c# xna


    【解决方案1】:

    在某些时候,您可能会使用“旋转 Vector3”并从中创建一个矩阵。该矩阵有一个 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;
    }
    

    【讨论】:

      【解决方案2】:

      除了 Steve H 的回答,您可能会发现您需要使用 Quarternions 在 3D 空间中更有效地进行旋转。我提供了一些链接,如果您决定使用 Quarternions,可能会对您有所帮助。

      Quarternion Structure (MSDN)

      Quarternion Tutorial (MSDN Social)

      Quarternion Rotation in XNA (Stackoverflow Question)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-03
        • 2013-08-12
        • 2013-10-01
        • 2018-07-04
        相关资源
        最近更新 更多