ARCore——模型旋转

ARCore – Model rotation

我在 ARCore Android 工作,我想在点击按钮时旋转 3D 模型。

我做了旋转,但问题是它不会在当前位置旋转,即如果模型在平面上的其他地方移动,它会回到模型投影的初始位置,在这里我们可以看到旋转。我想在平面上的任何地方旋转我的模型,它仍然在那里。

这是我的代码

 private void rotateRight(TransformableNode node, AxisClass objAxis, Vector3 pos) {
     node.getRotationController().setEnabled(true);
     node.getScaleController().setEnabled(true);
     node.getTranslationController().setEnabled(false);

     Quaternion rightMoveVector = new Quaternion();
     rightMoveVector = tNode.getLocalRotation();

     Quaternion orientations = new Quaternion();
     Quaternion orientation = Quaternion.axisAngle(new Vector3(pos.x, 1.0f, pos.z), rotateAngle);
     node.setLocalRotation(Quaternion.axisAngle(new Vector3(0.0f, 1.0f, 0.0f), rotateAngle));
     rotateAngle = rotateAngle + 30;
     objAxis.setRotateRight(String.valueOf(rotateAngle));
     objAxis.setY_axis(String.valueOf(Math.toRadians(rotateAngle)));
}

我正在回答我自己的问题,这对某些人会有帮助。

对于模型旋转,您必须重写 sceneform 中的 onupdate 方法 android。

执行旋转后,您必须设置模型位置,使其保持在原位。

Quaternion q1 = tNode.getLocalRotation();
        Quaternion q2 = Quaternion.axisAngle(new Vector3(0f, 1f, 0f), -2f);
        tNode.setLocalRotation(Quaternion.multiply(q1, q2));
        tNode.setLocalPosition(localPosition);