private void OnExtrinsicData(VLExtrinsicDataWrapper extrinsicData) { if (!this.useLastValidPose || !this.ready || this.initCamera == null) { return; } if (!extrinsicData.GetValid() || !extrinsicData.GetModelViewMatrix(this.modelViewMatrixArray)) { return; } // Apply the extrinsic camera parameters for (int i = 0; i < 16; ++i) { this.modelViewMatrix[i % 4, i / 4] = this.modelViewMatrixArray[i]; } /* * // TODO(mbuchner): Why is this necessary? According to the Unity * // documentation, Camera.worldToCameraMatrix should work with OpenGL * // coordinates. * this.modelViewMatrix[0, 2] = -this.modelViewMatrix[0, 2]; * this.modelViewMatrix[1, 2] = -this.modelViewMatrix[1, 2]; * this.modelViewMatrix[2, 2] = -this.modelViewMatrix[2, 2]; * * // Reverse the rotation of the scene which Unity does * // automatically * this.initCamera.worldToCameraMatrix = * this.invRotCamera * this.modelViewMatrix; */ // Compute the right-handed world to camera matrix Matrix4x4 worldToCameraMatrix = this.invRotCamera * this.modelViewMatrix; if (this.workerBehaviour.flipCoordinateSystemHandedness == VLUnityCameraHelper.FlipCoordinateSystemHandedness.Automatically) { worldToCameraMatrix *= VLUnityCameraHelper.rotationY180; } // Compute the left-handed world to camera matrix worldToCameraMatrix = VLUnityCameraHelper.flipZ * worldToCameraMatrix * VLUnityCameraHelper.flipZ; // Compute the left-handed camera to world matrix Matrix4x4 cameraToWorldMatrix = worldToCameraMatrix.inverse; // Extract the rotation and translation from the computed matrix this.initCamera.transform.rotation = Quaternion.LookRotation( cameraToWorldMatrix.GetColumn(2), cameraToWorldMatrix.GetColumn(1)); this.initCamera.transform.position = cameraToWorldMatrix.GetColumn(3); // TODO(mbuchner): Compute camera orientation in native code }
private void OnExtrinsicData(VLExtrinsicDataWrapper extrinsicData) { if (this.updateIgnoreCounter > 0) { this.updateIgnoreCounter -= 1; return; } bool valid = extrinsicData.GetValid(); // State changed from invalid to valid? if (valid && this.initMode) { // Clear the anchor otherwise the content can't be moved ClearContentAnchor(); this.initMode = false; } // State changed from valid to invalid? else if (!valid && !this.initMode) { // Don't go to initialization mode, because the HoloLens is able to // relocate itself //this.initMode = true; } }
private void OnExtrinsicData(VLExtrinsicDataWrapper extrinsicData) { if (this.updateIgnoreCounter > 0) { this.updateIgnoreCounter -= 1; return; } // State changed from invalid to valid? bool valid = extrinsicData.GetValid(); if (valid && this.initMode) { this.DeactivateInitMode(); } // State changed from valid to invalid? else if (!valid && !this.initMode) { // Don't go to initialization mode, because the HoloLens is able to // relocate itself //this.ActivateInitMode(); } if (!extrinsicData.GetModelViewMatrix(this.modelViewMatrixArray)) { return; } if (valid) { // Apply the extrinsic camera parameters for (int i = 0; i < 16; ++i) { this.modelViewMatrix[i % 4, i / 4] = this.modelViewMatrixArray[i]; } if (this.workerBehaviour.flipCoordinateSystemHandedness == VLUnityCameraHelper.FlipCoordinateSystemHandedness.Automatically) { this.modelViewMatrix *= VLUnityCameraHelper.rotationY180; } // Compute the left-handed world to camera matrix this.modelViewMatrix = VLUnityCameraHelper.flipZ * VLUnityCameraHelper.flipYZ * this.modelViewMatrix * VLUnityCameraHelper.flipZ; Vector3 t = this.modelViewMatrix.GetColumn(3); Quaternion q = Quaternion.LookRotation( this.modelViewMatrix.GetColumn(2), this.modelViewMatrix.GetColumn(1)); // Don't set the position directly. Interpolate smoothly in the // Update function instead this.contentTargetPosition = t; this.contentTargetRotation = q; } }
private void ExtrinsicDataHandler(IntPtr handle) { VLExtrinsicDataWrapper extrinsicData = new VLExtrinsicDataWrapper(handle, false); if (OnExtrinsicData != null) { OnExtrinsicData(extrinsicData); } if (OnTrackingState != null) { if (extrinsicData.GetValid()) { OnTrackingState(100, "0"); } else { OnTrackingState(0, "0"); } } extrinsicData.Dispose(); }