【问题标题】:How to calculate rotation just like in MotionBuilder如何像在 MotionBuilder 中一样计算旋转
【发布时间】:2019-09-02 07:41:49
【问题描述】:

问题:

我的目标是编写一个代码,将 bvh 的根关节旋转 θ 度围绕全局 y 轴3,并将值保持在-180 到@987654329 的范围内@(就像 MotionBuilder 一样)。我尝试使用欧拉、四元数、矩阵(考虑 bvh 的旋转顺序)旋转关节,但我还没有弄清楚如何获得正确的值。 MotionBuilder 计算值x,y,z,因此它们对 bvh 文件有效。我想编写一个代码来计算关节的旋转x,y,z,就像在 MotionBuilder 中一样。

示例:

初始:根轮换:[x= -169.56, y=15.97, z=39.57]

手动旋转45度左右后:根旋转:[x=-117.81, y=49.37, z=70.15]

全局y轴:

【问题讨论】:

    标签: algorithm animation 3d rotation motionbuilder


    【解决方案1】:

    要围绕世界 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)
    

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多