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