Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArcRotateCamera: Modify offset math to correctly zoom to point #14209

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
private _wheel: Nullable<(p: PointerInfo, s: EventState) => void>;
private _observer: Nullable<Observer<PointerInfo>>;
private _hitPlane: Nullable<Plane>;
private _viewOffset: Vector3 = new Vector3(0, 0, 0);
private _globalOffset: Vector3 = new Vector3(0, 0, 0);

protected _computeDeltaFromMouseWheelLegacyEvent(mouseWheelDelta: number, radius: number) {
let delta = 0;
Expand Down Expand Up @@ -210,8 +212,14 @@ export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCam
// a vector defining where we want to zoom to.
const ray = scene.createPickingRay(scene.pointerX, scene.pointerY, Matrix.Identity(), camera, false);
// Since the camera is the origin of the picking ray, we need to offset it by the camera's offset manually
ray.origin.x -= camera.targetScreenOffset.x;
ray.origin.y -= camera.targetScreenOffset.y;
// Because the offset is in view space, we need to convert it to world space first
if (camera.targetScreenOffset.x !== 0 || camera.targetScreenOffset.y !== 0) {
this._viewOffset.set(camera.targetScreenOffset.x, camera.targetScreenOffset.y, 0);
camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);
this._globalOffset = Vector3.TransformNormal(this._viewOffset, camera._cameraTransformMatrix);
ray.origin.addInPlace(this._globalOffset);
}

let distance = 0;
if (this._hitPlane) {
distance = ray.intersectsPlane(this._hitPlane) ?? 0;
Expand Down