diff options
| author | Micha White <botahamec@outlook.com> | 2022-09-25 23:12:41 -0400 |
|---|---|---|
| committer | Micha White <botahamec@outlook.com> | 2022-09-25 23:12:41 -0400 |
| commit | 374c97ca348bb1d8df4cb125a9e68b855365daf5 (patch) | |
| tree | b17ef27cd085c0d4fbc094bf500b7459ebcae64d /src | |
| parent | 20815949e86e82a97529432d8a6d1e425354afaa (diff) | |
Public API for rotating the camera
Diffstat (limited to 'src')
| -rw-r--r-- | src/camera.rs | 25 | ||||
| -rw-r--r-- | src/renderer.rs | 10 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/camera.rs b/src/camera.rs index 2a2a2e6..22f9837 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -44,12 +44,18 @@ impl Camera { self.zoom } + /// Get the camera's current rotation, in radians + #[must_use] + pub const fn rotation(&self) -> f32 { + self.rotation + } + /// Set the position of the camera pub fn set_position(&mut self, x: f32, y: f32) { debug_assert!( - x <= 1000.0 && y <= 1000.0, - "The position of the camera is ({}, {}), which is too large. \ - Please keep both the x and y positions below 1000 units. \ + (-1000.0..1000.0).contains(&x) && (-1000.0..1000.0).contains(&y), + "The position of the camera is (x: {}, y: {}). \ + Please keep both the x and y positions above -1000 and below 1000 units. \ Otherwise, everything will look crazy. \ For an explanation, see https://www.youtube.com/watch?v=Q2OGwnRik24", x, @@ -61,9 +67,22 @@ impl Camera { /// Set the zoom of the camera pub fn set_zoom(&mut self, zoom: f32) { + debug_assert!( + (-1000.0..1000.0).contains(&zoom), + "The zoom of the camera is {}. \ + Please keep above -1000, and below 1000, or else smooth zoom may be difficult. \ + For an explanation, see https://www.youtube.com/watch?v=Q2OGwnRik24", + zoom + ); + self.zoom = zoom; } + /// Set the camera rotation, in radians + pub fn set_rotation(&mut self, rotation: f32) { + self.rotation = rotation % std::f32::consts::TAU; + } + /// Set the aspect ratio of the camera pub(crate) fn set_size(&mut self, width: u32, height: u32) { self.inverse_aspect_ratio = inverse_aspect_ratio(width, height); diff --git a/src/renderer.rs b/src/renderer.rs index 4ac521f..55333f4 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -342,6 +342,16 @@ impl Renderer { self.instances.clear(); } + /// Get the camera information + pub const fn camera(&self) -> &Camera { + &self.camera + } + + /// Get a mutable reference to the camera + pub fn camera_mut(&mut self) -> &mut Camera { + &mut self.camera + } + fn refresh_camera_buffer(&mut self) { self.queue.write_buffer( &self.camera_buffer, |
