Skip to main content

Camera2dController

Struct Camera2dController 

Source
pub struct Camera2dController {
    pub pan_sensitivity: f32,
    pub zoom_sensitivity: f32,
    /* private fields */
}
Expand description

Drag-to-pan and zoom-about-the-cursor for a Camera2d.

Two ways to drive it, as with the other controllers:

controller.begin_frame(ViewportContext::new(ownership, viewport_size));
for event in events { controller.push_event(event); }
controller.apply_to_camera(&mut camera2d, dt);
frame_camera = camera2d.camera();

Both paths also advance the camera’s follow and shake, so do not call Camera2d::update as well.

Fields§

§pan_sensitivity: f32

Multiplier on pan deltas. Defaults to 1.0, which keeps the content under the pointer while dragging.

§zoom_sensitivity: f32

Zoom per pixel of wheel or pinch input: each frame zooms by exp(zoom * zoom_sensitivity). Defaults to DEFAULT_ZOOM_SENSITIVITY.

Implementations§

Source§

impl Camera2dController

Source

pub const DEFAULT_ZOOM_SENSITIVITY: f32 = 0.002

Default zoom sensitivity: a wheel notch zooms by about 6%.

Source

pub fn new() -> Self

A controller with its own resolver holding planar_bindings.

Source

pub fn from_bindings(bindings: Vec<ViewportBinding>) -> Self

A controller with its own resolver holding bindings.

Source

pub fn new_stateless() -> Self

A controller with no bindings, for a host that resolves its own frames and calls apply.

Source

pub fn input_mut(&mut self) -> &mut ViewportInput

The controller’s own resolver, for touch settings or cancelling a gesture.

Source

pub fn begin_frame(&mut self, ctx: ViewportContext)

Begin a frame: clear the per-frame input and record the context (input ownership and viewport size). Call it before pushing the frame’s events.

Source

pub fn begin_frame_at(&mut self, ctx: ViewportContext, time_seconds: f32)

begin_frame with the host’s clock, which double tap and long press need.

Source

pub fn push_event(&mut self, event: ViewportEvent)

Push one translated event. Routing follows the ownership given to the last begin_frame.

Source

pub fn resolve(&self) -> ActionFrame

Resolve the events pushed this frame without moving any camera.

Source

pub fn apply_to_camera(&mut self, camera: &mut Camera2d, dt: f32) -> ActionFrame

Resolve this frame’s events, set the camera’s viewport size from the last begin_frame, apply the input and advance follow and shake by dt. Returns the resolved frame.

Source

pub fn apply(&mut self, camera: &mut Camera2d, frame: &ActionFrame, dt: f32)

Apply a resolved frame: pan by navigation.pan, zoom by navigation.zoom about the cursor (the touch point during a pinch, the screen centre with neither), then advance follow and shake by dt. Orbit and twist are ignored. The camera’s viewport size must already be current.

Trait Implementations§

Source§

impl Default for Camera2dController

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.