在 ARCore 中放置具有给定罗盘方位的对象 [英] Placing an object with a given compass bearing in ARCore
问题描述
我想使用场景形式将一个朝北的箭头放置到 ARCore 世界中.我试图了解从手机的罗盘到场景形式的四元数的正确转换系统.
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.
推荐答案
这是我用来解决问题的代码:
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);
本质上,这里的想法是获取设备姿势,而不管方向如何.随后,我聆听 ROTATION_VECTOR
传感器给出的方位.鉴于 AR-Core 的坐标系是右手坐标系,AR-Core 世界中的旋转不遵循我们将航向描述为顺时针向北的惯例.(360-rotation)+heading
本质上是将锚点旋转到朝北(通过 +heading
),然后应用所需航向的旋转 (360-heading)
.并将其应用于相机的当前旋转 (float)Math.toDegrees(rpy[1])+360
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
这篇关于在 ARCore 中放置具有给定罗盘方位的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!