Skip to main content

CameraController

Trait CameraController 

Source
pub trait CameraController {
    // Required method
    fn apply(&mut self, camera: &mut Camera, frame: &ActionFrame, dt: f32);

    // Provided methods
    fn set_viewport(&mut self, viewport_size: [f32; 2], pixels_per_point: f32) { ... }
    fn as_any_mut(&mut self) -> Option<&mut dyn Any> { ... }
}
Expand description

A camera controller: the “apply” half of input handling.

Implement this to drive a Camera from a resolved ActionFrame however you like - the built-in controllers (OrbitCameraController, …) are one set of policies, not the only ones. Resolve the frame with input::ViewportInput, then hand it to your controller each frame.

The built-in controllers implement this, but the trait is not required to use them: their inherent apply methods and free-function forms still work. It exists so a custom controller has a concrete shape to fill and so controllers are interchangeable by type where a consumer wants that.

Required Methods§

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.

Provided Methods§

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§