Skip to content

Commit 8abe6e6

Browse files
authored
Merge pull request #112 from De-Panther/camera_enhancments
Camera enhancments
2 parents 2a7a1d4 + 0fbeeb6 commit 8abe6e6

33 files changed

+234
-1443
lines changed

Build/Build/Build.data.unityweb

-1.01 KB
Binary file not shown.

Build/Build/Build.wasm

-20.5 KB
Binary file not shown.

Build/Build/Build.wasm.framework.unityweb

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Build/gl-matrix-min.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

Build/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
document.dispatchEvent(new CustomEvent('toggleVR', {}));
5151
}, false);
5252
</script>
53-
<script src="gl-matrix-min.js"></script>
5453
<script src="webxr.js"></script>
5554
</body>
5655
</html>

Build/index_ml1.html

Lines changed: 0 additions & 56 deletions
This file was deleted.

Build/webxr.js

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22
'use strict';
33

44
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];
1021
this.gamepads = [];
1122
this.controllerA = new XRControllerData();
1223
this.controllerB = new XRControllerData();
@@ -542,7 +553,6 @@
542553
JSON.stringify({
543554
canPresentAR: this.isARSupported,
544555
canPresentVR: this.isVRSupported,
545-
hasPosition: true, // TODO: check this
546556
hasExternalDisplay: false // TODO: check this
547557
})
548558
);
@@ -715,39 +725,6 @@
715725
}
716726
}
717727

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-
751728
XRManager.prototype.onSessionStarted = function (session) {
752729
let glLayer = new XRWebGLLayer(session, this.ctx);
753730
session.updateRenderState({ baseLayer: glLayer });
@@ -825,11 +802,19 @@
825802

826803
for (let view of pose.views) {
827804
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;
830811
} 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;
833818
}
834819
}
835820

@@ -878,8 +863,7 @@
878863
leftProjectionMatrix: xrData.leftProjectionMatrix,
879864
rightProjectionMatrix: xrData.rightProjectionMatrix,
880865
leftViewMatrix: xrData.leftViewMatrix,
881-
rightViewMatrix: xrData.rightViewMatrix,
882-
sitStandMatrix: xrData.sitStandMatrix
866+
rightViewMatrix: xrData.rightViewMatrix
883867
}}));
884868

885869
document.dispatchEvent(new CustomEvent('XRControllersData', { detail: {

0 commit comments

Comments
 (0)