Browse Source

Some fixes for oculus

Deltakosh 11 years ago
parent
commit
4c60a10888

+ 2 - 6
Babylon/Cameras/Controllers/babylon.globalAxisFactorsFilter.js

@@ -9,20 +9,16 @@ var BABYLON = BABYLON || {};
 		this.yFactor = yFactor;
 		this.zFactor = zFactor;
 
-		this._localToGlobalMatrix = new BABYLON.Matrix();
-		this._globalToLocalMatrix = new BABYLON.Matrix();
 		this._globalMovement = new BABYLON.Vector3(0, 0, 0);
 	};
 	BABYLON.globalAxisFactorsFilter.prototype = Object.create(BABYLON.inputFilter.prototype);
 	BABYLON.globalAxisFactorsFilter.prototype.moveRelative = function (relativeMovement) {
 		var orientation = this.getOrientation();
-		BABYLON.Matrix.RotationYawPitchRollToRef(orientation.yaw, orientation.pitch, orientation.roll, this._localToGlobalMatrix);
-		this._localToGlobalMatrix.invertToRef(this._globalToLocalMatrix);
-		BABYLON.Vector3.TransformNormalToRef(relativeMovement, this._localToGlobalMatrix, this._globalMovement);
+		BABYLON.Vector3.TransformNormalToRef(relativeMovement, this.getOrientationMatrix(), this._globalMovement);
 		this._globalMovement.x *= this.xFactor;
 		this._globalMovement.y *= this.yFactor;
 		this._globalMovement.z *= this.zFactor;
-		BABYLON.Vector3.TransformNormalToRef(this._globalMovement, this._globalToLocalMatrix, relativeMovement);
+		BABYLON.Vector3.TransformNormalToRef(this._globalMovement, this.getInvertOrientationMatrix(), relativeMovement);
 		this.target.moveRelative(relativeMovement);
 	};
 })();

+ 2 - 6
Babylon/Cameras/Controllers/babylon.gravityInputController.js

@@ -5,20 +5,16 @@ var BABYLON = BABYLON || {};
 (function () {
     BABYLON.GravityInputController = function (scene, target) {
         BABYLON.inputController.call(this, scene, target);
-        this._fallSpeed = 1; // 1 meters per second
         this._moveVectorGlobal = new BABYLON.Vector3(0, 0, 0);
         this._moveVectorLocal = new BABYLON.Vector3(0, 0, 0);
-        this._invertMatrix = new BABYLON.Matrix();
+        this._fallSpeed = .6;
     };
     BABYLON.GravityInputController.prototype = Object.create(BABYLON.inputController.prototype);
     BABYLON.GravityInputController.prototype.update = function () {
-        var orientation = this.target.getOrientation();
-        BABYLON.Matrix.RotationYawPitchRollToRef(orientation.yaw, orientation.pitch, orientation.roll, this._invertMatrix);
-        this._invertMatrix.invert();
         this._moveVectorGlobal.x = 0;
         this._moveVectorGlobal.y = -this._fallSpeed * BABYLON.Tools.GetDeltaTime() / 1000.0;
         this._moveVectorGlobal.z = 0;
-        BABYLON.Vector3.TransformNormalToRef(this._moveVectorGlobal,this._invertMatrix, this._moveVectorLocal);
+        BABYLON.Vector3.TransformNormalToRef(this._moveVectorGlobal, this.target.getInvertOrientationMatrix(), this._moveVectorLocal);
         this.target.moveRelative(this._moveVectorLocal);
     };
 })();

+ 4 - 10
Babylon/Cameras/Controllers/babylon.inputCollisionFilter.js

