Search code examples
javaandroidaugmented-realityarcore

Rotating and moving static object in ArCore


I'm using the camera anchor in ArCore to create a static object in the scene.

float scaleFactor = 1.0f;

camera.getPose().toMatrix(cameraAnchorMatrix, 0);
// Update and draw the model and its shadow.
Matrix.rotateM(cameraAnchorMatrix, 0, 110, 0f, 1f, 0f);

virtualObject.updateModelMatrix(cameraAnchorMatrix, scaleFactor / 10);
virtualObject.draw(viewmtx, projmtx, colorCorrectionRgba);

However rotating the object sometimes makes it not visible, also translating it doesn't seem to work. I'm also kinda guessing the values for the rotation. Also the object is visible from the top, how can I make it look more natural? (It's an arrow that's supposed to show a direction.) How can I move the object to the bottom left corner of the screen and rotate it from left to right?

enter image description here

This is how it looks at the moment. I want to move the arrow down and to the left and also tilt it forward. Then it should be able to rotate left and right. Thank your for your help.


Solution

  • Solved it with the following code:

    camera.getPose().compose(Pose.makeTranslation(0.37f, -0.17f, -1f)).extractTranslation().toMatrix(cameraAnchorMatrix, 0);           
    

    This makes the object appear 'behind' the camera and moves it to the bottom-left. Then you can rotate the object with the angle value:

     Matrix.rotateM(cameraAnchorMatrix, 0, 230 - directionChange, 0f, 1f, 0f);