【问题标题】:Global Translation in libgdx is reset by method calculateTransforms?libgdx 中的全局翻译由方法 calculateTransforms 重置?
【发布时间】:2017-09-30 10:34:38
【问题描述】:

libgdx 中,当使用ModelModelInstance 执行以下代码时,它具有多个节点(其中一个是“臀部”):

Matrix4 mtr4 = new Matrix4().idt();
mtr4 = modelInstance.getNode("Hips").globalTransform.cpy();
mtr4 = mtr4.translate(deltaVector3);

modelInstance.getNode("Hips").globalTransform.set(mtr4);

//now, mtr4 still has the same value when:
mtr4 = modInstance.getNode("Hips").globalTransform.cpy();

modelInstance.calculateTransforms();

//after following, mtr4 will be reset to before it was translated with deltaVector3
mtr4 = modInstance.getNode("Hips").globalTransform.cpy();

为什么mtr4 的值会变回? calculateTransforms() 方法不是“应用”分配给节点的内容吗?

【问题讨论】:

    标签: java libgdx transformation


    【解决方案1】:

    引用calculateTransforms方法的documentation

    递归地计算此模型中所有Node 实例的本地和世界变换。首先每个Node.localTransform 变换是根据每个节点的平移、旋转和缩放来计算的。然后根据父节点的世界变换和每个节点的局部变换计算每个Node.calculateWorldTransform()。最后,动画骨骼矩阵会相应更新。

    如果节点的任何本地属性(平移、旋转、缩放)被修改,此方法可用于重新计算所有变换。

    因此,当您调用 calculateTransforms 方法时,确实会重新计算(并因此覆盖)localTransformglobalTransform(方法命名对此很明显)。

    如果您想直接使用矩阵,而不是 translationscalerotation 成员,那么您有两种选择:

    • 不要调用calculateTransforms方法,或者
    • isAnimated 成员设置为true 以通知calculateTransforms 方法它应该重新计算该特定节点的矩阵。为此,您应该改为修改 localTransform 成员。

    如果您不希望节点继承其父转换,则可以将inheritTransform 成员设置为false

    【讨论】:

    • node.rotation.set(quaternion) 时,调用calculateTransforms() 后,模型可视需要旋转;该方法实际上必须被调用,否则没有可见的结果。翻译为什么以及如何不同? @Xoppa 你能否也看看我的另一个问题来验证那里给出的答案,对于 libgdx 中的欧拉旋转顺序(stackoverflow.com/questions/41633455/…
    • 对于翻译,目标是用人体模型:从旋转一条腿,在全球世界中翻译脚。之前和之后状态之间的平移差异应添加到臀部,以便(当稍后通过将其全局位置重置为原点将脚“固定在地面上”时)人站起来(因为臀部向上移动)。有没有更好的方法在 libgdx 中使用例如是否有现有的 IK 解算器?
    • 目前还不清楚您的确切意思。如果您还有其他问题,那么您最好提出一个新问题。评论不适合那个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    相关资源
    最近更新 更多