Browse Source

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.
pull/33/head
Ian Chamberlain 1 year ago
parent
commit
31272895d7
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 6
      citro3d/examples/triangle.rs
  2. 32
      citro3d/src/math/projection.rs

6
citro3d/examples/triangle.rs

@ -34,15 +34,15 @@ struct Vertex { @@ -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),
},
];

32
citro3d/src/math/projection.rs

@ -26,14 +26,42 @@ impl<Kind> Projection<Kind> { @@ -26,14 +26,42 @@ impl<Kind> Projection<Kind> {
/// 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
}

Loading…
Cancel
Save