使用Matrix4x4,行星围绕其局部y轴旋转

时间:2014-10-19 20:46:50

标签: c# unity3d

我在使用带有自定义旋转公式的Matrix4x4来确定如何围绕它的局部y轴从一个起始静态位置旋转球体(行星)时遇到了一些麻烦。这个星球完全没有旋转。我已经发布了以下代码。谢谢你的任何建议。

注意:ori将是每秒旋转的度数

void OrientationRate()
{
    Matrix4x4 o = new Matrix4x4();
    float theta = ori * Time.fixedDeltaTime;

    o[0, 0] = Mathf.Cos(theta);
    o[0, 2] = -Mathf.Sin(theta);
    o[2, 0] = Mathf.Sin(theta);
    o[2, 2] = Mathf.Cos(theta);

    Vector4 p = this.transform.eulerAngles;
    p.w = 1;

    Vector4 pprime = (o * p);

    //set the new position
    this.transform.Rotate(new Vector3(pprime.z, pprime.x, pprime.y) * Time.fixedDeltaTime);
}

0 个答案:

没有答案
相关问题