MotionTracking¶
演示如何使用运动跟踪。
演示如何在不支持EasyAR运动跟踪的时候自动使用ARKit/ARCore
用法¶

开始时sample会检测水平面。水平面检测将在cube放在平面上后停止,然后可以点击 Unlock Plane 来重新开始检测。
场景中的Cube可以使用单指移动放在平面上。双指捏合可以放大缩小Cube,双指同时水平移动可以水平旋转Cube。
详解¶
VIO设备策略¶
VIOCameraDeviceUnion 是个设备 Union,根据 DeviceChooseStrategy 和系统情况会选择为MotionTracker或ARKit或ARCore。
在这个sample中, VIOCameraDeviceUnion.DeviceStrategy 设为 DeviceChooseStrategy.EasyARMotionTrackerFirst ,EasyAR motion tracking 如果可用会优先被选择。

世界中心下的物体¶
WorldRoot 可以用来实现这些功能,
在跟踪状态变化时控制物体显示和隐藏。
根据 ARSession.CenterMode 相对camera一起移动。
如果上面这些都有其它地方处理,那可以忽略 WorldRoot。
在这个sample中, WorldRootController.ActiveControl 设成 ActiveControlStrategy.HideWhenNotTracking ,这样cube会在跟踪失败时隐藏。

检测平面¶
这部分只有在EasyAR Sense 4.1及之后版本中,运行 EasyAR motion tracking 的时候才有效。
可以使用 VIOCameraDeviceUnion.HitTestAgainstHorizontalPlane 获取世界中平面的位置。可以在这个位置放置一个平面。
var viewPoint = new Vector2(0.5f, 0.333f);
var points = vioCamera.HitTestAgainstHorizontalPlane(viewPoint);
if (points.Count > 0)
{
Plane.transform.position = points[0];
...
}
在平面检测到之后,保持平面不动直至它即将超出视野。
var viewportPoint = Camera.main.WorldToViewportPoint(Plane.transform.position);
if (!Plane.activeSelf || viewportPoint.x < 0 || viewportPoint.x > 1 || viewportPoint.y < 0 || viewportPoint.y > 1)
{
...
}
在平面上移动物体¶
这部分只有在EasyAR Sense 4.1及之后版本中,运行 EasyAR motion tracking 的时候才有效。
可以对plane执行Raycast并移动cube。
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
TouchControl.transform.position = hitInfo.point;
...
}
中心模式¶
在空间感知功能中,有两个 ARSession.CenterMode 的模式是有效的。
在 ARSession.ARCenterMode.WorldRoot 模式中,camera会在设备运动时自动移动,而WorldRoot不会动。在 ARSession.ARCenterMode.Camera 模式中,设备运动时camera不会自动移动。大多数情况下建议使用 ARSession.ARCenterMode.WorldRoot 。