/// <summary> /// Called when device orientation is changed. /// </summary> /// <param name="displayRotation">Orientation of current activity. Index enum is same as Android screen /// rotation standard.</param> /// <param name="colorCameraRotation">Orientation of current color camera sensor. Index enum is same as Android /// camera rotation standard.</param> private void _OnDisplayChanged(OrientationManager.Rotation displayRotation, OrientationManager.Rotation colorCameraRotation) { if (IsRendering) { _SetRenderAndCamera(displayRotation, colorCameraRotation); } }
public static extern int TangoSupport_getDepthAtPointNearestNeighbor( ref TangoPointCloudIntPtr point_cloud, ref DVector3 poitnCloudTranslation, ref DVector4 pointCloudOrientation, ref Vector2 uvCoordinatesInColorCamera, OrientationManager.Rotation display_rotation, ref DVector3 colorCameraTranslation, ref DVector4 colorCameraOrientation, out Vector3 outputPoint);
public static extern int TangoSupport_fitPlaneModelNearPoint( ref TangoPointCloudIntPtr pointCloud, ref DVector3 pointCloudTranslation, ref DVector4 pointCloundOrientation, ref Vector2 uvCoordinates, OrientationManager.Rotation rotation, ref DVector3 cameraTranslation, ref DVector4 cameraOrientation, out DVector3 intersectionPoint, out DVector4 planeModel);
public static int TangoSupport_getDepthAtPointNearestNeighbor( ref TangoPointCloudIntPtr point_cloud, ref DVector3 poitnCloudTranslation, ref DVector4 pointCloudOrientation, ref Vector2 uvCoordinatesInColorCamera, OrientationManager.Rotation display_rotation, ref DVector3 colorCameraTranslation, ref DVector4 colorCameraOrientation, out Vector3 outputPoint) { outputPoint = Vector3.zero; return(Common.ErrorType.TANGO_SUCCESS); }
public static int TangoSupport_fitPlaneModelNearPoint( ref TangoPointCloudIntPtr pointCloud, ref DVector3 pointCloudTranslation, ref DVector4 pointCloundOrientation, ref Vector2 uvCoordinates, OrientationManager.Rotation rotation, ref DVector3 cameraTranslation, ref DVector4 cameraOrientation, out DVector3 intersectionPoint, out DVector4 planeModel) { intersectionPoint = new DVector3(); planeModel = new DVector4(); return(Common.ErrorType.TANGO_SUCCESS); }
/// <summary> /// Update AR screen material with camera texture size data /// (and distortion parameters if using distortion post-process filter). /// </summary> /// <param name="uOffset">U texcoord offset.</param> /// <param name="vOffset">V texcoord offset.</param> /// <param name="colorCameraRDisplay">Rotation of the display with respect to the color camera.</param> private static void _MaterialUpdateForIntrinsics( float uOffset, float vOffset, OrientationManager.Rotation colorCameraRDisplay) { Vector2[] uvs = new Vector2[4]; uvs[0] = new Vector2(0 + uOffset, 0 + vOffset); uvs[1] = new Vector2(0 + uOffset, 1 - vOffset); uvs[2] = new Vector2(1 - uOffset, 0 + vOffset); uvs[3] = new Vector2(1 - uOffset, 1 - vOffset); for (int i = 0; i < 4; ++i) { uvs[i] = _GetUnityUvBasedOnRotation(uvs[i], colorCameraRDisplay); } VideoOverlayProvider.SetARScreenUVs(uvs); }
/// @endcond /// <summary> /// Rotate color camera render material's UV based on the color camera orientation and current activity orientation. /// </summary> /// <param name="uv">Input UV.</param> /// <param name="colorCamerRDisplay">Combined rotation index with color camera sensor and activity rotation.</param> /// <returns>Converted UV in Vector2.</returns> private static Vector2 _GetUnityUvBasedOnRotation(Vector2 uv, OrientationManager.Rotation colorCamerRDisplay) { switch (colorCamerRDisplay) { case OrientationManager.Rotation.ROTATION_270: return(new Vector2(1 - uv.y, 1 - uv.x)); case OrientationManager.Rotation.ROTATION_180: return(new Vector2(1 - uv.x, 0 + uv.y)); case OrientationManager.Rotation.ROTATION_90: return(new Vector2(0 + uv.y, 0 + uv.x)); default: return(new Vector2(0 + uv.x, 1 - uv.y)); } }
/// <summary> /// Update current additional rotation matrix based on the display orientation and color camera orientation. /// /// Not that m_colorCameraPoseRotation will need to compensate the rotation with physical color camera. /// </summary> /// <param name="displayRotation">Orientation of current activity. Index enum is same same as Android screen /// orientation standard.</param> /// <param name="colorCameraRotation">Orientation of current color camera sensor. Index enum is same as Android /// camera orientation standard.</param> public static void UpdatePoseMatrixFromDeviceRotation(OrientationManager.Rotation displayRotation, OrientationManager.Rotation colorCameraRotation) { Tango.OrientationManager.Rotation r = RotateFromAToB(displayRotation, colorCameraRotation); switch (r) { case Tango.OrientationManager.Rotation.ROTATION_90: m_colorCameraPoseRotation = ROTATION90_T_DEFAULT; break; case Tango.OrientationManager.Rotation.ROTATION_180: m_colorCameraPoseRotation = ROTATION180_T_DEFAULT; break; case Tango.OrientationManager.Rotation.ROTATION_270: m_colorCameraPoseRotation = ROTATION270_T_DEFAULT; break; default: m_colorCameraPoseRotation = Matrix4x4.identity; break; } switch (displayRotation) { case Tango.OrientationManager.Rotation.ROTATION_90: m_devicePoseRotation = ROTATION90_T_DEFAULT; break; case Tango.OrientationManager.Rotation.ROTATION_180: m_devicePoseRotation = ROTATION180_T_DEFAULT; break; case Tango.OrientationManager.Rotation.ROTATION_270: m_devicePoseRotation = ROTATION270_T_DEFAULT; break; default: m_devicePoseRotation = Matrix4x4.identity; break; } }
/// <summary> /// Update AR screen rendering and attached Camera's projection matrix. /// </summary> /// <param name="displayRotation">Activity (screen) rotation.</param> /// <param name="colorCameraRotation">Color camera sensor rotation.</param> private void _SetRenderAndCamera(OrientationManager.Rotation displayRotation, OrientationManager.Rotation colorCameraRotation) { float cameraWidth = (float)Screen.width; float cameraHeight = (float)Screen.height; #pragma warning disable 0219 // Here we are computing if current display orientation is landscape or portrait. // AndroidHelper.GetAndroidDefaultOrientation() returns 1 if device default orientation is in portrait, // returns 2 if device default orientation is landscape. Adding device default orientation with // how much the display is rotated from default orientation will get us the result of current display // orientation. (landscape vs. portrait) bool isLandscape = (AndroidHelper.GetDefaultOrientation() + (int)displayRotation) % 2 == 0; bool needToFlipCameraRatio = false; float cameraRatio = (float)Screen.width / (float)Screen.height; #pragma warning restore 0219 #if !UNITY_EDITOR // In most cases, we don't need to flip the camera width and height. However, in some cases Unity camera // only updates a couple of frames after the display changed callback from Android; thus, we need to flip the width // and height in this case. // // This does not happen in the editor, because the emulated device does not ever rotate. needToFlipCameraRatio = (!isLandscape & (cameraRatio > 1.0f)) || (isLandscape & (cameraRatio < 1.0f)); if (needToFlipCameraRatio) { cameraRatio = 1.0f / cameraRatio; float tmp = cameraWidth; cameraWidth = cameraHeight; cameraHeight = tmp; } #endif TangoCameraIntrinsics alignedIntrinsics = new TangoCameraIntrinsics(); TangoCameraIntrinsics intrinsics = new TangoCameraIntrinsics(); VideoOverlayProvider.GetDeviceOrientationAlignedIntrinsics(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR, alignedIntrinsics); VideoOverlayProvider.GetIntrinsics(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR, intrinsics); if (alignedIntrinsics.width != 0 && alignedIntrinsics.height != 0) { // The camera to which this script is attached is an Augmented Reality camera. The color camera // image must fill that camera's viewport. That means we must clip the color camera image to make // its ratio the same as the Unity camera. If we don't do this the color camera image will be // stretched non-uniformly, making a circle into an ellipse. float widthRatio = (float)cameraWidth / (float)alignedIntrinsics.width; float heightRatio = (float)cameraHeight / (float)alignedIntrinsics.height; if (widthRatio >= heightRatio) { m_uOffset = 0; m_vOffset = (1 - (heightRatio / widthRatio)) / 2; } else { m_uOffset = (1 - (widthRatio / heightRatio)) / 2; m_vOffset = 0; } // Note that here we are passing in non-inverted intrinsics, because the YUV conversion is still operating // on native buffer layout. OrientationManager.Rotation rotation = TangoSupport.RotateFromAToB(displayRotation, colorCameraRotation); _MaterialUpdateForIntrinsics(m_uOffset, m_vOffset, rotation); _CameraUpdateForIntrinsics(m_camera, alignedIntrinsics, m_uOffset, m_vOffset); if (m_arCameraPostProcess != null) { m_arCameraPostProcess.SetupIntrinsic(intrinsics); } } else { Debug.LogError("AR Camera intrinsic is not valid."); } }