summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/camera.rs25
-rw-r--r--src/renderer.rs10
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,