Browse Source

Fixing lenses

Deltakosh 11 years ago
parent
commit
2dfacb8369

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

@@ -0,0 +1,85 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+
+	BABYLON.inputControllerTarget = function () {
+		this._position = new BABYLON.Vector3(0, 0, 0);
+		this._orientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+	};
+
+	BABYLON.inputControllerTarget.prototype.getPosition = function () {
+		return this._position;
+	};
+	BABYLON.inputControllerTarget.prototype.getOrientation = function () {
+		return this._orientation;
+	};
+	BABYLON.inputControllerTarget.prototype.moveRelative = function (movementVector) {
+
+	};
+	
+	BABYLON.inputControllerTarget.prototype.rotateRelative = function (relativeOrientation) {
+
+	};
+
+	BABYLON.inputControllerMultiTarget = function (targets) {
+	    this.targets = targets;
+	    var mainTarget = this.targets[0];
+	    if (!mainTarget.controllers) {
+	        mainTarget.controllers = [this];
+	    } else {
+	        mainTarget.controllers.push(this);
+	    }
+	};
+
+	BABYLON.inputControllerMultiTarget.prototype.getPosition = function () {
+		return this.targets[0].getPosition();
+	};
+	BABYLON.inputControllerMultiTarget.prototype.getOrientation = function () {
+		return this.targets[0].getOrientation();
+	};
+	BABYLON.inputControllerMultiTarget.prototype.moveRelative = function (movementVector) {
+		for (var i = 0; i < this.targets.length; ++i) {
+			this.targets[i].moveRelative(movementVector);
+		}
+	};
+
+	BABYLON.inputControllerMultiTarget.prototype.rotateRelative = function (relativeOrientation) {
+		for (var i = 0; i < this.targets.length; ++i) {
+			this.targets[i].rotateRelative(relativeOrientation);
+		}
+	};
+
+	BABYLON.inputControllerMultiTarget.prototype.update = function () {
+		if (this.controllers) {
+			for (var i = 0; i < this.controllers.length; ++i) {
+				this.controllers[i].update();
+			}
+		}
+	};
+	
+	BABYLON.inputController = function (scene, target) {
+		this.scene = scene;
+		this.target = target;
+		if (!this.target.controllers) {
+			this.target.controllers = [this];
+		} else {
+			this.target.controllers.push(this);
+		}
+	};
+	BABYLON.inputController.prototype.attachToCanvas = function (canvas) {
+
+	};
+	BABYLON.inputController.prototype.detachFromCanvas = function (canvas) {
+
+	};
+	BABYLON.inputController.prototype.update = function () {
+
+	};
+
+	BABYLON.inputController.prototype.dispose = function () {
+
+	};
+
+})();

+ 133 - 0
Babylon/Cameras/Controllers/babylon.keyboardMoveController.js

