|
@@ -23,9 +23,14 @@ module BABYLON {
|
|
|
|
|
|
private _quaternionCache: Quaternion;
|
|
|
|
|
|
+ private _positionOffset: Vector3;
|
|
|
+
|
|
|
constructor(name: string, position: Vector3, scene: Scene, compensateDistortion = false, private webVROptions: WebVROptions = {}) {
|
|
|
super(name, position, scene);
|
|
|
|
|
|
+ //using the position provided as the current position offset
|
|
|
+ this._positionOffset = position;
|
|
|
+
|
|
|
//enable VR
|
|
|
this.getEngine().initWebVR();
|
|
|
|
|
@@ -81,7 +86,10 @@ module BABYLON {
|
|
|
this.rotationQuaternion.copyFromFloats(this._cacheState.orientation[0], this._cacheState.orientation[1], -this._cacheState.orientation[2], -this._cacheState.orientation[3]);
|
|
|
if (this.webVROptions.trackPosition && this._cacheState.position) {
|
|
|
this.position.copyFromFloats(this._cacheState.position[0], this._cacheState.position[1], -this._cacheState.position[2]);
|
|
|
- this.webVROptions.positionScale && this.position.scaleInPlace(this.webVROptions.positionScale)
|
|
|
+ //scale the position accordingly
|
|
|
+ this.webVROptions.positionScale && this.position.scaleInPlace(this.webVROptions.positionScale);
|
|
|
+ //add the position offset
|
|
|
+ this.position.addInPlace(this._positionOffset);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -122,6 +130,23 @@ module BABYLON {
|
|
|
//pitch and roll won't be affected.
|
|
|
this._vrDevice.resetPose();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * Set the position offset of the VR camera
|
|
|
+ * The offset will be added to the WebVR pose, after scaling it (if set).
|
|
|
+ *
|
|
|
+ * @param {Vector3} [newPosition] an optional new position. if not provided, the current camera position will be used.
|
|
|
+ *
|
|
|
+ * @memberOf WebVRFreeCamera
|
|
|
+ */
|
|
|
+ public setPositionOffset(newPosition?: Vector3) {
|
|
|
+ if(newPosition) {
|
|
|
+ this._positionOffset = newPosition;
|
|
|
+ } else {
|
|
|
+ this._positionOffset.copyFrom(this.position);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|