Skip to main content

glam/camera/lh/
view.rs

1// Generated from camera_view.rs.tera template. Edit the template, not the generated file.
2
3//! View (camera) constructors for left-handed world coordinate systems.
4//!
5//! Every function transforms world space points into a left-handed Y-up
6//! view space with X-right and +Z-forward.
7//!
8//! * `look_at_*` targets a focal point (`center`)
9//! * `look_to_*` targets a forward direction (`dir`)
10//!
11//! Functions returning `Mat4`, `Affine3`, `Affine3A`, or
12//! similar return a full view transform (rotation and translation).
13//! Functions returning `Mat3`, `Mat3A`, or `Quat` return
14//! only the view rotation.
15
16use crate::{camera::camera_impl, Affine3, Affine3A, Mat3, Mat3A, Mat4, Quat, Vec3};
17
18/// Returns a `Mat4` view matrix from eye, focal point, and up.
19///
20/// Transforms left-handed world space points into left-handed Y-up view space.
21///
22/// # Panics
23///
24/// Will panic if `up` is not normalized, if `center` is equal to `eye`, or if the view
25/// direction is parallel to `up`, when `glam_assert` is enabled.
26#[inline]
27#[must_use]
28#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
29pub fn look_at_mat4(eye: Vec3, center: Vec3, up: Vec3) -> Mat4 {
30    look_to_mat4(eye, (center - eye).normalize(), up)
31}
32
33/// Returns a `Mat4` view matrix from eye, forward direction, and up.
34///
35/// Transforms left-handed world space points into left-handed Y-up view space.
36///
37/// # Panics
38///
39/// Will panic if `dir` or `up` are not normalized, or if `dir` and `up` are parallel,
40/// when `glam_assert` is enabled.
41#[inline]
42#[must_use]
43#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
44pub fn look_to_mat4(eye: Vec3, dir: Vec3, up: Vec3) -> Mat4 {
45    camera_impl::look_to_mat4::<false>(eye, dir, up)
46}
47
48/// Returns an `Affine3` view transform from eye, focal point, and up.
49///
50/// Transforms left-handed world space points into left-handed Y-up view space.
51///
52/// # Panics
53///
54/// Will panic if `up` is not normalized, if `center` is equal to `eye`, or if the view
55/// direction is parallel to `up`, when `glam_assert` is enabled.
56#[inline]
57#[must_use]
58#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
59pub fn look_at_affine3(eye: Vec3, center: Vec3, up: Vec3) -> Affine3 {
60    look_to_affine3(eye, (center - eye).normalize(), up)
61}
62
63/// Returns an `Affine3` view transform from eye, forward direction, and up.
64///
65/// Transforms left-handed world space points into left-handed Y-up view space.
66///
67/// # Panics
68///
69/// Will panic if `dir` or `up` are not normalized, or if `dir` and `up` are parallel,
70/// when `glam_assert` is enabled.
71#[inline]
72#[must_use]
73#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
74pub fn look_to_affine3(eye: Vec3, dir: Vec3, up: Vec3) -> Affine3 {
75    camera_impl::look_to_affine3::<false>(eye, dir, up)
76}
77
78/// Returns an `Affine3A` view transform from eye, focal point, and up.
79///
80/// Transforms left-handed world space points into left-handed Y-up view space.
81///
82/// # Panics
83///
84/// Will panic if `up` is not normalized, if `center` is equal to `eye`, or if the view
85/// direction is parallel to `up`, when `glam_assert` is enabled.
86#[inline]
87#[must_use]
88#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
89pub fn look_at_affine3a(eye: Vec3, center: Vec3, up: Vec3) -> Affine3A {
90    look_to_affine3a(eye, (center - eye).normalize(), up)
91}
92
93/// Returns an `Affine3A` view transform from eye, forward direction, and up.
94///
95/// Transforms left-handed world space points into left-handed Y-up view space.
96///
97/// # Panics
98///
99/// Will panic if `dir` or `up` are not normalized, or if `dir` and `up` are parallel,
100/// when `glam_assert` is enabled.
101#[inline]
102#[must_use]
103#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
104pub fn look_to_affine3a(eye: Vec3, dir: Vec3, up: Vec3) -> Affine3A {
105    camera_impl::look_to_affine3a::<false>(eye, dir, up)
106}
107
108/// Returns a `Mat3` view rotation (no translation) from eye, focal point, and up.
109///
110/// Transforms left-handed world space points into left-handed Y-up view space.
111///
112/// # Panics
113///
114/// Will panic if `up` is not normalized, if `center` is equal to `eye`, or if the view
115/// direction is parallel to `up`, when `glam_assert` is enabled.
116#[inline]
117#[must_use]
118#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
119pub fn look_at_mat3(eye: Vec3, center: Vec3, up: Vec3) -> Mat3 {
120    look_to_mat3((center - eye).normalize(), up)
121}
122
123/// Returns a `Mat3` view rotation (no translation) from direction and up.
124///
125/// Transforms left-handed world space points into left-handed Y-up view space.
126///
127/// # Panics
128///
129/// Will panic if `dir` or `up` are not normalized, or if `dir` and `up` are parallel,
130/// when `glam_assert` is enabled.
131#[inline]
132#[must_use]
133#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
134pub fn look_to_mat3(dir: Vec3, up: Vec3) -> Mat3 {
135    camera_impl::look_to_mat3::<false>(dir, up)
136}
137
138/// Returns a `Mat3A` view rotation (no translation) from eye, focal point, and up.
139///
140/// Transforms left-handed world space points into left-handed Y-up view space.
141///
142/// # Panics
143///
144/// Will panic if `up` is not normalized, if `center` is equal to `eye`, or if the view
145/// direction is parallel to `up`, when `glam_assert` is enabled.
146#[inline]
147#[must_use]
148#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
149pub fn look_at_mat3a(eye: Vec3, center: Vec3, up: Vec3) -> Mat3A {
150    look_to_mat3a((center - eye).normalize(), up)
151}
152
153/// Returns a `Mat3A` view rotation (no translation) from direction and up.
154///
155/// Transforms left-handed world space points into left-handed Y-up view space.
156///
157/// # Panics
158///
159/// Will panic if `dir` or `up` are not normalized, or if `dir` and `up` are parallel,
160/// when `glam_assert` is enabled.
161#[inline]
162#[must_use]
163#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
164pub fn look_to_mat3a(dir: Vec3, up: Vec3) -> Mat3A {
165    camera_impl::look_to_mat3a::<false>(dir, up)
166}
167
168/// Returns a `Quat` view rotation from eye, focal point, and up.
169///
170/// Transforms left-handed world space points into left-handed Y-up view space.
171///
172/// # Panics
173///
174/// Will panic if `up` is not normalized, if `center` is equal to `eye`, or if the view
175/// direction is parallel to `up`, when `glam_assert` is enabled.
176#[inline]
177#[must_use]
178#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
179pub fn look_at_quat(eye: Vec3, center: Vec3, up: Vec3) -> Quat {
180    look_to_quat((center - eye).normalize(), up)
181}
182
183/// Returns a `Quat` view rotation from direction and up.
184///
185/// Transforms left-handed world space points into left-handed Y-up view space.
186///
187/// # Panics
188///
189/// Will panic if `dir` or `up` are not normalized, or if `dir` and `up` are parallel,
190/// when `glam_assert` is enabled.
191#[inline]
192#[must_use]
193#[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
194pub fn look_to_quat(dir: Vec3, up: Vec3) -> Quat {
195    camera_impl::look_to_quat::<false>(dir, up)
196}