@@ -0,0 +1,133 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+	BABYLON.keyboardMoveController = function (scene, target) {
+		BABYLON.inputController.call(this, scene, target);
+		this._keys = [];
+		this.keysUp = [38];
+		this.keysDown = [40];
+		this.keysLeft = [37];
+		this.keysRight = [39];
+		this._currentSpeed = new BABYLON.Vector3(0, 0, 0);
+		this._lastFrameSpeed = new BABYLON.Vector3(0, 0, 0);
+		this._currentAcceleration = new BABYLON.Vector3(0, 0, 0);
+		this._tempSpeed = new BABYLON.Vector3(0, 0, 0);
+		this._tempSpeed2 = new BABYLON.Vector3(0, 0, 0);
+		this.maxAbsoluteSpeed = 2; // 2 meters per second
+		this.maxAbsoluteAcceleration = 5; // 2 meters per second²
+		this._targetSpeed = new BABYLON.Vector3(0, 0, 0);
+	};
+	BABYLON.keyboardMoveController.prototype = Object.create(BABYLON.inputController.prototype);
+	BABYLON.keyboardMoveController.prototype.attachToCanvas = function (canvas) {
+		var that = this;
+		this._canvas = canvas;
+
+		this._onKeyDown = function (evt) {
+			if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
+				that.keysDown.indexOf(evt.keyCode) !== -1 ||
+				that.keysLeft.indexOf(evt.keyCode) !== -1 ||
+				that.keysRight.indexOf(evt.keyCode) !== -1) {
+				var index = that._keys.indexOf(evt.keyCode);
+
+				if (index === -1) {
+					that._keys.push(evt.keyCode);
+				}
+			}
+		};
+
+		this._onKeyUp = function (evt) {
+			if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
+				that.keysDown.indexOf(evt.keyCode) !== -1 ||
+				that.keysLeft.indexOf(evt.keyCode) !== -1 ||
+				that.keysRight.indexOf(evt.keyCode) !== -1) {
+				var index = that._keys.indexOf(evt.keyCode);
+
+				if (index >= 0) {
+					that._keys.splice(index, 1);
+				}
+			}
+		};
+
+		this._onLostFocus = function () {
+			that._keys = [];
+		};
+
+		window.addEventListener("keydown", this._onKeyDown, false);
+		window.addEventListener("keyup", this._onKeyUp, false);
+		window.addEventListener("blur", this._onLostFocus, false);
+	};
+	BABYLON.keyboardMoveController.prototype.detachFromCanvas = function (canvas) {
+		window.removeEventListener("keydown", this._onKeyDown, false);
+		window.removeEventListener("keyup", this._onKeyUp, false);
+		window.removeEventListener("blur", this._onLostFocus, false);
+	};
+	BABYLON.keyboardMoveController.prototype.updateCurrentSpeed = function () {
+		this._lastFrameSpeed.x = this._currentSpeed.x;
+		this._lastFrameSpeed.y = this._currentSpeed.y;
+		this._lastFrameSpeed.z = this._currentSpeed.z;
+		if (this._currentSpeed.equals(this._targetSpeed)) {
+			this._currentAcceleration.x = 0;
+			this._currentAcceleration.y = 0;
+			this._currentAcceleration.z = 0;
+			return;
+		}
+		var dt = BABYLON.Tools.GetDeltaTime()/1000.0;
+		
+		var dv = this._tempSpeed;
+		this._targetSpeed.subtractToRef(this._lastFrameSpeed, dv);
+		var absoluteAccToTarget = dv.length() / dt;
+		if (absoluteAccToTarget < this.maxAbsoluteAcceleration) {
+			this._currentSpeed.x = this._targetSpeed.x;
+			this._currentSpeed.y = this._targetSpeed.y;
+			this._currentSpeed.z = this._targetSpeed.z;
+			dv.normalize();
+			dv.scaleToRef(absoluteAccToTarget, this._currentAcceleration);
+		} else {
+			dv.normalize();
+			dv.scaleToRef(this.maxAbsoluteAcceleration, this._currentAcceleration);
+			dv.scaleInPlace(this.maxAbsoluteAcceleration * dt);
+		
+			this._currentSpeed.addInPlace(dv);
+		}
+	};
+	BABYLON.keyboardMoveController.prototype.update = function () {
+		this._targetSpeed.x = 0;
+		this._targetSpeed.y = 0;
+		this._targetSpeed.z = 0;
+		// update target speed from input
+		for (var index = 0; index < this._keys.length; index++) {
+			var keyCode = this._keys[index];
+			if (this.keysLeft.indexOf(keyCode) !== -1) {
+				this._targetSpeed.x -= 1;
+			} else if (this.keysUp.indexOf(keyCode) !== -1) {
+				this._targetSpeed.z += 1;
+			} else if (this.keysRight.indexOf(keyCode) !== -1) {
+				this._targetSpeed.x += 1;
+			} else if (this.keysDown.indexOf(keyCode) !== -1) {
+				this._targetSpeed.z -= 1;
+			}
+		}
+		if (this._targetSpeed.x != 0 || this._targetSpeed.z != 0) {
+			this._targetSpeed.normalize();
+			this._targetSpeed.scaleInPlace(this.maxAbsoluteSpeed);
+		}
+
+		this.updateCurrentSpeed();
+
+		if (this._lastFrameSpeed.x == 0 && this._lastFrameSpeed.z == 0 && this._currentAcceleration.x == 0 && this._currentAcceleration.z == 0) {
+			return;
+		}
+
+		// dv = (dt * v0) + 1/2 * dt² * a
+
+		var dt = BABYLON.Tools.GetDeltaTime() / 1000.0;
+		this._lastFrameSpeed.scaleToRef(dt, this._tempSpeed);
+		this._currentAcceleration.scaleToRef(dt * dt * 0.5, this._tempSpeed2);
+		this._tempSpeed.addInPlace(this._tempSpeed2);
+		if (this._tempSpeed.x != 0 || this._tempSpeed.z != 0) {
+			this.target.moveRelative(this._tempSpeed);
+		}
+	};
+})();

