summaryrefslogtreecommitdiff
path: root/src/camera.rs
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2022-09-25 23:12:41 -0400
committerMicha White <botahamec@outlook.com>2022-09-25 23:12:41 -0400
commit374c97ca348bb1d8df4cb125a9e68b855365daf5 (patch)
treeb17ef27cd085c0d4fbc094bf500b7459ebcae64d /src/camera.rs
parent20815949e86e82a97529432d8a6d1e425354afaa (diff)
Public API for rotating the camera
Diffstat (limited to 'src/camera.rs')
-rw-r--r--src/camera.rs25
1 files changed, 22 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);