/// <summary> /// Gets the latest point cloud from the depth camera. /// </summary> /// <returns>The latest point cloud from the depth camera.</returns> public PointCloud GetLatestPointCloud() { // Maintain frame consistency. if (Time.frameCount == m_latestPointCloudFrame) { return(m_latestRawPointCloud); } // Attempt to query latest point cloud. UnityTango.PointCloudData rawPointCloud = new UnityTango.PointCloudData(); if (!UnityTango.Device.TryGetLatestPointCloud(ref rawPointCloud)) { return(m_latestRawPointCloud); } // Update the latest point cloud. m_latestRawPointCloud = new PointCloud(rawPointCloud); m_latestPointCloudFrame = Time.frameCount; return(m_latestRawPointCloud); }
/// <summary> /// Constructor for a new PointCloud wrapping <c>rawPointCloud</c>. /// </summary> /// <param name="rawPointCloud">The raw point cloud to wrap. If <c>rawPointCloud</c> is null, the /// resulting PointCloud will have <c>IsValid</c> set to false.</param> public PointCloud(UnityTango.PointCloudData?rawPointCloud) { if (rawPointCloud == null) { IsValid = false; m_rawPointCloud = new UnityTango.PointCloudData(); Pose = new Pose(); m_unityWorldTDepthCamera = Matrix4x4.identity; return; } IsValid = true; m_rawPointCloud = rawPointCloud.Value; Pose = new Pose(); m_unityWorldTDepthCamera = Matrix4x4.identity; ApiPoseData apiPoseData = new ApiPoseData(); if (ExternApi.TangoService_getPoseAtTime(m_rawPointCloud.timestamp, new ApiCoordinateFramePair(Constants.START_SERVICE_T_DEPTH_FRAME_PAIR), ref apiPoseData) == ApiServiceErrorStatus.Success) { Matrix4x4 ss_T_depth = Matrix4x4.TRS(apiPoseData.translation.ToVector3(), apiPoseData.orientation.ToQuaternion(), Vector3.one); m_unityWorldTDepthCamera = Constants.UNITY_WORLD_T_START_SERVICE * ss_T_depth; Vector3 translation = m_unityWorldTDepthCamera.GetColumn(3); Quaternion rotation = Quaternion.LookRotation(m_unityWorldTDepthCamera.GetColumn(2), m_unityWorldTDepthCamera.GetColumn(1)); Pose = new Pose(translation, rotation); } else { ARDebug.LogError("Could not retrieve a pose for the point cloud."); Pose = new Pose(); m_unityWorldTDepthCamera = Matrix4x4.identity; } }