+ 150 - 0
Babylon/Cameras/Controllers/babylon.oculusController.js

@@ -0,0 +1,150 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.OculusOrientedCamera = function (name, position, scene, isLeftEye, ovrSettings, neutralOrientation) {
+        BABYLON.Camera.call(this, name, position, scene);
+        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._currentOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        this._currentViewMatrix = new BABYLON.Matrix();
+        this._currentOrientationMatrix = new BABYLON.Matrix();
+        this._tempMatrix = new BABYLON.Matrix();
+        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);
+        this.resetProjectionMatrix();
+        this.resetViewMatrix();
+    };
+    
+    BABYLON.OculusOrientedCamera.buildOculusStereoCamera = function (scene, name, canvas, minZ, maxZ, position, neutralOrientation, useFXAA, ovrSettings) {
+        position = position || new BABYLON.Vector2(0, 0);
+        neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        //var controller =  new BABYLON.OculusController();
+        ovrSettings = ovrSettings || BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric;
+
+        var leftCamera = new BABYLON.OculusOrientedCamera(name + "_left", position, scene, 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, 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);
+        var multiTarget = new BABYLON.inputControllerMultiTarget([leftCamera, rightCamera]);
+        var controller = new BABYLON.OculusController(scene, multiTarget);
+        var moveController = new BABYLON.keyboardMoveController(scene, multiTarget);
+        moveController.attachToCanvas(canvas);
+        var result = {
+            leftCamera: leftCamera, rightCamera: rightCamera, intermediateControllerTarget: multiTarget,
+            oculusController: controller,
+            keyboardController: moveController
+        };
+        result.dispose = function () {
+            this.leftCamera.detachControl(canvas);
+            this.rightCamera.detachControl(canvas);
+            this.leftCamera.dispose();
+            this.rightCamera.dispose();
+            this.oculusController.dispose();
+            this.keyboardController.detachFromCanvas(canvas);
+            this.keyboardController.dispose();
+        }.bind(result);
+        return result;
+    };
+    
+    BABYLON.OculusOrientedCamera.prototype = Object.create(BABYLON.Camera.prototype);
+
+    BABYLON.OculusOrientedCamera.prototype.resetViewMatrix = function () {
+        BABYLON.Matrix.RotationYawPitchRollToRef(
+            this._currentOrientation.yaw,
+            this._currentOrientation.pitch,
+            -this._currentOrientation.roll
+            , this._currentOrientationMatrix);
+
+        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceDirection, this._currentOrientationMatrix, this._actualDirection);
+        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceUp, this._currentOrientationMatrix, 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.getViewMatrix = function () {
+
+        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._currentOrientation.yaw = this._controller._currentOrientation.yaw - this._referenceOculusOrientation.yaw;
+        //    this._currentOrientation.pitch = this._controller._currentOrientation.pitch - this._referenceOculusOrientation.pitch;
+        //    this._currentOrientation.roll = this._controller._currentOrientation.roll - this._referenceOculusOrientation.roll;
+        //}
+        if (this.controllers) {
+            for (var i = 0; i < this.controllers.length; ++i) {
+                this.controllers[i].update();
+            }
+        }
+    };
+
+    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);
+        return this._projectionMatrix;
+    };
+
+    BABYLON.OculusOrientedCamera.prototype.getProjectionMatrix = function (force) {
+        return this._projectionMatrix;
+    };
+
+    // implementation of inputControllerTarget
+    BABYLON.OculusOrientedCamera.prototype.getOrientation = function () {
+        return this._currentOrientation;
+    };
+    BABYLON.OculusOrientedCamera.prototype.getPosition = function () {
+        return this.position;
+    };
+    BABYLON.OculusOrientedCamera.prototype.moveRelative = function (movementVector) {
+        if (!this._tempMoveVector) {
+            this._tempMoveVector = new BABYLON.Vector3(0, 0, 0);
+        }
+        BABYLON.Vector3.TransformCoordinatesToRef(movementVector, this._currentOrientationMatrix, this._tempMoveVector);
+        this.position.addInPlace(this._tempMoveVector);
+        this.resetViewMatrix();
+    };
+    BABYLON.OculusOrientedCamera.prototype.rotateRelative = function (rotation) {
+        this._currentOrientation.yaw += rotation.yaw;
+        this._currentOrientation.pitch += rotation.pitch;
+        this._currentOrientation.roll += rotation.roll;
+        this.resetViewMatrix();
+    };
+})();

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

