Skip to main content

glam/dcamera/lh/
proj.rs

1// Generated from camera_proj.rs.tera template. Edit the template, not the generated file.
2
3//! Projection matrix constructors.
4//!
5//! Expects left-handed Y-up view space input.
6//!
7//! Each sub-module targets a specific graphics API convention:
8//!
9//! * [`opengl`] - NDC Z range **[-1, 1]**, Y-up
10//! * [`directx`] - NDC Z range **[0, 1]**, Y-up
11//! * [`vulkan`] - NDC Z range **[0, 1]**, Y-down
12
13#[doc(alias = "webgl")]
14pub mod opengl {
15    //! OpenGL NDC convention: Z range **[-1, 1]**, Y-up.
16    //!
17    //! Expects a left-handed Y-up view space input.
18
19    use crate::{dcamera::camera_impl, DMat4};
20
21    /// Creates a perspective projection matrix for use with OpenGL.
22    ///
23    /// Expects a left-handed Y-up view space input.
24    /// Outputs NDC with Z in [-1, 1] and Y-up.
25    ///
26    /// # Panics
27    ///
28    /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
29    #[inline]
30    #[must_use]
31    pub fn perspective(vertical_fov: f64, aspect_ratio: f64, near: f64, far: f64) -> DMat4 {
32        camera_impl::perspective::<false, false, false>(vertical_fov, aspect_ratio, near, far)
33    }
34
35    /// Creates an orthographic projection matrix for use with OpenGL.
36    ///
37    /// Expects a left-handed Y-up view space input.
38    /// Outputs NDC with Z in [-1, 1] and Y-up.
39    #[inline]
40    #[must_use]
41    pub fn orthographic(
42        left: f64,
43        right: f64,
44        bottom: f64,
45        top: f64,
46        near: f64,
47        far: f64,
48    ) -> DMat4 {
49        camera_impl::orthographic::<false, false, false>(left, right, bottom, top, near, far)
50    }
51
52    /// Creates a perspective projection matrix from a frustum for use with OpenGL.
53    ///
54    /// Expects a left-handed Y-up view space input.
55    /// Outputs NDC with Z in [-1, 1] and Y-up.
56    ///
57    /// # Panics
58    ///
59    /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
60    #[inline]
61    #[must_use]
62    pub fn frustum(left: f64, right: f64, bottom: f64, top: f64, near: f64, far: f64) -> DMat4 {
63        camera_impl::frustum::<false, false, false>(left, right, bottom, top, near, far)
64    }
65}
66
67pub mod vulkan {
68    //! Vulkan NDC convention: Z range **[0, 1]**, Y-down.
69    //!
70    //! Expects a left-handed Y-up view space input.
71    //!
72    //! Includes standard, infinite-far, and reverse-depth variants.
73
74    use crate::{dcamera::camera_impl, DMat4};
75
76    /// Creates a perspective projection matrix for use with Vulkan.
77    ///
78    /// Expects a left-handed Y-up view space input.
79    /// Outputs NDC with Z in [0, 1] and Y-down.
80    ///
81    /// # Panics
82    ///
83    /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
84    #[inline]
85    #[must_use]
86    pub fn perspective(vertical_fov: f64, aspect_ratio: f64, near: f64, far: f64) -> DMat4 {
87        camera_impl::perspective::<false, true, true>(vertical_fov, aspect_ratio, near, far)
88    }
89
90    /// Creates an infinite perspective projection matrix for use with Vulkan.
91    ///
92    /// Like `perspective`, but with an infinite value for `far`. Points at distance
93    /// `near` map to depth `0`; as distance approaches infinity, depth approaches `1`.
94    ///
95    /// Expects a left-handed Y-up view space input.
96    /// Outputs NDC with Z in [0, 1] and Y-down.
97    ///
98    /// # Panics
99    ///
100    /// Will panic if `near` is less than or equal to zero when `glam_assert` is enabled.
101    #[inline]
102    #[must_use]
103    pub fn perspective_infinite(vertical_fov: f64, aspect_ratio: f64, near: f64) -> DMat4 {
104        camera_impl::perspective_infinite::<false, true, true>(vertical_fov, aspect_ratio, near)
105    }
106
107    /// Creates an infinite perspective projection matrix with reversed depth for use with
108    /// Vulkan.
109    ///
110    /// Maps `near` to depth `1` and infinity to depth `0`.
111    ///
112    /// Reversed Z improves depth precision when used with a floating-point depth buffer.
113    ///
114    /// Expects a left-handed Y-up view space input.
115    /// Outputs NDC with Z in [0, 1] and Y-down.
116    ///
117    /// # Panics
118    ///
119    /// Will panic if `near` is less than or equal to zero when `glam_assert` is enabled.
120    #[inline]
121    #[must_use]
122    pub fn perspective_infinite_reverse(vertical_fov: f64, aspect_ratio: f64, near: f64) -> DMat4 {
123        camera_impl::perspective_infinite_reverse::<false, true>(vertical_fov, aspect_ratio, near)
124    }
125
126    /// Creates an orthographic projection matrix for use with Vulkan.
127    ///
128    /// Expects a left-handed Y-up view space input.
129    /// Outputs NDC with Z in [0, 1] and Y-down.
130    #[inline]
131    #[must_use]
132    pub fn orthographic(
133        left: f64,
134        right: f64,
135        bottom: f64,
136        top: f64,
137        near: f64,
138        far: f64,
139    ) -> DMat4 {
140        camera_impl::orthographic::<false, true, true>(left, right, bottom, top, near, far)
141    }
142
143    /// Creates a perspective projection from a frustum for use with Vulkan.
144    ///
145    /// Expects a left-handed Y-up view space input.
146    /// Outputs NDC with Z in [0, 1] and Y-down.
147    ///
148    /// # Panics
149    ///
150    /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
151    #[inline]
152    #[must_use]
153    pub fn frustum(left: f64, right: f64, bottom: f64, top: f64, near: f64, far: f64) -> DMat4 {
154        camera_impl::frustum::<false, true, true>(left, right, bottom, top, near, far)
155    }
156}
157
158#[doc(alias = "webgpu")]
159pub mod directx {
160    //! DirectX and WebGPU NDC convention: Z range **[0, 1]**, Y-up.
161    //!
162    //! Expects a left-handed Y-up view space input.
163    //!
164    //! Includes standard, infinite-far, and reverse-depth variants.
165
166    use crate::{dcamera::camera_impl, DMat4};
167
168    /// Creates a perspective projection matrix for use with DirectX and WebGPU.
169    ///
170    /// Expects a left-handed Y-up view space input.
171    /// Outputs NDC with Z in [0, 1] and Y-up.
172    ///
173    /// # Panics
174    ///
175    /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
176    #[inline]
177    #[must_use]
178    pub fn perspective(vertical_fov: f64, aspect_ratio: f64, near: f64, far: f64) -> DMat4 {
179        camera_impl::perspective::<false, true, false>(vertical_fov, aspect_ratio, near, far)
180    }
181
182    /// Creates an infinite perspective projection matrix for use with DirectX and WebGPU.
183    ///
184    /// Like `perspective`, but with an infinite value for `far`. Points at distance
185    /// `near` map to depth `0`; as distance approaches infinity, depth approaches `1`.
186    ///
187    /// Expects a left-handed Y-up view space input.
188    /// Outputs NDC with Z in [0, 1] and Y-up.
189    ///
190    /// # Panics
191    ///
192    /// Will panic if `near` is less than or equal to zero when `glam_assert` is enabled.
193    #[inline]
194    #[must_use]
195    pub fn perspective_infinite(vertical_fov: f64, aspect_ratio: f64, near: f64) -> DMat4 {
196        camera_impl::perspective_infinite::<false, true, false>(vertical_fov, aspect_ratio, near)
197    }
198
199    /// Creates an infinite perspective projection matrix with reversed depth for use with
200    /// DirectX and WebGPU.
201    ///
202    /// Maps `near` to depth `1` and infinity to depth `0`.
203    ///
204    /// Reversed Z improves depth precision when used with a floating-point depth buffer.
205    ///
206    /// Expects a left-handed Y-up view space input.
207    /// Outputs NDC with Z in [0, 1] and Y-up.
208    ///
209    /// # Panics
210    ///
211    /// Will panic if `near` is less than or equal to zero when `glam_assert` is enabled.
212    #[inline]
213    #[must_use]
214    pub fn perspective_infinite_reverse(vertical_fov: f64, aspect_ratio: f64, near: f64) -> DMat4 {
215        camera_impl::perspective_infinite_reverse::<false, false>(vertical_fov, aspect_ratio, near)
216    }
217
218    /// Creates an orthographic projection matrix for use with DirectX and WebGPU.
219    ///
220    /// Expects a left-handed Y-up view space input.
221    /// Outputs NDC with Z in [0, 1] and Y-up.
222    #[inline]
223    #[must_use]
224    pub fn orthographic(
225        left: f64,
226        right: f64,
227        bottom: f64,
228        top: f64,
229        near: f64,
230        far: f64,
231    ) -> DMat4 {
232        camera_impl::orthographic::<false, true, false>(left, right, bottom, top, near, far)
233    }
234
235    /// Creates a perspective projection from a frustum for use with DirectX and WebGPU.
236    ///
237    /// Expects a left-handed Y-up view space input.
238    /// Outputs NDC with Z in [0, 1] and Y-up.
239    ///
240    /// # Panics
241    ///
242    /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
243    #[inline]
244    #[must_use]
245    pub fn frustum(left: f64, right: f64, bottom: f64, top: f64, near: f64, far: f64) -> DMat4 {
246        camera_impl::frustum::<false, true, false>(left, right, bottom, top, near, far)
247    }
248}