|
@@ -7,6 +7,8 @@
|
|
@serializeAsVector3()
|
|
@serializeAsVector3()
|
|
public rotation = new Vector3(0, 0, 0);
|
|
public rotation = new Vector3(0, 0, 0);
|
|
|
|
|
|
|
|
+ public rotationQuaternion: Quaternion;
|
|
|
|
+
|
|
@serialize()
|
|
@serialize()
|
|
public speed = 2.0;
|
|
public speed = 2.0;
|
|
|
|
|
|
@@ -23,6 +25,7 @@
|
|
private _rigCamTransformMatrix: Matrix;
|
|
private _rigCamTransformMatrix: Matrix;
|
|
|
|
|
|
public _referencePoint = new Vector3(0, 0, 1);
|
|
public _referencePoint = new Vector3(0, 0, 1);
|
|
|
|
+ private _defaultUpVector = new Vector3(0, 1, 0);
|
|
public _transformedReferencePoint = Vector3.Zero();
|
|
public _transformedReferencePoint = Vector3.Zero();
|
|
public _lookAtTemp = Matrix.Zero();
|
|
public _lookAtTemp = Matrix.Zero();
|
|
public _tempMatrix = Matrix.Zero();
|
|
public _tempMatrix = Matrix.Zero();
|
|
@@ -53,6 +56,7 @@
|
|
super._initCache();
|
|
super._initCache();
|
|
this._cache.lockedTarget = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
this._cache.lockedTarget = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
this._cache.rotation = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
this._cache.rotation = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
|
|
+ this._cache.rotationQuaternion = new Quaternion(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
}
|
|
}
|
|
|
|
|
|
public _updateCache(ignoreParentClass?: boolean): void {
|
|
public _updateCache(ignoreParentClass?: boolean): void {
|
|
@@ -74,6 +78,8 @@
|
|
}
|
|
}
|
|
|
|
|
|
this._cache.rotation.copyFrom(this.rotation);
|
|
this._cache.rotation.copyFrom(this.rotation);
|
|
|
|
+ if (this.rotationQuaternion)
|
|
|
|
+ this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
|
|
}
|
|
}
|
|
|
|
|
|
// Synchronized
|
|
// Synchronized
|
|
@@ -85,7 +91,7 @@
|
|
var lockedTargetPosition = this._getLockedTargetPosition();
|
|
var lockedTargetPosition = this._getLockedTargetPosition();
|
|
|
|
|
|
return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition)
|
|
return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition)
|
|
- && this._cache.rotation.equals(this.rotation);
|
|
|
|
|
|
+ && (this.rotationQuaternion ? this.rotationQuaternion.equals(this._cache.rotationQuaternion) : this._cache.rotation.equals(this.rotation));
|
|
}
|
|
}
|
|
|
|
|
|
// Methods
|
|
// Methods
|
|
@@ -124,6 +130,10 @@
|
|
if (isNaN(this.rotation.z)) {
|
|
if (isNaN(this.rotation.z)) {
|
|
this.rotation.z = 0;
|
|
this.rotation.z = 0;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (this.rotationQuaternion) {
|
|
|
|
+ Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this.rotationQuaternion);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public getTarget(): Vector3 {
|
|
public getTarget(): Vector3 {
|
|
@@ -194,21 +204,26 @@
|
|
super._checkInputs();
|
|
super._checkInputs();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public _getViewMatrix(): Matrix {
|
|
|
|
- if (!this.lockedTarget) {
|
|
|
|
- // Compute
|
|
|
|
|
|
+ private _updateCameraRotationMatrix() {
|
|
|
|
+ if (this.rotationQuaternion) {
|
|
|
|
+ this.rotationQuaternion.toRotationMatrix(this._cameraRotationMatrix);
|
|
|
|
+ //update the up vector!
|
|
|
|
+ BABYLON.Vector3.TransformNormalToRef(this._defaultUpVector, this._cameraRotationMatrix, this.upVector);
|
|
|
|
+ } else {
|
|
|
|
+ Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
|
|
if (this.upVector.x !== 0 || this.upVector.y !== 1.0 || this.upVector.z !== 0) {
|
|
if (this.upVector.x !== 0 || this.upVector.y !== 1.0 || this.upVector.z !== 0) {
|
|
Matrix.LookAtLHToRef(Vector3.Zero(), this._referencePoint, this.upVector, this._lookAtTemp);
|
|
Matrix.LookAtLHToRef(Vector3.Zero(), this._referencePoint, this.upVector, this._lookAtTemp);
|
|
- Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix, this._tempMatrix);
|
|
this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix, this._tempMatrix);
|
|
this._lookAtTemp.invert();
|
|
this._lookAtTemp.invert();
|
|
this._tempMatrix.multiplyToRef(this._lookAtTemp, this._cameraRotationMatrix);
|
|
this._tempMatrix.multiplyToRef(this._lookAtTemp, this._cameraRotationMatrix);
|
|
- } else {
|
|
|
|
- Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
|
|
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public _getViewMatrix(): Matrix {
|
|
|
|
+ if (!this.lockedTarget) {
|
|
|
|
+ // Compute
|
|
|
|
+ this._updateCameraRotationMatrix();
|
|
|
|
|
|
Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
|
|
Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
|
|
|
|
|
|
@@ -223,10 +238,10 @@
|
|
}
|
|
}
|
|
|
|
|
|
public _getVRViewMatrix(): Matrix {
|
|
public _getVRViewMatrix(): Matrix {
|
|
- Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
|
|
|
|
|
|
+ this._updateCameraRotationMatrix();
|
|
|
|
|
|
Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
|
|
Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
|
|
- Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._cameraRigParams.vrActualUp);
|
|
|
|
|
|
+ Vector3.TransformNormalToRef(this._defaultUpVector, this._cameraRotationMatrix, this._cameraRigParams.vrActualUp);
|
|
|
|
|
|
// Computing target and final matrix
|
|
// Computing target and final matrix
|
|
this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
|
|
this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
|
|
@@ -236,7 +251,7 @@
|
|
this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._viewMatrix);
|
|
this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix, this._viewMatrix);
|
|
return this._viewMatrix;
|
|
return this._viewMatrix;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @override
|
|
* @override
|
|
* Override Camera.createRigCamera
|
|
* Override Camera.createRigCamera
|
|
@@ -245,15 +260,19 @@
|
|
if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
|
|
if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
|
|
var rigCamera = new TargetCamera(name, this.position.clone(), this.getScene());
|
|
var rigCamera = new TargetCamera(name, this.position.clone(), this.getScene());
|
|
if (this.cameraRigMode === Camera.RIG_MODE_VR) {
|
|
if (this.cameraRigMode === Camera.RIG_MODE_VR) {
|
|
|
|
+ if (!this.rotationQuaternion) {
|
|
|
|
+ this.rotationQuaternion = new Quaternion();
|
|
|
|
+ }
|
|
rigCamera._cameraRigParams = {};
|
|
rigCamera._cameraRigParams = {};
|
|
rigCamera._cameraRigParams.vrActualUp = new Vector3(0, 0, 0);
|
|
rigCamera._cameraRigParams.vrActualUp = new Vector3(0, 0, 0);
|
|
rigCamera._getViewMatrix = rigCamera._getVRViewMatrix;
|
|
rigCamera._getViewMatrix = rigCamera._getVRViewMatrix;
|
|
|
|
+ rigCamera.rotationQuaternion = new Quaternion();
|
|
}
|
|
}
|
|
return rigCamera;
|
|
return rigCamera;
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @override
|
|
* @override
|
|
* Override Camera._updateRigCameras
|
|
* Override Camera._updateRigCameras
|
|
@@ -268,20 +287,18 @@
|
|
case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
|
|
case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
|
|
case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
|
|
case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
|
|
//provisionnaly using _cameraRigParams.stereoHalfAngle instead of calculations based on _cameraRigParams.interaxialDistance:
|
|
//provisionnaly using _cameraRigParams.stereoHalfAngle instead of calculations based on _cameraRigParams.interaxialDistance:
|
|
- var leftSign = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED) ? 1 : -1;
|
|
|
|
- var rightSign = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED) ? -1 : 1;
|
|
|
|
- this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle * leftSign , camLeft.position);
|
|
|
|
|
|
+ var leftSign = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED) ? 1 : -1;
|
|
|
|
+ var rightSign = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED) ? -1 : 1;
|
|
|
|
+ this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle * leftSign, camLeft.position);
|
|
this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle * rightSign, camRight.position);
|
|
this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle * rightSign, camRight.position);
|
|
|
|
|
|
camLeft.setTarget(this.getTarget());
|
|
camLeft.setTarget(this.getTarget());
|
|
camRight.setTarget(this.getTarget());
|
|
camRight.setTarget(this.getTarget());
|
|
break;
|
|
break;
|
|
-
|
|
|
|
- case Camera.RIG_MODE_VR:
|
|
|
|
- camLeft.rotation.x = camRight.rotation.x = this.rotation.x;
|
|
|
|
- camLeft.rotation.y = camRight.rotation.y = this.rotation.y;
|
|
|
|
- camLeft.rotation.z = camRight.rotation.z = this.rotation.z;
|
|
|
|
|
|
|
|
|
|
+ case Camera.RIG_MODE_VR:
|
|
|
|
+ camLeft.rotationQuaternion.copyFrom(this.rotationQuaternion);
|
|
|
|
+ camRight.rotationQuaternion.copyFrom(this.rotationQuaternion);
|
|
camLeft.position.copyFrom(this.position);
|
|
camLeft.position.copyFrom(this.position);
|
|
camRight.position.copyFrom(this.position);
|
|
camRight.position.copyFrom(this.position);
|
|
|
|
|