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 when `glam_assert` is enabled.
25#[inline]
26#[must_use]
27pub fn look_at_mat4(eye: Vec3, center: Vec3, up: Vec3) -> Mat4 {
28    look_to_mat4(eye, (center - eye).normalize(), up)
29}
30
31/// Returns a `Mat4` view matrix from eye, forward direction, and up.
32///
33/// Transforms left-handed world space points into left-handed Y-up view space.
34///
35/// # Panics
36///
37/// Will panic if `dir` or `up` are not normalized when `glam_assert` is enabled.
38#[inline]
39#[must_use]
40pub fn look_to_mat4(eye: Vec3, dir: Vec3, up: Vec3) -> Mat4 {
41    camera_impl::look_to_mat4::<false>(eye, dir, up)
42}
43
44/// Returns an `Affine3` view transform from eye, focal point, and up.
45///
46/// Transforms left-handed world space points into left-handed Y-up view space.
47///
48/// # Panics
49///
50/// Will panic if `up` is not normalized when `glam_assert` is enabled.
51#[inline]
52#[must_use]
53pub fn look_at_affine3(eye: Vec3, center: Vec3, up: Vec3) -> Affine3 {
54    look_to_affine3(eye, (center - eye).normalize(), up)
55}
56
57/// Returns an `Affine3` view transform from eye, forward direction, and up.
58///
59/// Transforms left-handed world space points into left-handed Y-up view space.
60///
61/// # Panics
62///
63/// Will panic if `dir` or `up` are not normalized when `glam_assert` is enabled.
64#[inline]
65#[must_use]
66pub fn look_to_affine3(eye: Vec3, dir: Vec3, up: Vec3) -> Affine3 {
67    camera_impl::look_to_affine3::<false>(eye, dir, up)
68}
69
70/// Returns an `Affine3A` view transform from eye, focal point, and up.
71///
72/// Transforms left-handed world space points into left-handed Y-up view space.
73///
74/// # Panics
75///
76/// Will panic if `up` is not normalized when `glam_assert` is enabled.
77#[inline]
78#[must_use]
79pub fn look_at_affine3a(eye: Vec3, center: Vec3, up: Vec3) -> Affine3A {
80    look_to_affine3a(eye, (center - eye).normalize(), up)
81}
82
83/// Returns an `Affine3A` view transform from eye, forward direction, and up.
84///
85/// Transforms left-handed world space points into left-handed Y-up view space.
86///
87/// # Panics
88///
89/// Will panic if `dir` or `up` are not normalized when `glam_assert` is enabled.
90#[inline]
91#[must_use]
92pub fn look_to_affine3a(eye: Vec3, dir: Vec3, up: Vec3) -> Affine3A {
93    camera_impl::look_to_affine3a::<false>(eye, dir, up)
94}
95
96/// Returns a `Mat3` view rotation (no translation) from eye, focal point, and up.
97///
98/// Transforms left-handed world space points into left-handed Y-up view space.
99///
100/// # Panics
101///
102/// Will panic if `up` is not normalized when `glam_assert` is enabled.
103#[inline]
104#[must_use]
105pub fn look_at_mat3(eye: Vec3, center: Vec3, up: Vec3) -> Mat3 {
106    look_to_mat3((center - eye).normalize(), up)
107}
108
109/// Returns a `Mat3` view rotation (no translation) from direction and up.
110///
111/// Transforms left-handed world space points into left-handed Y-up view space.
112///
113/// # Panics
114///
115/// Will panic if `dir` or `up` are not normalized when `glam_assert` is enabled.
116#[inline]
117#[must_use]
118pub fn look_to_mat3(dir: Vec3, up: Vec3) -> Mat3 {
119    camera_impl::look_to_mat3::<false>(dir, up)
120}
121
122/// Returns a `Mat3A` view rotation (no translation) from eye, focal point, and up.
123///
124/// Transforms left-handed world space points into left-handed Y-up view space.
125///
126/// # Panics
127///
128/// Will panic if `up` is not normalized when `glam_assert` is enabled.
129#[inline]
130#[must_use]
131pub fn look_at_mat3a(eye: Vec3, center: Vec3, up: Vec3) -> Mat3A {
132    look_to_mat3a((center - eye).normalize(), up)
133}
134
135/// Returns a `Mat3A` view rotation (no translation) from direction and up.
136///
137/// Transforms left-handed world space points into left-handed Y-up view space.
138///
139/// # Panics
140///
141/// Will panic if `dir` or `up` are not normalized when `glam_assert` is enabled.
142#[inline]
143#[must_use]
144pub fn look_to_mat3a(dir: Vec3, up: Vec3) -> Mat3A {
145    camera_impl::look_to_mat3a::<false>(dir, up)
146}
147
148/// Returns a `Quat` view rotation from eye, focal point, and up.
149///
150/// Transforms left-handed world space points into left-handed Y-up view space.
151///
152/// # Panics
153///
154/// Will panic if `up` is not normalized when `glam_assert` is enabled.
155#[inline]
156#[must_use]
157pub fn look_at_quat(eye: Vec3, center: Vec3, up: Vec3) -> Quat {
158    look_to_quat((center - eye).normalize(), up)
159}
160
161/// Returns a `Quat` view rotation from direction and up.
162///
163/// Transforms left-handed world space points into left-handed Y-up view space.
164///
165/// # Panics
166///
167/// Will panic if `dir` or `up` are not normalized when `glam_assert` is enabled.
168#[inline]
169#[must_use]
170pub fn look_to_quat(dir: Vec3, up: Vec3) -> Quat {
171    camera_impl::look_to_quat::<false>(dir, up)
172}