@@ -5,8 +5,6 @@ var BABYLON = BABYLON || {};
 (function () {
 	BABYLON.inputCollisionFilter = function (scene, target, ellipsoid) {
 		BABYLON.inputFilter.call(this, scene, target);
-		this._orientationMatrix = new BABYLON.Matrix();
-		this._orientationMatrixInvert = new BABYLON.Matrix();
 		this._transformedDirection = new BABYLON.Vector3();
 		this._tempNewPosition = new BABYLON.Vector3();
 		this._tempNewPosition2 = new BABYLON.Vector3();
@@ -19,8 +17,7 @@ var BABYLON = BABYLON || {};
 	BABYLON.inputCollisionFilter.prototype = Object.create(BABYLON.inputFilter.prototype);
 	BABYLON.inputCollisionFilter.prototype.moveRelative = function (relativeMovement) {
 		var rotation = this.getOrientation();
-		BABYLON.Matrix.RotationYawPitchRollToRef(rotation.yaw, rotation.pitch, rotation.roll, this._orientationMatrix);
-		BABYLON.Vector3.TransformNormalToRef(relativeMovement, this._orientationMatrix, this._transformedDirection);
+		BABYLON.Vector3.TransformNormalToRef(relativeMovement, this.getOrientationMatrix(), this._transformedDirection);
 		this.getPosition().addToRef(this._transformedDirection, this._tempNewPosition);
 		//this._tempNewPosition.y -= this._ellipsoid.y;
 		this._collider.radius = this._ellipsoid;
@@ -34,14 +31,11 @@ var BABYLON = BABYLON || {};
 
 
 		this._collidedPosition.subtractToRef(this._positionBottom, this._tempNewPosition2);
+		if (this._tempNewPosition2.length() > BABYLON.Engine.collisionsEpsilon * 5) {
 
-		if (this._tempNewPosition2.length() > BABYLON.Engine.collisionsEpsilon) {
-
-		    this._orientationMatrix.invertToRef(this._orientationMatrixInvert);
-		    BABYLON.Vector3.TransformNormalToRef(this._tempNewPosition2, this._orientationMatrixInvert, this._tempNewPosition);
-
+		    BABYLON.Vector3.TransformNormalToRef(this._tempNewPosition2, this.getInvertOrientationMatrix(), this._tempNewPosition);
 		    this.target.moveRelative(this._tempNewPosition);
-		}
+		} 
 
 	};
 })();

+ 9 - 0
Babylon/Cameras/Controllers/babylon.inputController.js

@@ -22,6 +22,8 @@ var BABYLON = BABYLON || {};
 	BABYLON.inputControllerTarget.prototype.rotateRelative = function (relativeOrientation) {
 
 	};
+	BABYLON.inputControllerTarget.prototype.getOrientationMatrix = function () { return new BABYLON.Matrix(); };
+	BABYLON.inputControllerTarget.prototype.getInvertOrientationMatrix = function () { return new BABYLON.Matrix(); };
 
 	BABYLON.inputControllerMultiTarget = function (targets) {
 	    this.targets = targets;
@@ -39,6 +41,11 @@ var BABYLON = BABYLON || {};
 	BABYLON.inputControllerMultiTarget.prototype.getOrientation = function () {
 		return this.targets[0].getOrientation();
 	};
+
+
+	BABYLON.inputControllerMultiTarget.prototype.getOrientationMatrix = function () { return this.targets[0].getOrientationMatrix(); };
+	BABYLON.inputControllerMultiTarget.prototype.getInvertOrientationMatrix = function () { return this.targets[0].getInvertOrientationMatrix(); };
+
 	BABYLON.inputControllerMultiTarget.prototype.moveRelative = function (movementVector) {
 		for (var i = 0; i < this.targets.length; ++i) {
 			this.targets[i].moveRelative(movementVector);
@@ -100,6 +107,8 @@ var BABYLON = BABYLON || {};
 	BABYLON.inputFilter.prototype.getOrientation = function () {
 	    return this.target.getOrientation();
 	};
+	BABYLON.inputFilter.prototype.getOrientationMatrix = function () { return this.target.getOrientationMatrix(); };
+	BABYLON.inputFilter.prototype.getInvertOrientationMatrix = function () { return this.target.getInvertOrientationMatrix(); };
 	BABYLON.inputFilter.prototype.moveRelative = function (movementVector) {
 	    this.target.moveRelative(movementVector);
 	};

+ 0 - 134
Babylon/Cameras/babylon.oculusCamera.js

@@ -1,134 +0,0 @@
-"use strict";
-
-var BABYLON = BABYLON || {};
-
-(function () {
-    BABYLON.OculusController = function () {
-        this._currentOrientation = { yaw: 0, pitch: 0, roll: 0 };
-        this._deviceOrientationHandler = this.onOrientationEvent.bind(this);
-        window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-    };
-
-    BABYLON.OculusController.prototype.onOrientationEvent = function (ev) {
-        var yaw = ev.alpha / 180 * Math.PI;
-        if(!this._referenceYaw){
-            this._referenceYaw= yaw;
-        }
-        this._currentOrientation.yaw = yaw - this._referenceYaw;
-        this._currentOrientation.pitch = ev.beta / 180 * Math.PI;
-        this._currentOrientation.roll = ev.gamma / 180 * Math.PI;
-    };
-    BABYLON.OculusController.prototype.dispose = function () {
-        window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
-    };
-
-    BABYLON.OculusController.prototype.getCurrentOrientation = function () {
-        return this._currentOrientation;
-    };
-
-    BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric = {
-        HResolution: 1280,
-        VResolution: 800,
-        HScreenSize: 0.149759993,
-        VScreenSize: 0.0935999975,
-        VScreenCenter: 0.0467999987,
-        EyeToScreenDistance: 0.0410000011,
-        LensSeparationDistance: 0.0635000020,
-        InterpupillaryDistance: 0.0640000030,
-        DistortionK: [1.0, 0.219999999, 0.239999995, 0.0],
-        ChromaAbCorrection: [0.995999992, -0.00400000019, 1.01400006, 0.0],
-        PostProcessScaleFactor: 1.714605507808412,
-        LensCenterOffset: 0.151976421
-    };
-
-    BABYLON.OculusOrientedCamera = function (name, position, scene, controller, isLeftEye, ovrSettings, neutralOrientation) {
-        BABYLON.Camera.call(this, name, position, scene);
-        this._controller = controller;
-        this._referenceDirection = new BABYLON.Vector3(0, 0, 1);
-        this._referenceUp = new BABYLON.Vector3(0, 1, 0);
-        this._actualDirection = new BABYLON.Vector3(1, 0, 0);
-        this._actualUp = new BABYLON.Vector3(0, 1, 0);
-        this._currentTargetPoint = new BABYLON.Vector3(0, 0, 0);
-        this._currentOculusOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        this._currentViewMatrix = new BABYLON.Matrix();
-        this._currentOculusOrientationMatrix = new BABYLON.Matrix();
-        this._tempMatrix = new BABYLON.Matrix();
-        neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        this._neutralOrientation = neutralOrientation;
-        if (isLeftEye) {
-            this.viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
-        } else {
-            this.viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
-        }
-
-        this._aspectRatioAspectRatio = ovrSettings.HResolution / (2 * ovrSettings.VResolution);
-        this._aspectRatioFov = (2 * Math.atan((ovrSettings.PostProcessScaleFactor * ovrSettings.VScreenSize) / (2 * ovrSettings.EyeToScreenDistance))) ;
-        var hMeters = (ovrSettings.HScreenSize / 4) - (ovrSettings.LensSeparationDistance / 2);
-        var h = (4 * hMeters) / ovrSettings.HScreenSize;
-        this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
-
-        this._projectionMatrix = new BABYLON.Matrix();
-        this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * ovrSettings.InterpupillaryDistance : -.5 * ovrSettings.InterpupillaryDistance, 0, 0);
-        new BABYLON.oculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, ovrSettings);
-    };
-    BABYLON.OculusOrientedCamera.buildOculusStereoCamera = function (scene, name, canvas, minZ, maxZ, position, neutralOrientation, useFXAA, controller, ovrSettings) {
-        position = position || new BABYLON.Vector2(0, 0);
-        neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        controller = controller || new BABYLON.OculusController();
-        ovrSettings = ovrSettings || BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric;
-
-        var leftCamera = new BABYLON.OculusOrientedCamera(name + "_left", position, scene, controller, true, ovrSettings, neutralOrientation);
-        leftCamera.minZ = minZ;
-        leftCamera.maxZ = maxZ;
-        if (useFXAA) {
-            new BABYLON.FxaaPostProcess("fxaa_left", 1.0, leftCamera);
-        }
-
-        var rightCamera = new BABYLON.OculusOrientedCamera(name + "_right", position, scene, controller, false, ovrSettings, neutralOrientation);
-        rightCamera.minZ = minZ;
-        rightCamera.maxZ = maxZ;
-        if (useFXAA) {
-            new BABYLON.FxaaPostProcess("fxaa_right", 1.0, rightCamera);
-        }
-        scene.activeCameras = [];
-        scene.activeCameras.push(leftCamera);
-        scene.activeCameras.push(rightCamera);
-        leftCamera.attachControl(canvas);
-        rightCamera.attachControl(canvas);
-    };
-    BABYLON.OculusOrientedCamera.prototype = Object.create(BABYLON.Camera.prototype);
-
-    BABYLON.OculusOrientedCamera.prototype.getViewMatrix = function () {
-
-        BABYLON.Matrix.RotationYawPitchRollToRef(
-            this._currentOculusOrientation.yaw + this._neutralOrientation.yaw,
-            this._currentOculusOrientation.pitch + this._neutralOrientation.pitch,
-            -this._currentOculusOrientation.roll + this._neutralOrientation.roll
-            , this._currentOculusOrientationMatrix);
-
-        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceDirection, this._currentOculusOrientationMatrix, this._actualDirection);
-        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceUp, this._currentOculusOrientationMatrix, this._actualUp);
-        
-        BABYLON.Vector3.FromFloatsToRef(this.position.x + this._actualDirection.x, this.position.y + this._actualDirection.y, this.position.z + this._actualDirection.z, this._currentTargetPoint);
-        BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTargetPoint, this._actualUp, this._tempMatrix);
-        this._tempMatrix.multiplyToRef(this._preViewMatrix, this._currentViewMatrix);
-        return this._currentViewMatrix;
-    };
-
-    BABYLON.OculusOrientedCamera.prototype._update = function () {
-        if (!this._referenceOculusOrientation) {
-            this._referenceOculusOrientation = { yaw: this._controller._currentOrientation.yaw, pitch: this._controller._currentOrientation.pitch, roll: this._controller._currentOrientation.roll };
-        }
-        else {
-            this._currentOculusOrientation.yaw = this._controller._currentOrientation.yaw - this._referenceOculusOrientation.yaw;
-            this._currentOculusOrientation.pitch = this._controller._currentOrientation.pitch - this._referenceOculusOrientation.pitch;
-            this._currentOculusOrientation.roll = this._controller._currentOrientation.roll - this._referenceOculusOrientation.roll;
-        }
-    };
-
-    BABYLON.OculusOrientedCamera.prototype.getProjectionMatrix = function (force) {
-        BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._tempMatrix);
-        this._tempMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
-        return this._projectionMatrix;
-    };
-})();

