|
@@ -8,6 +8,9 @@ module BABYLON {
|
|
private _cacheState = null;
|
|
private _cacheState = null;
|
|
public _vrEnabled = false;
|
|
public _vrEnabled = false;
|
|
|
|
|
|
|
|
+ private _initialQuaternion: Quaternion;
|
|
|
|
+ private _quaternionCache: Quaternion;
|
|
|
|
+
|
|
constructor(name: string, position: Vector3, scene: Scene, compensateDistortion = true, vrCameraMetrics: VRCameraMetrics = VRCameraMetrics.GetDefault()) {
|
|
constructor(name: string, position: Vector3, scene: Scene, compensateDistortion = true, vrCameraMetrics: VRCameraMetrics = VRCameraMetrics.GetDefault()) {
|
|
super(name, position, scene);
|
|
super(name, position, scene);
|
|
|
|
|
|
@@ -17,6 +20,7 @@ module BABYLON {
|
|
this._getWebVRDevices = this._getWebVRDevices.bind(this);
|
|
this._getWebVRDevices = this._getWebVRDevices.bind(this);
|
|
|
|
|
|
this.rotationQuaternion = new Quaternion();
|
|
this.rotationQuaternion = new Quaternion();
|
|
|
|
+ this._quaternionCache = new Quaternion();
|
|
}
|
|
}
|
|
|
|
|
|
private _getWebVRDevices(devices: Array<any>): void {
|
|
private _getWebVRDevices(devices: Array<any>): void {
|
|
@@ -54,6 +58,10 @@ module BABYLON {
|
|
//Flip in XY plane
|
|
//Flip in XY plane
|
|
this.rotationQuaternion.z *= -1;
|
|
this.rotationQuaternion.z *= -1;
|
|
this.rotationQuaternion.w *= -1;
|
|
this.rotationQuaternion.w *= -1;
|
|
|
|
+ if (this._initialQuaternion) {
|
|
|
|
+ this._quaternionCache.copyFrom(this.rotationQuaternion);
|
|
|
|
+ this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
super._checkInputs();
|
|
super._checkInputs();
|
|
@@ -85,6 +93,26 @@ module BABYLON {
|
|
public getTypeName(): string {
|
|
public getTypeName(): string {
|
|
return "WebVRFreeCamera";
|
|
return "WebVRFreeCamera";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|