/// <summary> /// Get the most recent light estimate. /// </summary> /// <returns></returns> public LightEstimate GetLatestLightEstimate() { // Maintain frame consistency. if (Time.frameCount == m_latestLightEstimateFrame) { return(m_latestLightEstimate); } m_latestLightEstimateFrame = Time.frameCount; UnityTango.NativeImage nativeImage = new UnityTango.NativeImage(); if (!UnityTango.Device.TryAcquireLatestImageBuffer(ref nativeImage)) { Debug.LogError("Unable to acquire image buffer."); return(m_latestLightEstimate); } // The Y plane is always the first one. var yPlaneInfo = nativeImage.planeInfos[0]; IntPtr yPlaneStart = new IntPtr(nativeImage.planeData.ToInt64() + yPlaneInfo.offset); float intensity; ApiServiceErrorStatus status = TangoClientApi.TangoService_getPixelIntensity( yPlaneStart, (int)nativeImage.width, (int)nativeImage.height, nativeImage.planeInfos[0].rowStride, out intensity); if (status != ApiServiceErrorStatus.Success) { Debug.LogErrorFormat("Call to getPixelIntensity failed: {0}.", status); return(m_latestLightEstimate); } m_latestLightEstimate = new LightEstimate(intensity); UnityTango.Device.ReleaseImageBuffer(nativeImage); return(m_latestLightEstimate); }
public void LightEstimateMessageHandler(MessageEventArgs message) { m_LightEstimate = message.data.Deserialize <SerializableLightEstimate>(); }