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//! Functions returning `DMat4`, `DAffine3`, or
12//! similar return a full view transform (rotation and translation).
13//! Functions returning `DMat3`, or `DQuat` return
14//! only the view rotation.
15
16use crate::{dcamera::camera_impl, DAffine3, DMat3, DMat4, DQuat, DVec3};
17
18/// Returns a `DMat4` 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: DVec3, center: DVec3, up: DVec3) -> DMat4 {
28    look_to_mat4(eye, (center - eye).normalize(), up)
29}
30
31/// Returns a `DMat4` 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: DVec3, dir: DVec3, up: DVec3) -> DMat4 {
41    camera_impl::look_to_mat4::<false>(eye, dir, up)
42}
43
44/// Returns an `DAffine3` 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: DVec3, center: DVec3, up: DVec3) -> DAffine3 {
54    look_to_affine3(eye, (center - eye).normalize(), up)
55}
56
57/// Returns an `DAffine3` 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: DVec3, dir: DVec3, up: DVec3) -> DAffine3 {
67    camera_impl::look_to_affine3::<false>(eye, dir, up)
68}
69
70/// Returns a `DMat3` view rotation (no translation) 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_mat3(eye: DVec3, center: DVec3, up: DVec3) -> DMat3 {
80    look_to_mat3((center - eye).normalize(), up)
81}
82
83/// Returns a `DMat3` view rotation (no translation) from 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_mat3(dir: DVec3, up: DVec3) -> DMat3 {
93    camera_impl::look_to_mat3::<false>(dir, up)
94}
95
96/// Returns a `DQuat` view rotation 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_quat(eye: DVec3, center: DVec3, up: DVec3) -> DQuat {
106    look_to_quat((center - eye).normalize(), up)
107}
108
109/// Returns a `DQuat` view rotation 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_quat(dir: DVec3, up: DVec3) -> DQuat {
119    camera_impl::look_to_quat::<false>(dir, up)
120}