【问题标题】:Libgdx decal rotation around custom axisLibgdx 贴花围绕自定义轴旋转
【发布时间】:2014-09-12 09:01:18
【问题描述】:

我正在使用 Libgdx 引擎和 3d 空间贴花的应用程序。 现在我需要围绕 X、Y、Z 轴旋转贴花,但要围绕位于 3d 空间某处的自定义枢轴点。

我发现贴花具有transformationOffset 字段,它可能适用于某些计算,但仅限于Vector2。这意味着我只能在 X 和 Y 轴上移动枢轴点。 并且当在 Y 轴上旋转贴花时,无论枢轴在哪里,结果都是一样的。

decal.transformationOffset = new Vector2(0, -5);

decal.rotateX(newValues[0]);
decal.rotateY(newValues[1]);
decal.rotateZ(newValues[2]);

我也需要在 Z 轴上移动枢轴。

这个问题有解决办法吗?

Tnx!

编辑:

我已经成功地将贴花旋转到 3d 空间中的枢轴点,但前提是枢轴和贴花的 Z 位置相同。如果不是,我就达不到我的预期。

这是适用于具有相同 Z 值的枢轴的代码:

decal.transformationOffset = new Vector2(pivotPosition.x - decal.getPosition().x, pivotPosition.y - decal.getPosition().y);
Tween.to(decal, DecalTween.XYZ_ROTATION, 5f).target(0, 360, 0).repeatYoyo(Tween.INFINITY, 0f).start(tweenManager);

在补间中我这样做:

target.setRotationX(0);
target.setRotationY(0);
target.setRotationZ(0);
target.rotateX(newValues[0]);
target.rotateY(newValues[1]);
target.rotateZ(newValues[2]);

如何扩展它以使用和 Z 值作为枢轴。我正在尝试在旋转旁边添加和翻译动画来实现这一点,但结果很奇怪。

Tween.to(decal, DecalTween.MOVE_XYZ, 2.5f).target(decal.getPosition().x, decal.getPosition().y, pivotPosition.z - decal.getPosition().z).repeatYoyo(Tween.INFINITY, 0f).start(tweenManager);
    decal.transformationOffset = new Vector2(pivotPosition.x - decal.getPosition().x, pivotPosition.y - decal.getPosition().y);
Tween.to(decal, DecalTween.XYZ_ROTATION, 5f).target(0, 360, 0).repeatYoyo(Tween.INFINITY, 0f).start(tweenManager);

知道如何结合平移和旋转动画以在枢轴点上的圆形路径中进行贴花旋转吗?

【问题讨论】:

    标签: rotation libgdx decal


    【解决方案1】:

    我想我会回答我自己的问题。

    我扩展了 Decal 类,将 transformationOffset 更改为 Vector3。

    然后在 transformVertices 我添加了 tz 值,就像已经有 tx 和 ty 一样。并在计算顶点位置时加上 tz。

    就这么简单。

    如果有人知道为什么本机 libgdx 支持忽略了这一点,请告诉我。

    干杯。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2017-02-10
      • 2019-10-18
      • 2015-06-15
      相关资源
      最近更新 更多