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:
- The host owns a
ViewportInput(or aViewportInstance) withplanar_bindingsand hands each resolved frame toapply. Create the controller withnew_stateless. - The controller owns the resolver: create it with
new, callbegin_framewith the frame’sViewportContext, push every translated event withpush_event, and callapply_to_cameraonce per frame. Events are routed by the context’s input ownership, so a drag that starts over the application’s UI does not pan.
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: f32Multiplier on pan deltas. Defaults to 1.0, which keeps the content
under the pointer while dragging.
zoom_sensitivity: f32Zoom per pixel of wheel or pinch input: each frame zooms by
exp(zoom * zoom_sensitivity). Defaults to
DEFAULT_ZOOM_SENSITIVITY.
Implementations§
Source§impl Camera2dController
impl Camera2dController
Sourcepub const DEFAULT_ZOOM_SENSITIVITY: f32 = 0.002
pub const DEFAULT_ZOOM_SENSITIVITY: f32 = 0.002
Default zoom sensitivity: a wheel notch zooms by about 6%.
Sourcepub fn new() -> Self
pub fn new() -> Self
A controller with its own resolver holding planar_bindings.
Sourcepub fn from_bindings(bindings: Vec<ViewportBinding>) -> Self
pub fn from_bindings(bindings: Vec<ViewportBinding>) -> Self
A controller with its own resolver holding bindings.
Sourcepub fn new_stateless() -> Self
pub fn new_stateless() -> Self
A controller with no bindings, for a host that resolves its own frames
and calls apply.
Sourcepub fn input_mut(&mut self) -> &mut ViewportInput
pub fn input_mut(&mut self) -> &mut ViewportInput
The controller’s own resolver, for touch settings or cancelling a gesture.
Sourcepub fn begin_frame(&mut self, ctx: ViewportContext)
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.
Sourcepub fn begin_frame_at(&mut self, ctx: ViewportContext, time_seconds: f32)
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.
Sourcepub fn push_event(&mut self, event: ViewportEvent)
pub fn push_event(&mut self, event: ViewportEvent)
Push one translated event. Routing follows the ownership given to the
last begin_frame.
Sourcepub fn resolve(&self) -> ActionFrame
pub fn resolve(&self) -> ActionFrame
Resolve the events pushed this frame without moving any camera.
Sourcepub fn apply_to_camera(&mut self, camera: &mut Camera2d, dt: f32) -> ActionFrame
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.
Sourcepub fn apply(&mut self, camera: &mut Camera2d, frame: &ActionFrame, dt: f32)
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.