feo_math/rotation/mod.rs
1//! Constructs for representing rotation in 3D space
2
3use crate::{One, Zero, axes::Axes, linear_algebra::vector3::Vector3};
4
5pub mod quaternion;
6pub mod euler;
7pub mod rotor;
8pub mod axes;
9
10use {
11 euler::Euler,
12 rotor::Rotor,
13 quaternion::Quaternion,
14
15 crate::linear_algebra::matrix3::Matrix3,
16};
17
18pub enum RotationTy<T>{
19 Quaternion(Quaternion<T>),
20 Euler(Euler<T>),
21 Rotor(Rotor<T>),
22 Axes(Axes<T>)
23}
24
25pub trait Rotation<T>:
26 Into<Matrix3<T>> +
27 From<Matrix3<T>> +
28 Into<Axes<T>> + From<Axes<T>> +
29 Into<Rotor<T>> + From<Rotor<T>> +
30 Into<Quaternion<T>> + From<Quaternion<T>> where T: One + Zero /* does not mean the same for all */{
31 const X_AXIS: Vector3<T> = Vector3(T::ONE , T::ZERO, T::ZERO);
32 const Y_AXIS: Vector3<T> = Vector3(T::ZERO, T::ONE , T::ZERO);
33 const Z_AXIS: Vector3<T> = Vector3(T::ZERO, T::ZERO, T::ONE );
34
35 /// Generate a rotation for an object at a position look at a point.
36 /// only uses the X and Y rotation axes to arrive at this result
37 /// Z rotation axis
38 /// ```text
39 /// ↻
40 /// | locked Z rotation axis
41 /// | /
42 /// o ---- ⤺
43 /// ```
44 /// # Arguments
45 /// * `pos` - A `Vector3<f32>` representing the position of the object
46 /// * `look_at` - A `Vector3<f32>` representing the position the object is to look at
47 fn look_at_xy(pos: Vector3<T>, look_at: Vector3<T>) -> Self;
48
49 /// Generate a rotation for an object at a position look at a point.
50 /// only uses the X and Z rotation axes to arrive at this result
51 /// Z rotation axis
52 /// ```text
53 /// locked Y rotation axis
54 /// | ⤺
55 /// | /
56 /// o ---- ⤺
57 /// ```
58 /// # Arguments
59 /// * `pos` - A `Vector3<f32>` representing the position of the object
60 /// * `look_at` - A `Vector3<f32>` representing the position the object is to look at
61 fn look_at_xz(pos: Vector3<T>, look_at: Vector3<T>) -> Self;
62
63 /// Generate a rotation for an object at a position look at a point.
64 /// only uses the Z and Y rotation axes to arrive at this result
65 /// Z rotation axis
66 /// ```text
67 /// ↻
68 /// | ⤺
69 /// | /
70 /// o ---- locked X rotation axis
71 /// ```
72 /// # Arguments
73 /// * `pos` - A `Vector3<f32>` representing the position of the object
74 /// * `look_at` - A `Vector3<f32>` representing the position the object is to look at
75 fn look_at_yz(pos: Vector3<T>, look_at: Vector3<T>) -> Self;
76
77 /// Generate a rotation for an object at a position look at a point.
78 /// only uses the Z and Y rotation axes to arrive at this result
79 /// Z rotation axis
80 /// ```text
81 /// ↻
82 /// | ⤺
83 /// | /
84 /// o ---- ⤺
85 /// \
86 /// locked_axis
87 /// ```
88 /// # Arguments
89 /// * `pos` - A `Vector3<f32>` representing the position of the object
90 /// * `look_at` - A `Vector3<f32>` representing the position the object is to look at
91 fn look_at_lock(pos: Vector3<T>, look_at: Vector3<T>, locked_axis: Vector3<T>) -> Self;
92
93 /// Camera Objects look along the -Z axis so the look_at function for a camera object
94 /// needs to be modified a little. flipping the pos and the look_at should do the trick.
95 /// TODO: finish comments watch out bc z is reversed and things may get wonky
96 /// ```text
97 /// ^ Z
98 /// |
99 /// |
100 /// Y• C ------> X
101 /// / \
102 /// / \
103 /// / \
104 /// ```
105 /// # Arguments
106 /// * `pos` - A `Vector3<f32>` representing the position of the camera
107 /// * `look_at` - A `Vector3<f32>` representing the position the camera is to look at
108 fn camera_look_at_xy(pos: Vector3<T>, look_at: Vector3<T>) -> Self;
109 fn camera_look_at_xz(pos: Vector3<T>, look_at: Vector3<T>) -> Self;
110 fn camera_look_at_yz(pos: Vector3<T>, look_at: Vector3<T>) -> Self;
111 fn camera_look_at_lock(pos: Vector3<T>, look_at: Vector3<T>, locked_axis: Vector3<T>) -> Self;
112}
113
114