所以我有一个将网格位置转换为全局空间的方法:
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));
}
有什么想法吗?
最佳答案
您可以使用 Quaternion.Inverse() 函数。这会返回相反的旋转。所以应该反转。 您可以这样使用它:
transform.rotation = Quaternion.Inverse(target.rotation);
来源:http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Inverse.html
关于c# - 四元数反向旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23293433/