ARCore – 模型旋转

Bil*_*ilz 2 java android augmented-reality arcore sceneform

我正在 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)));
}
Run Code Online (Sandbox Code Playgroud)

Bil*_*ilz 5

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

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

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

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