我想使用场景形式将一个朝北的箭头放置到 ARCore 世界中。我试图了解从手机指南针到场景形式四元数的正确转换系统。
问问题
2192 次
1 回答
-1
这是我用来解决问题的代码:
//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
于 2018-07-14T04:19:09.750 回答