From 31272895d7bf45e0673af086536933ced157f76b Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Thu, 30 Nov 2023 09:15:53 -0500 Subject: [PATCH] Fixup right-handed coordinates and projection API Since it's a builder, we should really consume self and return Self instead of using &mut self. This makes it easier to convert into the final matrix at the end of building. --- citro3d/examples/triangle.rs | 6 +++--- citro3d/src/math/projection.rs | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/citro3d/examples/triangle.rs b/citro3d/examples/triangle.rs index 7673670..305a9f8 100644 --- a/citro3d/examples/triangle.rs +++ b/citro3d/examples/triangle.rs @@ -34,15 +34,15 @@ struct Vertex { static VERTICES: &[Vertex] = &[ Vertex { - pos: Vec3::new(0.0, 0.5, 3.0), + pos: Vec3::new(0.0, 0.5, -3.0), color: Vec3::new(1.0, 0.0, 0.0), }, Vertex { - pos: Vec3::new(-0.5, -0.5, 3.0), + pos: Vec3::new(-0.5, -0.5, -3.0), color: Vec3::new(0.0, 1.0, 0.0), }, Vertex { - pos: Vec3::new(0.5, -0.5, 3.0), + pos: Vec3::new(0.5, -0.5, -3.0), color: Vec3::new(0.0, 0.0, 1.0), }, ]; diff --git a/citro3d/src/math/projection.rs b/citro3d/src/math/projection.rs index 0ec72e5..f694ad6 100644 --- a/citro3d/src/math/projection.rs +++ b/citro3d/src/math/projection.rs @@ -26,14 +26,42 @@ impl Projection { /// Set the coordinate system's orientation for the projection. /// See [`CoordinateOrientation`] for more details. - pub fn coordinates(&mut self, orientation: CoordinateOrientation) -> &mut Self { + /// + /// # Example + /// + /// ``` + /// # let _runner = test_runner::GdbRunner::default(); + /// # use citro3d::math::{Projection, AspectRatio, CoordinateOrientation, Matrix4, ClipPlanes}; + /// let clip_planes = ClipPlanes { + /// near: 0.1, + /// far: 100.0, + /// }; + /// let mtx: Matrix4 = Projection::perspective(40.0, AspectRatio::TopScreen, clip_planes) + /// .coordinates(CoordinateOrientation::LeftHanded) + /// .into(); + /// ``` + pub fn coordinates(mut self, orientation: CoordinateOrientation) -> Self { self.coordinates = orientation; self } /// Set the screen rotation for the projection. /// See [`ScreenOrientation`] for more details. - pub fn screen(&mut self, orientation: ScreenOrientation) -> &mut Self { + /// + /// # Example + /// + /// ``` + /// # let _runner = test_runner::GdbRunner::default(); + /// # use citro3d::math::{Projection, AspectRatio, ScreenOrientation, Matrix4, ClipPlanes}; + /// let clip_planes = ClipPlanes { + /// near: 0.1, + /// far: 100.0, + /// }; + /// let mtx: Matrix4 = Projection::perspective(40.0, AspectRatio::TopScreen, clip_planes) + /// .screen(ScreenOrientation::None) + /// .into(); + /// ``` + pub fn screen(mut self, orientation: ScreenOrientation) -> Self { self.rotation = orientation; self }