Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/dev/core/src/Cameras/arcRotateCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,11 @@ export class ArcRotateCamera extends TargetCamera {
}

this.inputs.checkInputs();

let hasUserInteractions = false;

const inertialPanningLimit = this.speed * this._panningEpsilon;
const inertialRotationLimit = this.speed * this._rotationEpsilon;

// Inertia
if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {
hasUserInteractions = true;
Expand All @@ -1062,13 +1064,13 @@ export class ArcRotateCamera extends TargetCamera {
this.inertialAlphaOffset *= this.inertia;
this.inertialBetaOffset *= this.inertia;
this.inertialRadiusOffset *= this.inertia;
if (Math.abs(this.inertialAlphaOffset) < Epsilon) {
if (Math.abs(this.inertialAlphaOffset) < inertialRotationLimit) {
this.inertialAlphaOffset = 0;
}
if (Math.abs(this.inertialBetaOffset) < Epsilon) {
if (Math.abs(this.inertialBetaOffset) < inertialRotationLimit) {
this.inertialBetaOffset = 0;
}
if (Math.abs(this.inertialRadiusOffset) < this.speed * Epsilon) {
if (Math.abs(this.inertialRadiusOffset) < inertialRotationLimit) {
this.inertialRadiusOffset = 0;
}
}
Expand Down Expand Up @@ -1114,10 +1116,10 @@ export class ArcRotateCamera extends TargetCamera {
this.inertialPanningX *= this.panningInertia;
this.inertialPanningY *= this.panningInertia;

if (Math.abs(this.inertialPanningX) < this.speed * Epsilon) {
if (Math.abs(this.inertialPanningX) < inertialPanningLimit) {
this.inertialPanningX = 0;
}
if (Math.abs(this.inertialPanningY) < this.speed * Epsilon) {
if (Math.abs(this.inertialPanningY) < inertialPanningLimit) {
this.inertialPanningY = 0;
}
}
Expand Down
25 changes: 20 additions & 5 deletions packages/dev/core/src/Cameras/targetCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ export class TargetCamera extends Camera {
*/
public inverseRotationSpeed = 0.2;

/**
* @internal
* @experimental
* Can be used to change clamping behavior for inertia. Hook into onBeforeRenderObservable to change the value per-frame
*/
public _panningEpsilon = Epsilon;
/**
* @internal
* @experimental
* Can be used to change clamping behavior for inertia. Hook into onBeforeRenderObservable to change the value per-frame
*/
public _rotationEpsilon = Epsilon;

/**
* Define the current target of the camera as an object or a position.
* Please note that locking a target will disable panning.
Expand Down Expand Up @@ -391,28 +404,30 @@ export class TargetCamera extends Camera {
}
}

const inertialPanningLimit = this.speed * this._panningEpsilon;
const inertialRotationLimit = this.speed * this._rotationEpsilon;
// Inertia
if (needToMove) {
if (Math.abs(this.cameraDirection.x) < this.speed * Epsilon) {
if (Math.abs(this.cameraDirection.x) < inertialPanningLimit) {
this.cameraDirection.x = 0;
}

if (Math.abs(this.cameraDirection.y) < this.speed * Epsilon) {
if (Math.abs(this.cameraDirection.y) < inertialPanningLimit) {
this.cameraDirection.y = 0;
}

if (Math.abs(this.cameraDirection.z) < this.speed * Epsilon) {
if (Math.abs(this.cameraDirection.z) < inertialPanningLimit) {
this.cameraDirection.z = 0;
}

this.cameraDirection.scaleInPlace(this.inertia);
}
if (needToRotate) {
if (Math.abs(this.cameraRotation.x) < this.speed * Epsilon) {
if (Math.abs(this.cameraRotation.x) < inertialRotationLimit) {
this.cameraRotation.x = 0;
}

if (Math.abs(this.cameraRotation.y) < this.speed * Epsilon) {
if (Math.abs(this.cameraRotation.y) < inertialRotationLimit) {
this.cameraRotation.y = 0;
}
this.cameraRotation.scaleInPlace(this.inertia);
Expand Down