Skip to main content

CameraAnimator

Struct CameraAnimator 

Source
pub struct CameraAnimator {
    pub momentum_decay: f64,
    pub smoothing: f64,
    /* private fields */
}
Expand description

Drives smooth camera transitions.

Supports three animation modes that may be active simultaneously:

  1. Fly-to / ease-to – a coordinated multi-property transition (only one may be active at a time; starting one cancels the other).
  2. Simple targets – independent exponential-smoothed zoom / yaw / pitch targets (useful for scroll-zoom, keyboard rotation).
  3. Momentum – inertial pan that decays over time.

Call tick every frame with the elapsed dt.

Fields§

§momentum_decay: f64

Momentum decay factor per second (0..1, 0 = instant stop).

§smoothing: f64

Smoothing factor for simple zoom/rotate targets (0 = instant, higher = smoother).

Implementations§

Source§

impl CameraAnimator

Source

pub fn new() -> Self

Create a new camera animator with default settings.

Source

pub fn start_fly_to(&mut self, camera: &mut Camera, options: &FlyToOptions)

Start a van Wijk fly-to animation.

This implements the “optimal path” algorithm from van Wijk & Nuij (2003), matching MapLibre/Mapbox flyTo behavior. The camera simultaneously interpolates center, zoom, bearing, and pitch along a zoom-out-then-zoom-in arc.

Cancels any active fly-to, ease-to, simple targets, and momentum.

If the requested transition is degenerate (no change or exceeds max_duration), a jump_to is performed instead.

Source

pub fn start_ease_to(&mut self, camera: &mut Camera, options: &EaseToOptions)

Start a simple ease-to animation.

Linearly interpolates center, zoom, bearing, and pitch over the specified duration with configurable easing.

Cancels any active fly-to, ease-to, simple targets, and momentum.

Source

pub fn animate_zoom(&mut self, target_distance: f64)

Set a zoom animation target (distance in meters).

Non-finite or non-positive distances are ignored.

Source

pub fn animate_rotate(&mut self, target_yaw: f64, target_pitch: f64)

Set rotation animation targets.

Non-finite angles are ignored independently.

Source

pub fn apply_momentum(&mut self, vx: f64, vy: f64)

Apply pan momentum in world meters/second.

Non-finite inputs are ignored.

Source

pub fn cancel(&mut self)

Cancel all animations and momentum.

Source

pub fn is_active(&self) -> bool

Whether any animation or momentum is active.

Source

pub fn is_flying(&self) -> bool

Whether a coordinated fly-to or ease-to animation is active.

Source

pub fn is_easing(&self) -> bool

Whether a coordinated ease-to animation is active.

Source

pub fn tick(&mut self, camera: &mut Camera, dt: f64)

Advance the animation by dt seconds, mutating the camera.

Non-finite or non-positive dt values are ignored.

Trait Implementations§

Source§

impl Default for CameraAnimator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.