applyTransformMatrix method
dynamic
applyTransformMatrix(
- dynamic transformation
- Apply a transformation matrix, to the camera and gizmos
- @param {Object} transformation Object containing matrices to apply to camera and gizmos
Implementation
applyTransformMatrix(transformation) {
if (transformation['camera'] != null) {
this
._m4_1
.copy(this._cameraMatrixState)
.premultiply(transformation['camera']);
this._m4_1.decompose(
this.camera.position, this.camera.quaternion, this.camera.scale);
this.camera.updateMatrix();
//update camera up vector
if (this._state == STATE2.ROTATE ||
this._state == STATE2.ZROTATE ||
this._state == STATE2.ANIMATION_ROTATE) {
this
.camera
.up
.copy(this._upState)
.applyQuaternion(this.camera.quaternion);
}
}
if (transformation['gizmos'] != null) {
this
._m4_1
.copy(this._gizmoMatrixState)
.premultiply(transformation['gizmos']);
this._m4_1.decompose(
this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
this._gizmos.updateMatrix();
}
if (this._state == STATE2.SCALE ||
this._state == STATE2.FOCUS ||
this._state == STATE2.ANIMATION_FOCUS) {
this._tbRadius = this.calculateTbRadius(this.camera);
if (this.adjustNearFar) {
var cameraDistance =
this.camera.position.distanceTo(this._gizmos.position);
var bb = new Box3();
bb.setFromObject(this._gizmos);
var sphere = new Sphere();
bb.getBoundingSphere(sphere);
var adjustedNearPosition =
Math.max(this._nearPos0, sphere.radius + sphere.center.length());
var regularNearPosition = cameraDistance - this._initialNear;
var minNearPos = Math.min(adjustedNearPosition, regularNearPosition);
this.camera.near = cameraDistance - minNearPos;
var adjustedFarPosition =
Math.min(this._farPos0, -sphere.radius + sphere.center.length());
var regularFarPosition = cameraDistance - this._initialFar;
var minFarPos = Math.min(adjustedFarPosition, regularFarPosition);
this.camera.far = cameraDistance - minFarPos;
this.camera.updateProjectionMatrix();
} else {
var update = false;
if (this.camera.near != this._initialNear) {
this.camera.near = this._initialNear;
update = true;
}
if (this.camera.far != this._initialFar) {
this.camera.far = this._initialFar;
update = true;
}
if (update) {
this.camera.updateProjectionMatrix();
}
}
}
}