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