1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Input handling for `viewport-lib`: a replaceable layer, not baked-in core.
//!
//! The design intent is that a consumer can bring their own. Input handling
//! splits into two halves, and either is usable on its own:
//!
//! 1. **Resolve**: [`input::ViewportInput`] turns `ViewportEvent`s into a single
//! [`ActionFrame`](viewport_lib_types::input::ActionFrame) per frame.
//! 2. **Apply**: a camera controller takes that `ActionFrame` and a
//! `&mut Camera` and produces a new pose. This is the half a custom controller
//! replaces; see [`CameraController`].
//!
//! The built-in [`controllers`] (orbit, first/third-person, turntable, and the
//! `dt`-driven animator) are the batteries-included defaults. The winit/egui
//! [adapters](input::adapters) that translate native events are optional
//! features (`winit-adapter`, `egui-adapter`), so the crate builds with no
//! framework dependency by default.
//!
//! This crate carries no `wgpu` and no renderer. It stands on
//! `viewport-lib-types` (the input vocabulary and the `Camera` type) plus `glam`.
//! `viewport-lib` re-exports it, so `viewport_lib::OrbitCameraController` and
//! friends keep working.
// Re-exported so controllers can name `crate::Camera` and consumers can get the
// camera type from this crate.
pub use Camera;
/// The batteries-included camera controllers.
/// The event resolver, the legacy query model, and the native-event adapters.
/// A camera controller: the "apply" half of input handling.
///
/// Implement this to drive a `Camera` from a resolved
/// [`ActionFrame`](viewport_lib_types::input::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.
// The first/third-person controllers take an extra per-frame position (eye /
// target), so they do not fit this two-argument shape; use their inherent
// `apply` methods directly. See `controllers`.