private void InitCamera() { //Debug.Log ("ServiceManager: Initializing Camera"); int videoWidth, videoHeight; bool okVP = DSHUnityPlugin.GetColorCamParams(out videoWidth, out videoHeight); if (!okVP) { //Debug.LogWarning ("Failed to get Camera parameter, please make sure you have Color camera connected"); return; } else { //Debug.Log ("Color camera Params: " + videoWidth + "x" + videoHeight); } _videoColor32Array = null; _videoColor32Array = new Color32[videoWidth * videoHeight]; _videoTexture = null; _videoTexture = new Texture2D(videoWidth, videoHeight, TextureFormat.RGB24, false); _videoTexture.hideFlags = HideFlags.HideAndDontSave; _videoTexture.filterMode = FilterMode.Bilinear; _videoTexture.wrapMode = TextureWrapMode.Clamp; _videoTexture.anisoLevel = 0; if (_useNativeGLTexture) { DAQRI.DSHUnityAbstraction.SetUnityColorRenderEventTextureID(_videoTexture.GetNativeTexturePtr()); } _visionAspectRatio = (float)videoWidth / (float)videoHeight; // This is temporary until we've decoupled the vision projection matrix from tracking _visionProjectionMatrix = Matrix4x4.Perspective(_visionFieldOfView, _visionAspectRatio, _nearPlane, _farPlane); }
/// <summary> /// Creates a new monoscopic camera. /// </summary> /// <param name="preserveAspectRatio">Preserves the aspect ratio of the video /// background and augmentations as the screen size changes.</param> public MonoCamera(DisplayManager displayManager, bool preserveAspectRatio) : base(displayManager) { this.preserveAspectRatio = preserveAspectRatio; this.opticalSeeThrough = false; gameObject = new GameObject("Mono Camera"); // set camera pose gameObject.transform.SetParent(displayManager.transform, false); if (useImuPose) { gameObject.transform.localPosition = Vector3.zero; gameObject.transform.localRotation = Quaternion.identity; } else { float[] posRaw = new float[3]; float[] rotRaw = new float[4]; DSHUnityPlugin.CameraGetPose(posRaw, rotRaw); gameObject.transform.localPosition = ServiceManager.Vector3FromFloatArray(posRaw); #if !UNITY_EDITOR gameObject.transform.localRotation = ServiceManager.QuaternionFromFloatArray(rotRaw); #endif } camera = gameObject.AddComponent <Camera> (); InitCamera(camera); ServiceManager.Instance.VisionParametersAvailable += Resize; DisplayManager.Instance.ScreenSizeChanged += Resize; }
private void StopPositionMonitor() { //Debug.Log ("ServiceManager: Stop VIO IMU"); DSHUnityPlugin.StopPositionMonitor(); _enablePose = false; _hasPoseData = false; }
private void StopIMU() { //Debug.Log ("ServiceManager: Stop IMU"); DSHUnityPlugin.StopIMU(); _enableIMU = false; _hasIMUData = false; }
private void InitThermal() { //Debug.Log ("ServiceManager: Initializing Thermal Camera"); int thermalWidth, thermalHeight; bool okVP = DSHUnityPlugin.GetThermalCamParams(out thermalWidth, out thermalHeight); if (!okVP || !_enableThermalUpdates) { //Debug.LogWarning ("Failed in InitThermal(), please make sure you have Thermal camera connected"); return; } else { //Debug.Log ("Thermal camera Params: " + thermalWidth + "x" + thermalHeight); } _thermalTexture = null; _thermalColor32Array = new Color32[thermalWidth * thermalHeight]; _thermalTexture = null; _thermalTexture = new Texture2D(thermalWidth, thermalHeight, TextureFormat.RGBA32, false); _thermalTexture.hideFlags = HideFlags.None; _thermalTexture.filterMode = FilterMode.Bilinear; _thermalTexture.wrapMode = TextureWrapMode.Clamp; _thermalTexture.anisoLevel = 0; if (_useNativeGLTexture) { DAQRI.DSHUnityAbstraction.SetUnityThermalRenderEventTextureID(_thermalTexture.GetNativeTexturePtr()); } _thermalAspectRatio = (float)thermalWidth / (float)thermalHeight; }
private bool StartCamera() { //Debug.Log ("ServiceManager: Start Camera"); bool status = DSHUnityPlugin.StartCamera(); _enableVideoTextureUpdates = status; InitCamera(); return(status); }
private bool StartPositionMonitor() { //Debug.Log ("ServiceManager: Start VIO IMU"); bool status = DSHUnityPlugin.StartPositionMonitor(); if (status) { _enablePose = true; } return(status); }
private bool StartIMU() { //Debug.Log ("ServiceManager: Start IMU"); bool status = DSHUnityPlugin.StartIMU(); if (status) { _enableIMU = true; } return(status); }
void Awake() { // Initialize the camera early so the textures are ready to be accessed // by other classes on Start DSHUnityPlugin.Initialize(); //Get the default parameters for color camera //InitCamera (); //Get the default parameters for thermal camera //InitThermal (); _visionProjectionMatrix = Matrix4x4.Perspective(_visionFieldOfView, _visionAspectRatio, _nearPlane, _farPlane); }
private void UpdatePose() { if (DSHUnityPlugin.GetVIOData(ref viodata)) { _imuQuaternion = viodata.Quat; _imuWorldPosition = viodata.WorldPosition; _imuWorldVelocity = viodata.WorldVelocity; _hasPoseData = true; } if (isVIODataInvalid()) { UpdateIMU(); } }
private void UpdateIMU() { DSHUnityPlugin.GetIMUQuaternion(quatTemp); _imuQuaternion.x = quatTemp [0]; _imuQuaternion.y = quatTemp [1]; _imuQuaternion.z = quatTemp [2]; _imuQuaternion.w = quatTemp [3]; DSHUnityPlugin.GetIMUGyro(gyroTemp); _imuGyro.x = gyroTemp[0]; _imuGyro.y = gyroTemp[1]; _imuGyro.z = gyroTemp[2]; _hasIMUData = true; }
private void UpdateVideoTexture() { if (_useNativeGLTexture) { GL.IssuePluginEvent(DAQRI.DSHUnityAbstraction.GetRenderEventFunc(), (int)DSHUnityPlugin.UNITY_RENDER_EVENTID.UPDATE_TEXTURE_GL_COLOR); } else if (_videoColor32Array != null) { bool updatedTexture = DSHUnityPlugin.GetColorCamData(_videoColor32Array); if (updatedTexture) { _videoTexture.SetPixels32(_videoColor32Array); _videoTexture.Apply(); } } }
private void UpdateThermalTexture() { if (_useNativeGLTexture) { GL.IssuePluginEvent(DAQRI.DSHUnityAbstraction.GetRenderEventFunc(), (int)DSHUnityPlugin.UNITY_RENDER_EVENTID.UPDATE_TEXTURE_GL_THERMAL); } else if (_thermalColor32Array != null) { bool updatedTexture = DSHUnityPlugin.GetThermalData(_thermalColor32Array); if (updatedTexture) { _thermalTexture.SetPixels32(_thermalColor32Array); _thermalTexture.Apply(); } } }
private bool StartThermal() { //Debug.Log ("ServiceManager: Start Thermal"); bool status = DSHUnityPlugin.StartThermal(); _enableThermalUpdates = status; if (!status || VIOEmulation) { int defaultThermalWidth = 160; int defaultThermalHeight = 120; _thermalTexture = new Texture2D(defaultThermalWidth, defaultThermalHeight, TextureFormat.RGBA32, false); _thermalTexture = LoadPNG("Texture/ThermalDefault"); //Application.dataPath + "/DAQRI/System/Textures/ThermalDefault.png"); } else { InitThermal(); } return(status); }
void Setup() { GetComponent <MeshRenderer>().material = (Material)Resources.Load("Materials/CameraBackdrop", typeof(Material)); GetComponent <MeshRenderer>().material.SetTexture("_MainTex", ServiceManager.Instance.GetThermalCameraTexture()); float[] posRaw = new float[3]; float[] rotRaw = new float[4]; DSHUnityPlugin.ThermalGetPose(posRaw, rotRaw); float thermalAspect = ServiceManager.Instance.GetThermalAspectRatio(); float dist = ServiceManager.Instance.GetFarClipPlane() * 0.95f; float halfFov = Mathf.Deg2Rad * (ServiceManager.Instance.GetThermalFieldOfView() / 2.0f); float height = Mathf.Tan(halfFov) * dist * 2.0f; float width = thermalAspect * height; //var rot = ServiceManager.QuaternionFromFloatArray (rotRaw); transform.localPosition = /*ServiceManager.Vector3FromFloatArray(posRaw) + rot * */ (new Vector3(0.0f, 0.0f, dist)); //transform.localRotation = rot; transform.localScale = new Vector3(width, -height, 1.0f); }
void Setup() { float[] posRaw = new float[3]; float[] rotRaw = new float[4]; DSHUnityPlugin.CameraGetPose(posRaw, rotRaw); float visionAspect = ServiceManager.Instance.GetVisionAspectRatio(); float dist = ServiceManager.Instance.GetFarClipPlane() * 0.95f; float halfFov = Mathf.Deg2Rad * (ServiceManager.Instance.GetVisionFieldOfView() / 2.0f); float height = Mathf.Tan(halfFov) * dist * 2.0f; float width = visionAspect * height; //var rot = ServiceManager.QuaternionFromFloatArray (rotRaw); transform.localPosition = /*ServiceManager.Vector3FromFloatArray(posRaw) + rot * */ (new Vector3(0.0f, 0.0f, dist)); #if !UNITY_EDITOR //transform.localRotation = rot; #endif transform.localScale = new Vector3(width, -height, 1.0f); }
private void StopCamera() { //Debug.Log ("ServiceManager: Stop Camera"); DSHUnityPlugin.StopCamera(); _enableVideoTextureUpdates = false; }
/// <summary> /// Creates a new stereoscopic camera. /// </summary> public StereoCamera(DisplayManager displayManager, bool preserveAspectRatio) : base(displayManager) { this.preserveAspectRatio = false; this.opticalSeeThrough = true; gameObject = new GameObject("Stereo Camera"); gameObject.transform.SetParent(displayManager.transform, false); GameObject leftCameraObject = new GameObject("Left Camera"); leftCameraObject.transform.SetParent(gameObject.transform, false); leftCamera = leftCameraObject.AddComponent <Camera> (); InitCamera(leftCamera); GameObject rightCameraObject = new GameObject("Right Camera"); rightCameraObject.transform.SetParent(gameObject.transform, false); rightCamera = rightCameraObject.AddComponent <Camera> (); InitCamera(rightCamera); leftCamera.rect = new Rect(0.0f, 0.0f, 0.5f, 1.0f); rightCamera.rect = new Rect(0.5f, 0.0f, 0.5f, 1.0f); float[] leftProjMatrixRaw = new float[16]; float[] rightProjMatrixRaw = new float[16]; float[] leftPosRaw = new float[3]; float[] leftRotRaw = new float[4]; float[] rightPosRaw = new float[3]; float[] rightRotRaw = new float[4]; DSHUnityPlugin.GetDisplayProjectionMatrices(ServiceManager.Instance.GetNearClipPlane(), ServiceManager.Instance.GetFarClipPlane(), leftProjMatrixRaw, rightProjMatrixRaw); DSHUnityPlugin.GetDisplayPoses(leftPosRaw, leftRotRaw, rightPosRaw, rightRotRaw); Matrix4x4 leftProjMatrix = ServiceManager.MatrixFromFloatArray(leftProjMatrixRaw); Matrix4x4 rightProjMatrix = ServiceManager.MatrixFromFloatArray(rightProjMatrixRaw); Vector3 leftPos = ServiceManager.Vector3FromFloatArray(leftPosRaw); Quaternion leftRot = ServiceManager.QuaternionFromFloatArray(leftRotRaw); Vector3 rightPos = ServiceManager.Vector3FromFloatArray(rightPosRaw); Quaternion rightRot = ServiceManager.QuaternionFromFloatArray(rightRotRaw); leftCamera.transform.localPosition = leftPos; leftCamera.transform.localRotation = leftRot; leftCamera.transform.localRotation = leftCamera.transform.localRotation; rightCamera.transform.localPosition = rightPos; rightCamera.transform.localRotation = rightRot; rightCamera.transform.localRotation = rightCamera.transform.localRotation; /*var eul = rightCamera.transform.localRotation.eulerAngles; * * eul.x = 0; * eul.y = -0.2f; * eul.z = 1.6f; * rightCamera.transform.localRotation = Quaternion.Euler (eul); */ /*eul = leftCamera.transform.localRotation.eulerAngles; * * eul.x = 0; * eul.y = 0.2f; * eul.z = -1.6f; * leftCamera.transform.localRotation = Quaternion.Euler (eul); */ leftCamera.projectionMatrix = leftProjMatrix; rightCamera.projectionMatrix = rightProjMatrix; ServiceManager.Instance.VisionParametersAvailable += Resize; DisplayManager.Instance.ScreenSizeChanged += Resize; }
private void StopThermal() { //Debug.Log ("ServiceManager: Stop Thermal"); DSHUnityPlugin.StopThermal(); _enableThermalUpdates = false; }