c# - 四元数反向旋转?

标签 c# rotation unity3d reverse quaternions

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

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/

相关文章:

c# - 如何从另一个对象中更改表单的组件?

javascript - 如何围绕字形的垂直中间或中心点应用 CSS 旋转过渡

android - 带有适用于AR的Google Play服务更新的初始屏幕后,Unity Android应用程序崩溃(2020年4月11日之后)

c# - Entity Framework 以一对多方式替换集合的正确方法

c# - 验证 Internet 连接或 Azure 服务 - Xamarin

c# - Entity Framework 6中如何生成38位ID映射

objective-c - 在 TabBarController 中旋转 Three20 Photo ViewController

java - 为什么我的围绕另一个点旋转一个点的方法不起作用?

opencv - 如何计算新的相机在3d空间中的位置和旋转,以在移动3d对象后获得完全相同的 View ?

c# - 如何在纯 C# 中制作队列消息代理