Skip to main content

glam/dcamera/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 `DMat4`, `DAffine3`, or
15//! similar return a full view transform (rotation and translation).
16//! Functions returning `DMat3`, or `DQuat` return
17//! only the view rotation.
18
19use crate::{DAffine3, DMat3, DMat4, DQuat, DVec3, dcamera::camera_impl};
20
21/// Returns a `DMat4` 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: DVec3, center: DVec3, up: DVec3) -> DMat4 {
33    look_to_mat4(eye, (center - eye).normalize(), up)
34}
35
36/// Returns a `DMat4` 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: DVec3, dir: DVec3, up: DVec3) -> DMat4 {
48    camera_impl::look_to_mat4::<false>(eye, dir, up)
49}
50
51/// Returns an `DAffine3` 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: DVec3, center: DVec3, up: DVec3) -> DAffine3 {
63    look_to_affine3(eye, (center - eye).normalize(), up)
64}
65
66/// Returns an `DAffine3` 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: DVec3, dir: DVec3, up: DVec3) -> DAffine3 {
78    camera_impl::look_to_affine3::<false>(eye, dir, up)
79}
80
81/// Returns a `DMat3` view rotation (no translation) 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_mat3(eye: DVec3, center: DVec3, up: DVec3) -> DMat3 {
93    look_to_mat3((center - eye).normalize(), up)
94}
95
96/// Returns a `DMat3` view rotation (no translation) from 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_mat3(dir: DVec3, up: DVec3) -> DMat3 {
108    camera_impl::look_to_mat3::<false>(dir, up)
109}
110
111/// Returns a `DQuat` view rotation 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_quat(eye: DVec3, center: DVec3, up: DVec3) -> DQuat {
123    look_to_quat((center - eye).normalize(), up)
124}
125
126/// Returns a `DQuat` view rotation 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_quat(dir: DVec3, up: DVec3) -> DQuat {
138    camera_impl::look_to_quat::<false>(dir, up)
139}