Hi,
I try to make the node always face to the camera and make the user feel that the ViewRenderable is always looking at him.
(UI_ArSceneView as MyArFragment).arSceneView.scene.addOnUpdateListener { frameTime ->
(UI_ArSceneView as MyArFragment).arSceneView.arFrame?.let { frame ->
if (frame.camera.trackingState == TrackingState.TRACKING) {
textNodeArray.forEach { node ->
node.worldRotation=Quaternion(frame.camera.pose.rotationQuaternion[0], frame.camera.pose.rotationQuaternion[1], frame.camera.pose.rotationQuaternion[2], frame.camera.pose.rotationQuaternion[3])
}
}
}
}
I did. But not what I expected
Hi,
i don't now if the camera pose is the correct quaternion source. I think you should get the scene camera rotation. Check here the sample from google (under "Animate in onUpdate") -> https://developers.google.com/ar/develop/java/sceneform/build-scene
The name card over the planets in the solar system sample do this. You can see the code in Planet.java line 128
You want to subtract the position of the object from the position of the camera to get the direction vector.
Then use the Quaternion.lookRotation() method to get the rotation.
Vector3 cameraPosition = getScene().getCamera().getWorldPosition();
Vector3 cardPosition = infoCard.getWorldPosition();
Vector3 direction = Vector3.subtract(cameraPosition, cardPosition);
Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up());
infoCard.setWorldRotation(lookRotation);
@claywilkinson @bobekos Very thankful.
The name card over the planets in the solar system sample do this. You can see the code in Planet.java line 128
You want to subtract the position of the object from the position of the camera to get the direction vector.
Then use theQuaternion.lookRotation()method to get the rotation.Vector3 cameraPosition = getScene().getCamera().getWorldPosition(); Vector3 cardPosition = infoCard.getWorldPosition(); Vector3 direction = Vector3.subtract(cameraPosition, cardPosition); Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up()); infoCard.setWorldRotation(lookRotation);
How to rotate the model to achieve the same effect when the phone is rotated +90 degrees, -90 degrees
Most helpful comment
The name card over the planets in the solar system sample do this. You can see the code in Planet.java line 128
You want to subtract the position of the object from the position of the camera to get the direction vector.
Then use the
Quaternion.lookRotation()method to get the rotation.