【问题标题】:Quaternion reverse rotation?四元数反转?
【发布时间】:2014-04-25 12:39:09
【问题描述】:

所以我有一种方法可以将网格位置转换为全局空间:

public Vector3 GridToGlobal(IVector3 gridPos)
{
 Vector3 globalPos = new Vector3(gridPos.x, gridPos.y, gridPos.z);
 globalPos *= Scale;
 globalPos = Container.transform.rotation * globalPos;
 return globalPos;
}

现在当我想做相反的事情时,我将如何将矢量旋转到网格空间中?

public IVector3 GlobalToGrid(Vector3 globalPos)
    {
        globalPos -= Container.transform.position;
        globalPos = Container.transform.rotation * globalPos; //this will obviously rotate in the wrong direction
        globalPos /= Scale;
        return new IVector3((int)Mathf.Round(globalPos.x), (int)Mathf.Round(globalPos.y), (int)Mathf.Round(globalPos.z));
    }

有什么想法吗?

【问题讨论】:

    标签: c# rotation unity3d reverse quaternions


    【解决方案1】:

    您可以使用 Quaternion.Inverse() 函数。这会返回相反的旋转。所以应该反转。 你可以这样使用它:

     transform.rotation = Quaternion.Inverse(target.rotation);
    

    来源:http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Inverse.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 2019-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多