glam/camera/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::{camera::camera_impl, Mat4};
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: f32, aspect_ratio: f32, near: f32, far: f32) -> Mat4 {
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(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) -> Mat4 {
42 camera_impl::orthographic::<false, false, false>(left, right, bottom, top, near, far)
43 }
44
45 /// Creates a perspective projection matrix from a frustum for use with OpenGL.
46 ///
47 /// Expects a left-handed Y-up view space input.
48 /// Outputs NDC with Z in [-1, 1] and Y-up.
49 ///
50 /// # Panics
51 ///
52 /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
53 #[inline]
54 #[must_use]
55 pub fn frustum(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) -> Mat4 {
56 camera_impl::frustum::<false, false, false>(left, right, bottom, top, near, far)
57 }
58}
59
60pub mod vulkan {
61 //! Vulkan NDC convention: Z range **[0, 1]**, Y-down.
62 //!
63 //! Expects a left-handed Y-up view space input.
64 //!
65 //! Includes standard, infinite-far, and reverse-depth variants.
66
67 use crate::{camera::camera_impl, Mat4};
68
69 /// Creates a perspective projection matrix for use with Vulkan.
70 ///
71 /// Expects a left-handed Y-up view space input.
72 /// Outputs NDC with Z in [0, 1] and Y-down.
73 ///
74 /// # Panics
75 ///
76 /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
77 #[inline]
78 #[must_use]
79 pub fn perspective(vertical_fov: f32, aspect_ratio: f32, near: f32, far: f32) -> Mat4 {
80 camera_impl::perspective::<false, true, true>(vertical_fov, aspect_ratio, near, far)
81 }
82
83 /// Creates an infinite perspective projection matrix for use with Vulkan.
84 ///
85 /// Like `perspective`, but with an infinite value for `far`. Points at distance
86 /// `near` map to depth `0`; as distance approaches infinity, depth approaches `1`.
87 ///
88 /// Expects a left-handed Y-up view space input.
89 /// Outputs NDC with Z in [0, 1] and Y-down.
90 ///
91 /// # Panics
92 ///
93 /// Will panic if `near` is less than or equal to zero when `glam_assert` is enabled.
94 #[inline]
95 #[must_use]
96 pub fn perspective_infinite(vertical_fov: f32, aspect_ratio: f32, near: f32) -> Mat4 {
97 camera_impl::perspective_infinite::<false, true, true>(vertical_fov, aspect_ratio, near)
98 }
99
100 /// Creates an infinite perspective projection matrix with reversed depth for use with
101 /// Vulkan.
102 ///
103 /// Maps `near` to depth `1` and infinity to depth `0`.
104 ///
105 /// Reversed Z improves depth precision when used with a floating-point depth buffer.
106 ///
107 /// Expects a left-handed Y-up view space input.
108 /// Outputs NDC with Z in [0, 1] and Y-down.
109 ///
110 /// # Panics
111 ///
112 /// Will panic if `near` is less than or equal to zero when `glam_assert` is enabled.
113 #[inline]
114 #[must_use]
115 pub fn perspective_infinite_reverse(vertical_fov: f32, aspect_ratio: f32, near: f32) -> Mat4 {
116 camera_impl::perspective_infinite_reverse::<false, true>(vertical_fov, aspect_ratio, near)
117 }
118
119 /// Creates an orthographic projection matrix for use with Vulkan.
120 ///
121 /// Expects a left-handed Y-up view space input.
122 /// Outputs NDC with Z in [0, 1] and Y-down.
123 #[inline]
124 #[must_use]
125 pub fn orthographic(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) -> Mat4 {
126 camera_impl::orthographic::<false, true, true>(left, right, bottom, top, near, far)
127 }
128
129 /// Creates a perspective projection from a frustum for use with Vulkan.
130 ///
131 /// Expects a left-handed Y-up view space input.
132 /// Outputs NDC with Z in [0, 1] and Y-down.
133 ///
134 /// # Panics
135 ///
136 /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
137 #[inline]
138 #[must_use]
139 pub fn frustum(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) -> Mat4 {
140 camera_impl::frustum::<false, true, true>(left, right, bottom, top, near, far)
141 }
142}
143
144#[doc(alias = "webgpu")]
145pub mod directx {
146 //! DirectX and WebGPU NDC convention: Z range **[0, 1]**, Y-up.
147 //!
148 //! Expects a left-handed Y-up view space input.
149 //!
150 //! Includes standard, infinite-far, and reverse-depth variants.
151
152 use crate::{camera::camera_impl, Mat4};
153
154 /// Creates a perspective projection matrix for use with DirectX and WebGPU.
155 ///
156 /// Expects a left-handed Y-up view space input.
157 /// Outputs NDC with Z in [0, 1] and Y-up.
158 ///
159 /// # Panics
160 ///
161 /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
162 #[inline]
163 #[must_use]
164 pub fn perspective(vertical_fov: f32, aspect_ratio: f32, near: f32, far: f32) -> Mat4 {
165 camera_impl::perspective::<false, true, false>(vertical_fov, aspect_ratio, near, far)
166 }
167
168 /// Creates an infinite perspective projection matrix for use with DirectX and WebGPU.
169 ///
170 /// Like `perspective`, but with an infinite value for `far`. Points at distance
171 /// `near` map to depth `0`; as distance approaches infinity, depth approaches `1`.
172 ///
173 /// Expects a left-handed Y-up view space input.
174 /// Outputs NDC with Z in [0, 1] and Y-up.
175 ///
176 /// # Panics
177 ///
178 /// Will panic if `near` is less than or equal to zero when `glam_assert` is enabled.
179 #[inline]
180 #[must_use]
181 pub fn perspective_infinite(vertical_fov: f32, aspect_ratio: f32, near: f32) -> Mat4 {
182 camera_impl::perspective_infinite::<false, true, false>(vertical_fov, aspect_ratio, near)
183 }
184
185 /// Creates an infinite perspective projection matrix with reversed depth for use with
186 /// DirectX and WebGPU.
187 ///
188 /// Maps `near` to depth `1` and infinity to depth `0`.
189 ///
190 /// Reversed Z improves depth precision when used with a floating-point depth buffer.
191 ///
192 /// Expects a left-handed Y-up view space input.
193 /// Outputs NDC with Z in [0, 1] and Y-up.
194 ///
195 /// # Panics
196 ///
197 /// Will panic if `near` is less than or equal to zero when `glam_assert` is enabled.
198 #[inline]
199 #[must_use]
200 pub fn perspective_infinite_reverse(vertical_fov: f32, aspect_ratio: f32, near: f32) -> Mat4 {
201 camera_impl::perspective_infinite_reverse::<false, false>(vertical_fov, aspect_ratio, near)
202 }
203
204 /// Creates an orthographic projection matrix for use with DirectX and WebGPU.
205 ///
206 /// Expects a left-handed Y-up view space input.
207 /// Outputs NDC with Z in [0, 1] and Y-up.
208 #[inline]
209 #[must_use]
210 pub fn orthographic(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) -> Mat4 {
211 camera_impl::orthographic::<false, true, false>(left, right, bottom, top, near, far)
212 }
213
214 /// Creates a perspective projection from a frustum for use with DirectX and WebGPU.
215 ///
216 /// Expects a left-handed Y-up view space input.
217 /// Outputs NDC with Z in [0, 1] and Y-up.
218 ///
219 /// # Panics
220 ///
221 /// Will panic if `near` or `far` are less than or equal to zero when `glam_assert` is enabled.
222 #[inline]
223 #[must_use]
224 pub fn frustum(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) -> Mat4 {
225 camera_impl::frustum::<false, true, false>(left, right, bottom, top, near, far)
226 }
227}