Skip to content

Commit

Permalink
Improve documentation for the Mat4 projection functions (#570)
Browse files Browse the repository at this point in the history
* Add detailed docs to the Mat4 projection utility functions
  • Loading branch information
kovaxis authored Oct 27, 2024
1 parent 30c6b0d commit e2f4be9
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 49 deletions.
45 changes: 38 additions & 7 deletions codegen/templates/mat.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,10 @@ impl {{ self_t }} {
Self::look_to_rh(eye, center.sub(eye), up)
}

/// Creates a right-handed perspective projection matrix with [-1,1] depth range.
/// Creates a right-handed perspective projection matrix with `[-1,1]` depth range.
///
/// Useful to map the standard right-handed coordinate system into what OpenGL expects.
///
/// This is the same as the OpenGL `gluPerspective` function.
/// See <https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml>
#[inline]
Expand All @@ -1742,6 +1745,8 @@ impl {{ self_t }} {

/// Creates a left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Useful to map the standard left-handed coordinate system into what WebGPU/Metal/Direct3D expect.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
Expand All @@ -1764,6 +1769,8 @@ impl {{ self_t }} {

/// Creates a right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Useful to map the standard right-handed coordinate system into what WebGPU/Metal/Direct3D expect.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
Expand All @@ -1786,9 +1793,13 @@ impl {{ self_t }} {

/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Like `perspective_lh`, but with an infinite value for `z_far`.
/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`.
///
/// # Panics
///
/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled.
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
/// enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_lh(fov_y_radians: {{ scalar_t }}, aspect_ratio: {{ scalar_t }}, z_near: {{ scalar_t }}) -> Self {
Expand All @@ -1804,7 +1815,9 @@ impl {{ self_t }} {
)
}

/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range.
/// Creates an infinite reverse left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Similar to `perspective_infinite_lh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`.
///
/// # Panics
///
Expand All @@ -1828,8 +1841,15 @@ impl {{ self_t }} {
)
}

/// Creates an infinite right-handed perspective projection matrix with
/// `[0,1]` depth range.
/// Creates an infinite right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Like `perspective_rh`, but with an infinite value for `z_far`.
/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
/// enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_rh(fov_y_radians: {{ scalar_t }}, aspect_ratio: {{ scalar_t }}, z_near: {{ scalar_t }}) -> Self {
Expand All @@ -1843,8 +1863,13 @@ impl {{ self_t }} {
)
}

/// Creates an infinite reverse right-handed perspective projection matrix
/// with `[0,1]` depth range.
/// Creates an infinite reverse right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Similar to `perspective_infinite_rh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`.
///
/// # Panics
///
/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_reverse_rh(
Expand All @@ -1866,6 +1891,8 @@ impl {{ self_t }} {
/// range. This is the same as the OpenGL `glOrtho` function in OpenGL.
/// See
/// <https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml>
///
/// Useful to map a right-handed coordinate system to the normalized device coordinates that OpenGL expects.
#[inline]
#[must_use]
pub fn orthographic_rh_gl(
Expand All @@ -1892,6 +1919,8 @@ impl {{ self_t }} {
}

/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range.
///
/// Useful to map a left-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect.
#[inline]
#[must_use]
pub fn orthographic_lh(
Expand Down Expand Up @@ -1919,6 +1948,8 @@ impl {{ self_t }} {
}

/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range.
///
/// Useful to map a right-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect.
#[inline]
#[must_use]
pub fn orthographic_rh(
Expand Down
45 changes: 38 additions & 7 deletions src/f32/coresimd/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,10 @@ impl Mat4 {
Self::look_to_rh(eye, center.sub(eye), up)
}

/// Creates a right-handed perspective projection matrix with [-1,1] depth range.
/// Creates a right-handed perspective projection matrix with `[-1,1]` depth range.
///
/// Useful to map the standard right-handed coordinate system into what OpenGL expects.
///
/// This is the same as the OpenGL `gluPerspective` function.
/// See <https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml>
#[inline]
Expand All @@ -874,6 +877,8 @@ impl Mat4 {

/// Creates a left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Useful to map the standard left-handed coordinate system into what WebGPU/Metal/Direct3D expect.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
Expand All @@ -896,6 +901,8 @@ impl Mat4 {

/// Creates a right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Useful to map the standard right-handed coordinate system into what WebGPU/Metal/Direct3D expect.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
Expand All @@ -918,9 +925,13 @@ impl Mat4 {

/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Like `perspective_lh`, but with an infinite value for `z_far`.
/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`.
///
/// # Panics
///
/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled.
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
/// enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_lh(fov_y_radians: f32, aspect_ratio: f32, z_near: f32) -> Self {
Expand All @@ -936,7 +947,9 @@ impl Mat4 {
)
}

/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range.
/// Creates an infinite reverse left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Similar to `perspective_infinite_lh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`.
///
/// # Panics
///
Expand All @@ -960,8 +973,15 @@ impl Mat4 {
)
}

/// Creates an infinite right-handed perspective projection matrix with
/// `[0,1]` depth range.
/// Creates an infinite right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Like `perspective_rh`, but with an infinite value for `z_far`.
/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
/// enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_rh(fov_y_radians: f32, aspect_ratio: f32, z_near: f32) -> Self {
Expand All @@ -975,8 +995,13 @@ impl Mat4 {
)
}

/// Creates an infinite reverse right-handed perspective projection matrix
/// with `[0,1]` depth range.
/// Creates an infinite reverse right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Similar to `perspective_infinite_rh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`.
///
/// # Panics
///
/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_reverse_rh(
Expand All @@ -998,6 +1023,8 @@ impl Mat4 {
/// range. This is the same as the OpenGL `glOrtho` function in OpenGL.
/// See
/// <https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml>
///
/// Useful to map a right-handed coordinate system to the normalized device coordinates that OpenGL expects.
#[inline]
#[must_use]
pub fn orthographic_rh_gl(
Expand All @@ -1024,6 +1051,8 @@ impl Mat4 {
}

/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range.
///
/// Useful to map a left-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect.
#[inline]
#[must_use]
pub fn orthographic_lh(
Expand Down Expand Up @@ -1051,6 +1080,8 @@ impl Mat4 {
}

/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range.
///
/// Useful to map a right-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect.
#[inline]
#[must_use]
pub fn orthographic_rh(
Expand Down
45 changes: 38 additions & 7 deletions src/f32/neon/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,10 @@ impl Mat4 {
Self::look_to_rh(eye, center.sub(eye), up)
}

/// Creates a right-handed perspective projection matrix with [-1,1] depth range.
/// Creates a right-handed perspective projection matrix with `[-1,1]` depth range.
///
/// Useful to map the standard right-handed coordinate system into what OpenGL expects.
///
/// This is the same as the OpenGL `gluPerspective` function.
/// See <https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml>
#[inline]
Expand All @@ -879,6 +882,8 @@ impl Mat4 {

/// Creates a left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Useful to map the standard left-handed coordinate system into what WebGPU/Metal/Direct3D expect.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
Expand All @@ -901,6 +906,8 @@ impl Mat4 {

/// Creates a right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Useful to map the standard right-handed coordinate system into what WebGPU/Metal/Direct3D expect.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
Expand All @@ -923,9 +930,13 @@ impl Mat4 {

/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Like `perspective_lh`, but with an infinite value for `z_far`.
/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`.
///
/// # Panics
///
/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled.
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
/// enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_lh(fov_y_radians: f32, aspect_ratio: f32, z_near: f32) -> Self {
Expand All @@ -941,7 +952,9 @@ impl Mat4 {
)
}

/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range.
/// Creates an infinite reverse left-handed perspective projection matrix with `[0,1]` depth range.
///
/// Similar to `perspective_infinite_lh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`.
///
/// # Panics
///
Expand All @@ -965,8 +978,15 @@ impl Mat4 {
)
}

/// Creates an infinite right-handed perspective projection matrix with
/// `[0,1]` depth range.
/// Creates an infinite right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Like `perspective_rh`, but with an infinite value for `z_far`.
/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`.
///
/// # Panics
///
/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is
/// enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_rh(fov_y_radians: f32, aspect_ratio: f32, z_near: f32) -> Self {
Expand All @@ -980,8 +1000,13 @@ impl Mat4 {
)
}

/// Creates an infinite reverse right-handed perspective projection matrix
/// with `[0,1]` depth range.
/// Creates an infinite reverse right-handed perspective projection matrix with `[0,1]` depth range.
///
/// Similar to `perspective_infinite_rh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`.
///
/// # Panics
///
/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled.
#[inline]
#[must_use]
pub fn perspective_infinite_reverse_rh(
Expand All @@ -1003,6 +1028,8 @@ impl Mat4 {
/// range. This is the same as the OpenGL `glOrtho` function in OpenGL.
/// See
/// <https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml>
///
/// Useful to map a right-handed coordinate system to the normalized device coordinates that OpenGL expects.
#[inline]
#[must_use]
pub fn orthographic_rh_gl(
Expand All @@ -1029,6 +1056,8 @@ impl Mat4 {
}

/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range.
///
/// Useful to map a left-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect.
#[inline]
#[must_use]
pub fn orthographic_lh(
Expand Down Expand Up @@ -1056,6 +1085,8 @@ impl Mat4 {
}

/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range.
///
/// Useful to map a right-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect.
#[inline]
#[must_use]
pub fn orthographic_rh(
Expand Down
Loading

0 comments on commit e2f4be9

Please sign in to comment.