|
@@ -39,7 +39,7 @@ module BABYLON {
|
|
public rawPose: DevicePose; //GamepadPose;
|
|
public rawPose: DevicePose; //GamepadPose;
|
|
|
|
|
|
private _mesh: AbstractMesh; // a node that will be attached to this Gamepad
|
|
private _mesh: AbstractMesh; // a node that will be attached to this Gamepad
|
|
- private _poseControlledCamera: PoseControlled;
|
|
|
|
|
|
+ private _poseControlledCamera: TargetCamera;
|
|
|
|
|
|
constructor(public vrGamepad) {
|
|
constructor(public vrGamepad) {
|
|
super(vrGamepad.id, vrGamepad.index, vrGamepad);
|
|
super(vrGamepad.id, vrGamepad.index, vrGamepad);
|
|
@@ -57,11 +57,11 @@ module BABYLON {
|
|
public update() {
|
|
public update() {
|
|
super.update();
|
|
super.update();
|
|
// update this device's offset position from the attached camera, if provided
|
|
// update this device's offset position from the attached camera, if provided
|
|
- if (this._poseControlledCamera && this._poseControlledCamera.deviceScaleFactor) {
|
|
|
|
- //this.position.copyFrom(this._poseControlledCamera.position);
|
|
|
|
- //this.rotationQuaternion.copyFrom(this._poseControlledCamera.rotationQuaternion);
|
|
|
|
- this.deviceScaleFactor = this._poseControlledCamera.deviceScaleFactor;
|
|
|
|
- }
|
|
|
|
|
|
+ //if (this._poseControlledCamera && this._poseControlledCamera.deviceScaleFactor) {
|
|
|
|
+ //this.position.copyFrom(this._poseControlledCamera.position);
|
|
|
|
+ //this.rotationQuaternion.copyFrom(this._poseControlledCamera.rotationQuaternion);
|
|
|
|
+ //this.deviceScaleFactor = this._poseControlledCamera.deviceScaleFactor;
|
|
|
|
+ //}
|
|
var pose: GamepadPose = this.vrGamepad.pose;
|
|
var pose: GamepadPose = this.vrGamepad.pose;
|
|
this.updateFromDevice(pose);
|
|
this.updateFromDevice(pose);
|
|
|
|
|
|
@@ -84,10 +84,10 @@ module BABYLON {
|
|
this._calculatedPosition.addInPlace(this.position);
|
|
this._calculatedPosition.addInPlace(this.position);
|
|
|
|
|
|
// scale the position using the scale factor, add the device's position
|
|
// scale the position using the scale factor, add the device's position
|
|
- if (this._poseControlledCamera) {
|
|
|
|
|
|
+ /*if (this._poseControlledCamera) {
|
|
// this allows total positioning freedom - the device, the camera and the mesh can be individually controlled.
|
|
// this allows total positioning freedom - the device, the camera and the mesh can be individually controlled.
|
|
this._calculatedPosition.addInPlace(this._poseControlledCamera.position);
|
|
this._calculatedPosition.addInPlace(this._poseControlledCamera.position);
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
}
|
|
}
|
|
if (poseData.orientation) {
|
|
if (poseData.orientation) {
|
|
this.deviceRotationQuaternion.copyFromFloats(this.rawPose.orientation[0], this.rawPose.orientation[1], -this.rawPose.orientation[2], -this.rawPose.orientation[3]);
|
|
this.deviceRotationQuaternion.copyFromFloats(this.rawPose.orientation[0], this.rawPose.orientation[1], -this.rawPose.orientation[2], -this.rawPose.orientation[3]);
|
|
@@ -99,7 +99,22 @@ module BABYLON {
|
|
// if the camera is set, rotate to the camera's rotation
|
|
// if the camera is set, rotate to the camera's rotation
|
|
this.rotationQuaternion.multiplyToRef(this.deviceRotationQuaternion, this._calculatedRotation);
|
|
this.rotationQuaternion.multiplyToRef(this.deviceRotationQuaternion, this._calculatedRotation);
|
|
if (this._poseControlledCamera) {
|
|
if (this._poseControlledCamera) {
|
|
- this._calculatedRotation.multiplyToRef(this._poseControlledCamera.rotationQuaternion, this._calculatedRotation);
|
|
|
|
|
|
+
|
|
|
|
+ Matrix.ScalingToRef(1, 1, 1, Tmp.Matrix[1]);
|
|
|
|
+ this._calculatedRotation.toRotationMatrix(Tmp.Matrix[0]);
|
|
|
|
+ Matrix.TranslationToRef(this._calculatedPosition.x, this._calculatedPosition.y, this._calculatedPosition.z, Tmp.Matrix[2]);
|
|
|
|
+
|
|
|
|
+ //Matrix.Identity().multiplyToRef(Tmp.Matrix[1], Tmp.Matrix[4]);
|
|
|
|
+ Tmp.Matrix[1].multiplyToRef(Tmp.Matrix[0], Tmp.Matrix[5]);
|
|
|
|
+
|
|
|
|
+ this._poseControlledCamera.getWorldMatrix().getTranslationToRef(Tmp.Vector3[0])
|
|
|
|
+
|
|
|
|
+ Matrix.ComposeToRef(new Vector3(this.deviceScaleFactor, this.deviceScaleFactor, this.deviceScaleFactor), this._poseControlledCamera.rotationQuaternion, Tmp.Vector3[0], Tmp.Matrix[4]);
|
|
|
|
+ Tmp.Matrix[5].multiplyToRef(Tmp.Matrix[2], Tmp.Matrix[1]);
|
|
|
|
+
|
|
|
|
+ Tmp.Matrix[1].multiplyToRef(Tmp.Matrix[4], Tmp.Matrix[2]);
|
|
|
|
+ Tmp.Matrix[2].decompose(Tmp.Vector3[0], this._calculatedRotation, this._calculatedPosition);
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -107,15 +122,13 @@ module BABYLON {
|
|
|
|
|
|
|
|
|
|
public attachToMesh(mesh: AbstractMesh) {
|
|
public attachToMesh(mesh: AbstractMesh) {
|
|
- this._mesh = mesh;
|
|
|
|
if (!this._mesh.rotationQuaternion) {
|
|
if (!this._mesh.rotationQuaternion) {
|
|
this._mesh.rotationQuaternion = new Quaternion();
|
|
this._mesh.rotationQuaternion = new Quaternion();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public attachToPoseControlledCamera(camera: PoseControlled) {
|
|
|
|
|
|
+ public attachToPoseControlledCamera(camera: TargetCamera) {
|
|
this._poseControlledCamera = camera;
|
|
this._poseControlledCamera = camera;
|
|
- this.deviceScaleFactor = camera.deviceScaleFactor;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public detachMesh() {
|
|
public detachMesh() {
|