Skip to main content

Camera2dControl

Struct Camera2dControl 

Source
pub struct Camera2dControl {
    pub camera: Camera2d,
    pub controller: Camera2dController,
}
Expand description

A Camera2d and a Camera2dController as one CameraController: each frame it applies pan and zoom from the resolved input, advances the follow and the shake, and writes the view into the camera with Camera2d::apply_to.

Hand it to a runner that drives a camera through CameraController (ViewportApp’s CameraControl::Controller), and reach the 2D camera through camera to follow, shake or set bounds. The runner passes the size the scene draws at through CameraController::set_viewport before each apply.

Fields§

§camera: Camera2d

The 2D view.

§controller: Camera2dController

The pan and zoom policy, with no resolver of its own.

Implementations§

Source§

impl Camera2dControl

Source

pub fn new(camera: Camera2d) -> Self

Drive camera with a stateless Camera2dController.

Trait Implementations§

Source§

impl CameraController for Camera2dControl

Source§

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

Apply one frame of resolved input to the camera. dt is the frame time in seconds, for input that is held rather than moved (a key held to fly, a stick held over): such input moves the camera at a rate, and needs the time to turn that rate into a distance. Drags and the wheel arrive in the frame as deltas already.
Source§

fn set_viewport(&mut self, viewport_size: [f32; 2], pixels_per_point: f32)

The size the scene draws at, in logical pixels, and its device pixels per point. A runner calls this before each apply, for controllers whose motion depends on the viewport (dragging by pixels, zooming about the cursor). For a viewport presented at a reference size it is the reference size with one pixel per point. The default ignores it.
Source§

fn as_any_mut(&mut self) -> Option<&mut dyn Any>

The controller as Any, so a host that handed it to a runner as a trait object can reach its concrete type again. The default returns None; return Some(self) to allow it.

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.