问题:
我的目标是编写一个代码,它旋转一个BVH的根关节,在全球Y轴3左右,保持值在-180180范围内(就像MotionBuilder一样)。我试着用euler,四元数,矩阵(考虑到bvh的旋转顺序)旋转关节,但是我还没有找到正确的值MotionBuilder计算值x,y,z,以便它们对BVH文件有效。我想编写一个计算关节旋转x,y,z的代码,就像在MotionBuilder中一样。
例子:
初始:根部旋转:[x= -169.56, y=15.97, z=39.57]
algorithm - 像在MotionBuilder中一样如何计算旋转-LMLPHP
手动旋转约45度后:根部旋转:[x=-117.81, y=49.37, z=70.15]
algorithm - 像在MotionBuilder中一样如何计算旋转-LMLPHP
全球Y轴:
algorithm - 像在MotionBuilder中一样如何计算旋转-LMLPHP

最佳答案

在世界Y轴上旋转一个节点,下面的任意数量的学位(https://en.wikipedia.org/wiki/Rotation_matrix):

import math
from pyfbsdk import *

angle = 45.0
radians = math.radians(angle)
root_matrix = FBMatrix()
root.GetMatrix(root_matrix, FBModelTransformationType.kModelRotation, True)

transformation_matrix = FBMatrix([
    math.cos(radians), 0.0, math.sin(radians), 0.0,
    0.0, 1.0, 0.0, 0.0,
    -math.sin(radians), 0.0, math.cos(radians), 0.0,
    0.0, 0.0, 0.0, 1.0
])

result_matrix = root_matrix * transformation_matrix
root.SetMatrix(result_matrix , FBModelTransformationType.kModelRotation, True)

如果根节点上有任何预旋转,则过程更复杂,可以尝试使用带有lrmtodof方法的setvector设置旋转。
result_vector = FBVector3d()
root.LRMToDof(result_vector, result_matrix)
root.SetVector(result_vector, FBModelTransformationType.kModelRotation, True)

关于algorithm - 像在MotionBuilder中一样如何计算旋转,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55636412/

10-11 23:10
查看更多