Placing an object with a given compass bearing in ARCore

柔情痞子 提交于 2019-12-22 08:52:37

问题


I'd like to place a north facing arrow into an ARCore world using sceneform. I am trying to understand the correct system of transformations to go from the phone's compass to sceneform's quaternions.


回答1:


This was the code I used to solve the problem:

    //Get the phone's pose in ARCore
    Pose deviceOrientedPose = frame.getCamera().getDisplayOrientedPose().compose(
            Pose.makeInterpolated(
                    Pose.IDENTITY,
                    Pose.makeRotation(0, 0, (float)Math.sqrt(0.5f), (float)Math.sqrt(0.5f)),
                    dhelper.getRotation()));
    float[] devquat = deviceOrientedPose.getRotationQuaternion();
    //Get the phone's heading in relation to the real world
    float heading = compassListener.getBearing(); //Use ROTATION_VECTOR sensor
    Quaternion deviceFrame = new Quaternion();
    deviceFrame.set(devquat[0],devquat[1],devquat[2],devquat[3]);
    double[] rpy = quat2rpy(deviceFrame);
    //Rotate around y axis... rotation in this case is the desired rotation
    float rotAngle = ((360-rotation)+heading+(float)Math.toDegrees(rpy[1])+360))%360;
    Quaternion qt = Quaternion.axisAngle(Vector3.up(),rotAngle);

Essentially the idea here is to acquire the device pose irregardless of orientation. Subesquently, I listen to the bearing as given by the ROTATION_VECTOR sensor. Given that AR-Core's co-ordinate system is right-handed, rotation in the AR-Core world does not follow the convention where we describe a heading as clockwise to North. (360-rotation)+heading essentially rotates the anchor to face north (via +heading), then it applies the rotation of the desired heading (360-heading). And applies this to the camera's current rotation (float)Math.toDegrees(rpy[1])+360



来源:https://stackoverflow.com/questions/50894058/placing-an-object-with-a-given-compass-bearing-in-arcore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!