|
2 | 2 | 'use strict';
|
3 | 3 |
|
4 | 4 | function XRData() {
|
5 |
| - this.leftProjectionMatrix = mat4.create(); |
6 |
| - this.rightProjectionMatrix = mat4.create(); |
7 |
| - this.leftViewMatrix = mat4.create(); |
8 |
| - this.rightViewMatrix = mat4.create(); |
9 |
| - this.sitStandMatrix = mat4.create(); |
| 5 | + this.leftProjectionMatrix = [1, 0, 0, 0, |
| 6 | + 0, 1, 0, 0, |
| 7 | + 0, 0, 1, 0, |
| 8 | + 0, 0, 0, 1]; |
| 9 | + this.rightProjectionMatrix = [1, 0, 0, 0, |
| 10 | + 0, 1, 0, 0, |
| 11 | + 0, 0, 1, 0, |
| 12 | + 0, 0, 0, 1]; |
| 13 | + this.leftViewMatrix = [1, 0, 0, 0, |
| 14 | + 0, 1, 0, 0, |
| 15 | + 0, 0, 1, 0, |
| 16 | + 0, 0, 0, 1]; |
| 17 | + this.rightViewMatrix = [1, 0, 0, 0, |
| 18 | + 0, 1, 0, 0, |
| 19 | + 0, 0, 1, 0, |
| 20 | + 0, 0, 0, 1]; |
10 | 21 | this.gamepads = [];
|
11 | 22 | this.controllerA = new XRControllerData();
|
12 | 23 | this.controllerB = new XRControllerData();
|
|
542 | 553 | JSON.stringify({
|
543 | 554 | canPresentAR: this.isARSupported,
|
544 | 555 | canPresentVR: this.isVRSupported,
|
545 |
| - hasPosition: true, // TODO: check this |
546 | 556 | hasExternalDisplay: false // TODO: check this
|
547 | 557 | })
|
548 | 558 | );
|
|
715 | 725 | }
|
716 | 726 | }
|
717 | 727 |
|
718 |
| - // Convert WebGL to Unity compatible Vector3 |
719 |
| - XRManager.prototype.GLVec3ToUnity = function(v) { |
720 |
| - v[2] *= -1; |
721 |
| - return v; |
722 |
| - } |
723 |
| - |
724 |
| - // Convert WebGL to Unity compatible Quaternion |
725 |
| - XRManager.prototype.GLQuaternionToUnity = function(q) { |
726 |
| - q[0] *= -1; |
727 |
| - q[1] *= -1; |
728 |
| - return q; |
729 |
| - } |
730 |
| - |
731 |
| - // Convert WebGL to Unity Projection Matrix4 |
732 |
| - XRManager.prototype.GLProjectionToUnity = function(m) { |
733 |
| - var out = mat4.create(); |
734 |
| - mat4.copy(out, m) |
735 |
| - mat4.transpose(out, out); |
736 |
| - return out; |
737 |
| - } |
738 |
| - |
739 |
| - // Convert WebGL to Unity View Matrix4 |
740 |
| - XRManager.prototype.GLViewToUnity = function(m) { |
741 |
| - var out = mat4.create(); |
742 |
| - mat4.copy(out, m); |
743 |
| - mat4.transpose(out, out); |
744 |
| - out[2] *= -1; |
745 |
| - out[6] *= -1; |
746 |
| - out[10] *= -1; |
747 |
| - out[14] *= -1; |
748 |
| - return out; |
749 |
| - } |
750 |
| - |
751 | 728 | XRManager.prototype.onSessionStarted = function (session) {
|
752 | 729 | let glLayer = new XRWebGLLayer(session, this.ctx);
|
753 | 730 | session.updateRenderState({ baseLayer: glLayer });
|
|
825 | 802 |
|
826 | 803 | for (let view of pose.views) {
|
827 | 804 | if (view.eye === 'left') {
|
828 |
| - xrData.leftProjectionMatrix = this.GLProjectionToUnity(view.projectionMatrix); |
829 |
| - xrData.leftViewMatrix = this.GLViewToUnity(view.transform.inverse.matrix); |
| 805 | + xrData.leftProjectionMatrix = view.projectionMatrix; |
| 806 | + xrData.leftViewMatrix = view.transform.matrix; |
| 807 | + xrData.leftViewMatrix[6] *= -1; |
| 808 | + xrData.leftViewMatrix[8] *= -1; |
| 809 | + xrData.leftViewMatrix[9] *= -1; |
| 810 | + xrData.leftViewMatrix[14] *= -1; |
830 | 811 | } else if (view.eye === 'right') {
|
831 |
| - xrData.rightProjectionMatrix = this.GLProjectionToUnity(view.projectionMatrix); |
832 |
| - xrData.rightViewMatrix = this.GLViewToUnity(view.transform.inverse.matrix); |
| 812 | + xrData.rightProjectionMatrix = view.projectionMatrix; |
| 813 | + xrData.rightViewMatrix = view.transform.matrix; |
| 814 | + xrData.rightViewMatrix[6] *= -1; |
| 815 | + xrData.rightViewMatrix[8] *= -1; |
| 816 | + xrData.rightViewMatrix[9] *= -1; |
| 817 | + xrData.rightViewMatrix[14] *= -1; |
833 | 818 | }
|
834 | 819 | }
|
835 | 820 |
|
|
878 | 863 | leftProjectionMatrix: xrData.leftProjectionMatrix,
|
879 | 864 | rightProjectionMatrix: xrData.rightProjectionMatrix,
|
880 | 865 | leftViewMatrix: xrData.leftViewMatrix,
|
881 |
| - rightViewMatrix: xrData.rightViewMatrix, |
882 |
| - sitStandMatrix: xrData.sitStandMatrix |
| 866 | + rightViewMatrix: xrData.rightViewMatrix |
883 | 867 | }}));
|
884 | 868 |
|
885 | 869 | document.dispatchEvent(new CustomEvent('XRControllersData', { detail: {
|
|
0 commit comments