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

Add API to interpolate between two free camera positions #10189

Open
mourner opened this issue Dec 11, 2020 · 0 comments
Open

Add API to interpolate between two free camera positions #10189

mourner opened this issue Dec 11, 2020 · 0 comments
Assignees

Comments

@mourner
Copy link
Member

mourner commented Dec 11, 2020

Currently there's no easy way to interpolate smoothly between two free-form camera positions. Existing examples interpolate lng/lat/latitude separately (which will have issues on bigger distances due non-linear latitude to y relation) and/or use lookAt method to sidestep interpolating rotation, which is not an applicable strategy in many cases.

In an example I played with for smooth animation along path, I had to interpolate manually using glMatrix spherical quaternion interpolation:

// interpolate position
camera.position.x = sourceCamera.position.x + (targetCamera.position.x - sourceCamera.position.x) * t;
camera.position.y = sourceCamera.position.y + (targetCamera.position.y - sourceCamera.position.y) * t;
camera.position.z = sourceCamera.position.z + (targetCamera.position.z - sourceCamera.position.z) * t;

// interpolate orientation
glMatrix.quat.slerp(camera.orientation, sourceCamera.orientation, targetCamera.orientation, t);

We should have an easy API for this, e.g.:

const camera = mapboxgl.FreeCameraOptions.interpolate(sourceCamera, targetCamera, t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant