当我有全局位置、全局旋转和局部旋转时计算局部位置

Calculating local positions when I have global positions, global rotations, and local rotaitions

我有一组数据,其中包含模型的局部旋转、全局旋转和全局位置。我需要计算每个骨骼的局部位置。

我首先尝试做 bone.globalpos - bone_parent.globalpos 然后意识到这些不依赖于旋转所以这就是 parent 和 child 骨骼之间的区别.我需要一些关于如何考虑旋转以及骨骼的建议。局部和全局旋转都存储为四元数。

我存储每个骨骼的数据

bone.globalpos (Vector3)
bone.globalrot (Quaternion)
bone.localpos (Unknown, but should be a Vector3)
bone.localrot (Quaternion)

由于局部姿势也应该基于旋转而不仅仅是与 parent 的距离,我不知道如何计算它。

示例数据:

bone_parent.globalpos = (-1.252995  8.46457E-05  37.22802)
bone_parent.globalrot = (-0.5405273 -0.4560547 -0.4560547 0.5405273)
bone_parent.localpos = (0 0 0) (I provided)
bone_parent.localrot = (1.0 0.0 0.0 0.0)
bone_child.globalpos = (-1.252995  5.001462  37.22802)
bone_child.globalrot = (0.4948359 0.505096 -0.505096 0.4948359)
bone_child.localpos = (0  0  5.001377) This is what I need to calculate, but here is the answer to what I'm trying to get
bone_child.localrot = (0.07421875 0.9970703 0 0)

据我所知,你想表达父坐标系中的方向向量。这可以通过使用父级的逆全局旋转来转换方向向量来完成。

child.localPos = transform(conjugate(parent.globalRot), child.globalPos - parent.globalPos)