|
@@ -3,6 +3,7 @@ module BABYLON {
|
|
|
export class DeviceOrientationCamera extends FreeCamera {
|
|
|
|
|
|
private _initialQuaternion: Quaternion;
|
|
|
+ private _quaternionCache: Quaternion;
|
|
|
|
|
|
constructor(name: string, position: Vector3, scene: Scene) {
|
|
|
super(name, position, scene);
|
|
@@ -15,24 +16,27 @@ module BABYLON {
|
|
|
|
|
|
public _checkInputs(): void {
|
|
|
super._checkInputs();
|
|
|
- if(this._initialQuaternion) {
|
|
|
+ if (this._initialQuaternion) {
|
|
|
+ this._quaternionCache.copyFrom(this.rotationQuaternion);
|
|
|
this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public resetToCurrentRotation(axis: BABYLON.Vector3 = BABYLON.Axis.Y) {
|
|
|
+ public resetToCurrentRotation(axis: BABYLON.Axis = BABYLON.Axis.Y) {
|
|
|
//can only work if this camera has a rotation quaternion already.
|
|
|
if (!this.rotationQuaternion) return;
|
|
|
|
|
|
if (!this._initialQuaternion) {
|
|
|
this._initialQuaternion = new BABYLON.Quaternion();
|
|
|
- } else {
|
|
|
- this._initialQuaternion.copyFrom(this.rotationQuaternion);
|
|
|
}
|
|
|
|
|
|
- ['x', 'y', 'z'].forEach(function (axisName) {
|
|
|
+ this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);
|
|
|
+
|
|
|
+ ['x', 'y', 'z'].forEach((axisName) => {
|
|
|
if (!axis[axisName]) {
|
|
|
this._initialQuaternion[axisName] = 0;
|
|
|
+ } else {
|
|
|
+ this._initialQuaternion[axisName] *= -1;
|
|
|
}
|
|
|
});
|
|
|
this._initialQuaternion.normalize();
|