+ 10 - 0
Babylon/Cameras/babylon.oculusOrientedCamera.js

@@ -13,6 +13,7 @@ var BABYLON = BABYLON || {};
         this._currentOrientation = Object.create(neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 });
         this._currentViewMatrix = new BABYLON.Matrix();
         this._currentOrientationMatrix = new BABYLON.Matrix();
+        this._currentInvertOrientationMatrix = new BABYLON.Matrix();
         this._tempMatrix = new BABYLON.Matrix();
         
         if (isLeftEye) {
@@ -98,6 +99,7 @@ var BABYLON = BABYLON || {};
             this._currentOrientation.pitch,
             -this._currentOrientation.roll
             , this._currentOrientationMatrix);
+        this._currentOrientationMatrix.invertToRef(this._currentInvertOrientationMatrix);
 
         BABYLON.Vector3.TransformNormalToRef(this._referenceDirection, this._currentOrientationMatrix, this._actualDirection);
         BABYLON.Vector3.TransformNormalToRef(this._referenceUp, this._currentOrientationMatrix, this._actualUp);
@@ -120,6 +122,14 @@ var BABYLON = BABYLON || {};
         }
     };
 
+    BABYLON.OculusOrientedCamera.prototype.getOrientationMatrix = function () {
+        return this._currentOrientationMatrix;
+    };
+
+    BABYLON.OculusOrientedCamera.prototype.getInvertOrientationMatrix = function () {
+        return this._currentInvertOrientationMatrix;
+    };
+
     BABYLON.OculusOrientedCamera.prototype.resetProjectionMatrix = function () {
         BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._tempMatrix);
         this._tempMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);

+ 0 - 34
Babylon/Collisions/babylon.collisionPlane.js

@@ -1,34 +0,0 @@
-var BABYLON = BABYLON || {};
-
-(function () {
-    BABYLON.CollisionPlane = function (origin, normal) {
-        this.normal = normal;
-        this.origin = origin;
-
-        normal.normalize();
-
-        this.equation = [];
-        this.equation[0] = normal.x;
-        this.equation[1] = normal.y;
-        this.equation[2] = normal.z;
-        this.equation[3] = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);
-    };
-
-    // Methods
-    BABYLON.CollisionPlane.prototype.isFrontFacingTo = function (direction, epsilon) {
-        var dot = BABYLON.Vector3.Dot(this.normal, direction);
-
-        return (dot <= epsilon);
-    };
-
-    BABYLON.CollisionPlane.prototype.signedDistanceTo = function (point) {
-        return BABYLON.Vector3.Dot(point, this.normal) + this.equation[3];
-    };
-
-    // Statics
-    BABYLON.CollisionPlane.CreateFromPoints = function (p1, p2, p3) {
-        var normal = BABYLON.Vector3.Cross(p2.subtract(p1), p3.subtract(p1));
-
-        return new BABYLON.CollisionPlane(p1, normal);
-    };
-})();