@@ -0,0 +1,198 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.OculusController = function (scene, target) {
+        BABYLON.inputController.call(this, scene, target);
+        this._deviceOrientationHandler = this.onOrientationEvent.bind(this);
+        this._tempOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        this._relativeOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        window.addEventListener("deviceorientation", this._deviceOrientationHandler);
+    };
+
+    BABYLON.OculusController.prototype = Object.create(BABYLON.inputController.prototype);
+
+    BABYLON.OculusController.prototype.onOrientationEvent = function (ev) {
+        this._tempOrientation.yaw = ev.alpha / 180 * Math.PI;
+        this._tempOrientation.pitch = ev.beta / 180 * Math.PI;
+        this._tempOrientation.roll = ev.gamma / 180 * Math.PI;
+
+        if (!this._lastOrientation) {
+            this._lastOrientation = Object.create(this._tempOrientation);
+        }
+        else {
+            this._relativeOrientation.yaw = this._tempOrientation.yaw - this._lastOrientation.yaw;
+            this._relativeOrientation.pitch = this._tempOrientation.pitch - this._lastOrientation.pitch;
+            this._relativeOrientation.roll = this._tempOrientation.roll - this._lastOrientation.roll;
+
+            var temp = this._tempOrientation;
+            this._tempOrientation = this._lastOrientation;
+            this._lastOrientation = temp;
+            this.target.rotateRelative(this._relativeOrientation);
+        }
+    };
+    BABYLON.OculusController.prototype.dispose = function () {
+        window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
+    };
+
+    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, isLeftEye, ovrSettings, neutralOrientation) {
+        BABYLON.Camera.call(this, name, position, scene);
+        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._currentOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        this._currentViewMatrix = new BABYLON.Matrix();
+        this._currentOrientationMatrix = new BABYLON.Matrix();
+        this._tempMatrix = new BABYLON.Matrix();
+        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);
+        this.resetProjectionMatrix();
+        this.resetViewMatrix();
+    };
+    
+    BABYLON.OculusOrientedCamera.buildOculusStereoCamera = function (scene, name, canvas, minZ, maxZ, position, neutralOrientation, useFXAA, ovrSettings) {
+        position = position || new BABYLON.Vector2(0, 0);
+        neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        //var controller =  new BABYLON.OculusController();
+        ovrSettings = ovrSettings || BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric;
+
+        var leftCamera = new BABYLON.OculusOrientedCamera(name + "_left", position, scene, 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, 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);
+        var multiTarget = new BABYLON.inputControllerMultiTarget([leftCamera, rightCamera]);
+        var controller = new BABYLON.OculusController(scene, multiTarget);
+        var moveController = new BABYLON.keyboardMoveController(scene, multiTarget);
+        moveController.attachToCanvas(canvas);
+        var result = {
+            leftCamera: leftCamera, rightCamera: rightCamera, intermediateControllerTarget: multiTarget,
+            oculusController: controller,
+            keyboardController: moveController
+        };
+        result.dispose = function () {
+            this.leftCamera.detachControl(canvas);
+            this.rightCamera.detachControl(canvas);
+            this.leftCamera.dispose();
+            this.rightCamera.dispose();
+            this.oculusController.dispose();
+            this.keyboardController.detachFromCanvas(canvas);
+            this.keyboardController.dispose();
+        }.bind(result);
+        return result;
+    };
+    
+    BABYLON.OculusOrientedCamera.prototype = Object.create(BABYLON.Camera.prototype);
+
+    BABYLON.OculusOrientedCamera.prototype.resetViewMatrix = function () {
+        BABYLON.Matrix.RotationYawPitchRollToRef(
+            this._currentOrientation.yaw,
+            this._currentOrientation.pitch,
+            -this._currentOrientation.roll
+            , this._currentOrientationMatrix);
+
+        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceDirection, this._currentOrientationMatrix, this._actualDirection);
+        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceUp, this._currentOrientationMatrix, 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.getViewMatrix = function () {
+
+        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._currentOrientation.yaw = this._controller._currentOrientation.yaw - this._referenceOculusOrientation.yaw;
+        //    this._currentOrientation.pitch = this._controller._currentOrientation.pitch - this._referenceOculusOrientation.pitch;
+        //    this._currentOrientation.roll = this._controller._currentOrientation.roll - this._referenceOculusOrientation.roll;
+        //}
+        if (this.controllers) {
+            for (var i = 0; i < this.controllers.length; ++i) {
+                this.controllers[i].update();
+            }
+        }
+    };
+
+    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);
+        return this._projectionMatrix;
+    };
+
+    BABYLON.OculusOrientedCamera.prototype.getProjectionMatrix = function (force) {
+        return this._projectionMatrix;
+    };
+
+    // implementation of inputControllerTarget
+    BABYLON.OculusOrientedCamera.prototype.getOrientation = function () {
+        return this._currentOrientation;
+    };
+    BABYLON.OculusOrientedCamera.prototype.getPosition = function () {
+        return this.position;
+    };
+    BABYLON.OculusOrientedCamera.prototype.moveRelative = function (movementVector) {
+        if (!this._tempMoveVector) {
+            this._tempMoveVector = new BABYLON.Vector3(0, 0, 0);
+        }
+        BABYLON.Vector3.TransformCoordinatesToRef(movementVector, this._currentOrientationMatrix, this._tempMoveVector);
+        this.position.addInPlace(this._tempMoveVector);
+        this.resetViewMatrix();
+    };
+    BABYLON.OculusOrientedCamera.prototype.rotateRelative = function (rotation) {
+        this._currentOrientation.yaw += rotation.yaw;
+        this._currentOrientation.pitch += rotation.pitch;
+        this._currentOrientation.roll += rotation.roll;
+        this.resetViewMatrix();
+    };
+})();

