【问题标题】:Getting the difference between two mirrored rotations in Unity在 Unity 中获取两个镜像旋转之间的差异
【发布时间】:2015-04-30 16:35:34
【问题描述】:

我在 Unity 中有两个示例对象,其结构如下:

EmptyGameObject1: scale(-1, 1, 1)
- Child1: rotation(-4, 167, 179)

EmptyGameObject2: scale(1, -1, -1)
- Child2: rotation(-1, -10, 0)

现在我想考虑到其父级的规模,得到子级欧拉角之间的差异。 Vector3.Distance 返回一个相当高的值,但我看到场景视图中孩子的旋转非常相似。

我知道父对象的负比例反映了子对象 - 但是 它在数学上对旋转有什么影响?

如何计算 x、y 和 z 的统一旋转差异?

【问题讨论】:

    标签: unity3d rotation


    【解决方案1】:

    假设var rotation1 = Child1.transform.rotation;var rotation2 = Child2.transform.rotation;(我们在世界空间中工作,对吧?)。我们想要找到从 Child1 到 Child2 的旋转(我们称之为 difference),这样 rotation1 * difference == rotation2。这意味着我们只需计算var difference = rotation2 * Quaternion.Inverse(rotation1);就可以找到它。现在我们知道了旋转,我们可以访问它的欧拉角属性来确定 x、y 和 z 角:difference.eulerAngles.x 等等。

    【讨论】:

    • 很高兴为您提供帮助。如果您尝试对其组件值进行操作,四元数可能会令人困惑,但在四元数操作上使用四元数会容易得多。改用欧拉角总是很诱人,因为它们看起来更直观,但在很多极端情况下,欧拉角会中断,而四元数却能完美运行。
    猜你喜欢
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 2020-03-22
    相关资源
    最近更新 更多