Ver código fonte

WebVR Fix

WebVR orientation is now working correctly.
Including full-screen mode for WebVR-enabled devices.
Tested with a DK2
Raanan Weber 9 anos atrás
pai
commit
c73150b0a8

+ 9 - 6
src/Cameras/VR/babylon.webVRCamera.ts

@@ -51,12 +51,10 @@ module BABYLON {
         public _checkInputs(): void {
             if (this._vrEnabled) {
                 this._cacheState = this._sensorDevice.getState();
-                this._cacheQuaternion.copyFromFloats(this._cacheState.orientation.x, this._cacheState.orientation.y, this._cacheState.orientation.z, this._cacheState.orientation.w);
-                this._cacheQuaternion.toEulerAnglesToRef(this._cacheRotation);
-
-                this.rotation.x = -this._cacheRotation.x;
-                this.rotation.y = -this._cacheRotation.y;
-                this.rotation.z = this._cacheRotation.z;
+                this.rotationQuaternion.copyFrom(this._cacheState.orientation);
+                //Flip in XY plane
+                this.rotationQuaternion.z *= -1;
+                this.rotationQuaternion.w *= -1;
             }
 
             super._checkInputs();
@@ -80,6 +78,11 @@ module BABYLON {
             this._vrEnabled = false;
         }
 
+        public requestVRFullscreen(requestPointerlock: boolean) {
+            if (!this._hmdDevice) return;
+            this.getEngine().switchFullscreen(requestPointerlock, { vrDisplay: this._hmdDevice })
+        }
+
         public getTypeName(): string {
             return "WebVRFreeCamera";
         }

+ 5 - 10
src/Tools/babylon.tools.ts

@@ -219,15 +219,10 @@
             }
         }
 
-        public static RequestFullscreen(element): void {
-            if (element.requestFullscreen)
-                element.requestFullscreen();
-            else if (element.msRequestFullscreen)
-                element.msRequestFullscreen();
-            else if (element.webkitRequestFullscreen)
-                element.webkitRequestFullscreen();
-            else if (element.mozRequestFullScreen)
-                element.mozRequestFullScreen();
+        public static RequestFullscreen(element, options?: any): void {
+            var requestFunction = element.requestFullscreen || element.msRequestFullscreen || element.webkitRequestFullscreen || element.mozRequestFullScreen;
+            if (!requestFunction) return;
+            requestFunction(options);
         }
 
         public static ExitFullscreen(): void {
@@ -911,7 +906,7 @@
         public static getClassName(object, isType: boolean = false): string {
             let name = null;
             if (object instanceof Object) {
-                let classObj = isType ? object :  Object.getPrototypeOf(object);
+                let classObj = isType ? object : Object.getPrototypeOf(object);
                 name = classObj.constructor["__bjsclassName__"];
             }
             if (!name) {

+ 3 - 2
src/babylon.engine.ts

@@ -689,13 +689,14 @@
         /**
          * Toggle full screen mode.
          * @param {boolean} requestPointerLock - should a pointer lock be requested from the user
+         * @param {any} options - an options object to be sent to the requestFullscreen function
          */
-        public switchFullscreen(requestPointerLock: boolean): void {
+        public switchFullscreen(requestPointerLock: boolean, options?: any): void {
             if (this.isFullscreen) {
                 Tools.ExitFullscreen();
             } else {
                 this._pointerLockRequested = requestPointerLock;
-                Tools.RequestFullscreen(this._renderingCanvas);
+                Tools.RequestFullscreen(this._renderingCanvas, options);
             }
         }