Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 11 additions & 7 deletions packages/dev/core/src/Cameras/arcRotateCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { ArcRotateCameraPointersInput } from "../Cameras/Inputs/arcRotateCa
import type { ArcRotateCameraKeyboardMoveInput } from "../Cameras/Inputs/arcRotateCameraKeyboardMoveInput";
import type { ArcRotateCameraMouseWheelInput } from "../Cameras/Inputs/arcRotateCameraMouseWheelInput";
import { ArcRotateCameraInputsManager } from "../Cameras/arcRotateCameraInputsManager";
import { Epsilon } from "../Maths/math.constants";
import { Epsilon, MsPerFrameAt60FPS } from "../Maths/math.constants";
import { Tools } from "../Misc/tools";
import { RegisterClass } from "../Misc/typeStore";

Expand Down Expand Up @@ -1040,9 +1040,13 @@ export class ArcRotateCamera extends TargetCamera {
}

this.inputs.checkInputs();

let hasUserInteractions = false;


// At 60FPS, InertialLimit should be == this.speed * Epsilon.
// We scale InertialLimit based on time since last frame to ensure a smaller inertialLimit at higher framerates
const InertialLimit = this.speed * Epsilon * this._scene.getEngine().getDeltaTime() / MsPerFrameAt60FPS;

// Inertia
if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {
hasUserInteractions = true;
Expand All @@ -1062,13 +1066,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) < InertialLimit) {
this.inertialAlphaOffset = 0;
}
if (Math.abs(this.inertialBetaOffset) < Epsilon) {
if (Math.abs(this.inertialBetaOffset) < InertialLimit) {
this.inertialBetaOffset = 0;
}
if (Math.abs(this.inertialRadiusOffset) < this.speed * Epsilon) {
if (Math.abs(this.inertialRadiusOffset) < InertialLimit) {
this.inertialRadiusOffset = 0;
}
}
Expand Down Expand Up @@ -1114,10 +1118,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) < InertialLimit) {
this.inertialPanningX = 0;
}
if (Math.abs(this.inertialPanningY) < this.speed * Epsilon) {
if (Math.abs(this.inertialPanningY) < InertialLimit) {
this.inertialPanningY = 0;
}
}
Expand Down
16 changes: 10 additions & 6 deletions packages/dev/core/src/Cameras/targetCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Nullable } from "../types";
import { Camera } from "./camera";
import type { Scene } from "../scene";
import { Quaternion, Matrix, Vector3, Vector2, TmpVectors } from "../Maths/math.vector";
import { Epsilon } from "../Maths/math.constants";
import { Epsilon, MsPerFrameAt60FPS } from "../Maths/math.constants";
import { Axis } from "../Maths/math.axis";
import type { AbstractMesh } from "../Meshes/abstractMesh";
import { Node } from "../node";
Expand Down Expand Up @@ -391,28 +391,32 @@ export class TargetCamera extends Camera {
}
}

// At 60FPS, InertialLimit should be == this.speed * Epsilon.
// We scale InertialLimit based on time since last frame to ensure a smaller inertialLimit at higher framerates
const InertialLimit = this.speed * Epsilon * this._scene.getEngine().getDeltaTime() / MsPerFrameAt60FPS;

// Inertia
if (needToMove) {
if (Math.abs(this.cameraDirection.x) < this.speed * Epsilon) {
if (Math.abs(this.cameraDirection.x) < InertialLimit) {
this.cameraDirection.x = 0;
}

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

if (Math.abs(this.cameraDirection.z) < this.speed * Epsilon) {
if (Math.abs(this.cameraDirection.z) < InertialLimit) {
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) < InertialLimit) {
this.cameraRotation.x = 0;
}

if (Math.abs(this.cameraRotation.y) < this.speed * Epsilon) {
if (Math.abs(this.cameraRotation.y) < InertialLimit) {
this.cameraRotation.y = 0;
}
this.cameraRotation.scaleInPlace(this.inertia);
Expand Down
6 changes: 6 additions & 0 deletions packages/dev/core/src/Maths/math.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ export const PHI = (1 + Math.sqrt(5)) / 2;
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export const Epsilon = 0.001;

/**
* Delta Time in milliseconds at 60 frames per second
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export const MsPerFrameAt60FPS = 1000 / 60; // 16.666... ms
Loading