little_camera/lib.rs
1//! Little engine camera abstraction
2//!
3//! Introduces a new position type: `WorldPosition`, which contains
4//! coordinates in f64 values. This allows little-bevy to model vast
5//! spaces, up to an entire solar system at millimetre precision.
6//!
7//! ## How to use
8//!
9//! The main product of `little-camera` is the `VirtualCameraBundle`,
10//! which defines a virtual camera in space, with additional settings
11//! (zoom, apeture size, exposure time, and ISO). A `VirtualCamera`
12//! can be marked as `Active`, which switches the rendered camera to
13//! that location and settings.
14//!
15//! `little-camera` exposes a utility function `init_base_camera()`,
16//! which spawns a correctly tagged 2D camera. Alternatively, you can
17//! spawn your own camera, as long as it is tagged with the
18//! `LittleCamera` component.
19//!
20//! The `translate` module is vital for translating different
21//! posititional systems to one-another.
22//!
23//! - Points from cursor positions and screen locations can be
24//! translated into render coordinates for indicator rendering, and
25//! world coordinates, for collision detection.
26//!
27//! - Points in world space can be translated into render coordinates,
28//! to place them at the correct location for the base camera.
29//!
30//! ## Future ideas
31//!
32//! - Integrated camera-sharing capabilities, allowing players or
33//! different sessions to share camera views. Having a template to
34//! express camera locations and setting also allows for scripted
35//! camera transitions and cutscenes.
36//!
37//! - `WorldPositionStack`, which allows a range of possible
38//! WorldPositions, become the new base scalar value for another layer
39//! of `WorldPosition`. This way vast quantities of space can be
40//! modelled.
41
42mod base;
43mod plugin;
44mod position;
45mod state;
46mod virt;
47
48pub mod translate;
49
50pub use base::*;
51pub use position::*;
52pub use state::*;
53pub use virt::*;
54
55use bevy::prelude::*;
56
57#[derive(Component)]
58pub struct LittleCamera;
59
60#[derive(Bundle)]
61pub struct VirtualCameraBundle<State: Component> {
62 _marker: VirtualCamera,
63 pub pos: WorldPosition,
64 pub scale: VCameraScale,
65 pub state: State,
66 pub iso: BaseCameraISO,
67 pub exposure: BaseCameraExposureMs,
68 pub apeture: BaseCameraApeture,
69}
70
71impl<State: Component> VirtualCameraBundle<State> {
72 pub fn new(pos: WorldPosition, scale: VCameraScale, state: State) -> Self {
73 Self {
74 _marker: VirtualCamera,
75 pos,
76 scale,
77 state,
78 iso: BaseCameraISO(400),
79 exposure: BaseCameraExposureMs(120.0),
80 apeture: BaseCameraApeture(8.0),
81 }
82 }
83}