Reputation: 196
I am working in ARCore Android and I want to rotate 3D model on button click.
I have done rotation but the problem is that it would not rotate on current position, i.e. if model is moved somewhere else on plane it come back to its initial position where model is projected and here we can see rotation. I want to rotate my model anywhere on plane and it remains there.
Here is my code
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)));
}
Upvotes: 2
Views: 1438
Reputation: 196
i am answering my own question, it would be helpful for someone.
for model rotation you have to override onupdate method in sceneform android.
after performing rotation you have to set model position so that it remains on its position.
Quaternion q1 = tNode.getLocalRotation();
Quaternion q2 = Quaternion.axisAngle(new Vector3(0f, 1f, 0f), -2f);
tNode.setLocalRotation(Quaternion.multiply(q1, q2));
tNode.setLocalPosition(localPosition);
Upvotes: 6