/// <summary> /// Get a CameraDevice instance. /// </summary> /// <returns>Return the CameraDevice instance</returns> public static CameraDevice GetInstance() { if (instance == null) { instance = new CameraDevice(); } return(instance); }
private void TransformBackgroundPlane(Camera camera, Transform planeTransform) { if (targetImage != null) { screenWidth = (int)targetImage.rectTransform.rect.width; screenHeight = (int)targetImage.rectTransform.rect.height; } else { screenWidth = Screen.width; screenHeight = Screen.height; } float widthRatio = (float)screenWidth / cameraWidth; float heightRatio = (float)screenHeight / cameraHeight; float farClipPlane = camera.farClipPlane * 0.90f; float tanFovWidth = (1.0f / (float)screenWidth) * (float)screenHeight; float frustumWidth = tanFovWidth * farClipPlane * camera.aspect; float viewWidth = (float)frustumWidth / screenWidth; float viewHeight = viewWidth * (widthRatio / heightRatio); float flipHorizontal = 1.0f; float flipVertical = 1.0f; if (CameraDevice.GetInstance().IsFlipHorizontal()) { flipHorizontal = -1.0f; } if (CameraDevice.GetInstance().IsFlipVertical()) { flipVertical = -1.0f; } if (MaxstARUtils.IsDirectXAPI()) { flipHorizontal = -flipHorizontal; } if (widthRatio > heightRatio) { planeTransform.localScale = new Vector3(widthRatio * cameraWidth * viewWidth * flipVertical, widthRatio * cameraHeight * viewWidth * flipHorizontal, 0.1f); planeTransform.localPosition = new Vector3(0.0f, 0.0f, farClipPlane); } else { planeTransform.localScale = new Vector3(heightRatio * cameraWidth * viewHeight * flipVertical, heightRatio * cameraHeight * viewHeight * flipHorizontal, 0.1f); planeTransform.localPosition = new Vector3(0.0f, 0.0f, farClipPlane); } if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D9 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12) { planeTransform.localScale = new Vector3(planeTransform.localScale.x, -planeTransform.localScale.y, planeTransform.localScale.z); } }
void OnPreRender() { if (screenWidth != Screen.width || screenHeight != Screen.height) { screenWidth = Screen.width; screenHeight = Screen.height; MaxstAR.OnSurfaceChanged(screenWidth, screenHeight); } if (orientation != Screen.orientation) { orientation = Screen.orientation; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { MaxstAR.SetScreenOrientation((int)orientation); } } if (nearClipPlane != arCamera.nearClipPlane || farClipPlane != arCamera.farClipPlane) { nearClipPlane = arCamera.nearClipPlane; farClipPlane = arCamera.farClipPlane; } int tempCameraWidth = CameraDevice.GetInstance().GetWidth(); int tempCameraHeight = CameraDevice.GetInstance().GetHeight(); if (tempCameraWidth == 0 || tempCameraHeight == 0) { return; } if (cameraWidth != tempCameraWidth || cameraHeight != tempCameraHeight) { cameraWidth = tempCameraWidth; cameraHeight = tempCameraHeight; } //if (AbstractCameraBackgroundBehaviour.Instance != null) //{ // TransformBackgroundPlane(arCamera, AbstractCameraBackgroundBehaviour.Instance.transform); //} arCamera.projectionMatrix = CameraDevice.GetInstance().GetProjectionMatrix(); }
internal void StartCloud() { loopState = true; this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY; while (this.loopState) { Thread.Sleep(100); TrackingState trackingState = TrackerManager.GetInstance().UpdateTrackingState(); TrackingResult trackingResult = trackingState.GetTrackingResult(); TrackedImage trackedImage = trackingState.GetImage(); int trackingCount = trackingResult.GetCount(); if (trackingCount == 0) { if (cloudState == CloudState.CLOUDSTATE_TRACKING) { cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY; } } else { cloudState = CloudState.CLOUDSTATE_TRACKING; } if (trackingCount == 0 && (cloudState == CloudState.CLOUDSTATE_TRACKING || cloudState == CloudState.CLOUDSTATE_FEATURE_COLLECT_READY)) { if (!TrackerManager.GetInstance().IsTrackerDataLoadCompleted() || cloudState == CloudState.CLOUDSTATE_STOP) { continue; } isGetFeatureState = true; bool isCameraMove = CameraDevice.GetInstance().CheckCameraMove(trackedImage); isGetFeatureState = false; if (isCameraMove) { GetCloudRecognition(trackedImage, (bool cloudResult, string featureBase64) => { if (cloudResult) { this.featureBase64 = featureBase64; this.cloudState = CloudState.CLOUDSTATE_CONNECT; } else { this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY; } if (this.restart) { this.loopState = true; this.restart = false; } cloudSemaphore.Release(); }); cloudSemaphore.WaitOne(); } } if (this.cloudState == CloudState.CLOUDSTATE_STOP) { this.loopState = false; } } }
void OnPreRender() { if (targetImage != null) { if (screenWidth != (int)targetImage.rectTransform.rect.width || screenHeight != (int)targetImage.rectTransform.rect.height) { screenWidth = (int)targetImage.rectTransform.rect.width; screenHeight = (int)targetImage.rectTransform.rect.height; if (arCamera.targetTexture != null) { arCamera.targetTexture.Release(); } int screenScale = (int)Screen.dpi / 100; float width = targetImage.rectTransform.rect.width; float height = targetImage.rectTransform.rect.height; renderTexture = new RenderTexture((int)(width * screenScale), (int)(height * screenScale), 24); arCamera.targetTexture = renderTexture; targetImage.material.mainTexture = renderTexture; targetImage.SetAllDirty(); MaxstAR.OnSurfaceChanged(screenWidth, screenHeight); } } else { if (screenWidth != Screen.width || screenHeight != Screen.height) { screenWidth = Screen.width; screenHeight = Screen.height; MaxstAR.OnSurfaceChanged(screenWidth, screenHeight); } } if (orientation != Screen.orientation) { orientation = Screen.orientation; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { MaxstAR.SetScreenOrientation((int)orientation); } } if (nearClipPlane != arCamera.nearClipPlane || farClipPlane != arCamera.farClipPlane) { nearClipPlane = arCamera.nearClipPlane; farClipPlane = arCamera.farClipPlane; } int tempCameraWidth = CameraDevice.GetInstance().GetWidth(); int tempCameraHeight = CameraDevice.GetInstance().GetHeight(); if (tempCameraWidth == 0 || tempCameraHeight == 0) { return; } if (cameraWidth != tempCameraWidth || cameraHeight != tempCameraHeight) { cameraWidth = tempCameraWidth; cameraHeight = tempCameraHeight; } if (AbstractCameraBackgroundBehaviour.Instance != null) { TransformBackgroundPlane(arCamera, AbstractCameraBackgroundBehaviour.Instance.transform); } arCamera.projectionMatrix = CameraDevice.GetInstance().GetProjectionMatrix(); }