+ 1 - 1
Babylon/LensFlare/babylon.lensFlareSystem.js

@@ -164,7 +164,7 @@ var BABYLON = BABYLON || {};
             var y = centerY - (distY * flare.position);
             
             var cw = flare.size;
-            var ch = flare.size * engine.getAspectRatio();
+            var ch = flare.size * engine.getAspectRatio(this._scene.activeCamera);
             var cx = 2 * (x / globalViewport.width) - 1.0;
             var cy = 1.0 - 2 * (y / globalViewport.height);
             

+ 5 - 2
Babylon/babylon.engine.js

@@ -3,12 +3,15 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.Engine = function (canvas, antialias) {
+    BABYLON.Engine = function (canvas, antialias, options) {
         this._renderingCanvas = canvas;
 
+        options = options || {};
+        options.antialias = antialias;
+
         // GL
         try {
-            this._gl = canvas.getContext("webgl", { antialias: antialias }) || canvas.getContext("experimental-webgl", { antialias: antialias });
+            this._gl = canvas.getContext("webgl", options) || canvas.getContext("experimental-webgl", options);
         } catch (e) {
             throw new Error("WebGL not supported");
         }

+ 4 - 1
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/babylonJS.xml

@@ -1,9 +1,12 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <files xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="babylonJS.xsd">
+  <script src="Babylon/Cameras/Controllers/babylon.inputController.js"></script>
   <script src="Babylon/PostProcess/babylon.oculusDistortionCorrectionPostProcess.js"></script>
   <script src="Babylon/Tools/babylon.virtualJoystick.js"></script>
-  <script src="Babylon/Cameras/babylon.oculusCamera.js"></script>
+  <script src="Babylon/Cameras/Controllers/babylon.oculusController.js"></script>
+  <script src="Babylon/Cameras/babylon.oculusOrientedCamera.js"></script>
   <script src="Babylon/Cameras/babylon.virtualJoysticksCamera.js"></script>
+  <script src="Babylon/Cameras/Controllers/babylon.keyboardMoveController.js"></script>
   <script src="Babylon/Mesh/babylon.csg.js"></script>
   <script src="Babylon/Tools/babylon.sceneSerializer.js"></script>
   <script src="Babylon/Physics/babylon.physicsEngine.js"></script>

File diff suppressed because it is too large
+ 2 - 2
babylon.1.9.0.js