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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
macro_rules! transform_complete_mod {
($mod:ident) => {
use ::std::iter::Sum;
use $crate::num_traits::{Zero, One, real::Real};
use $crate::ops::*;
use vec::$mod::*;
use quaternion::$mod::*;
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, )]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
pub struct Transform<P,O,S> {
pub position: Vec3<P>,
pub orientation: Quaternion<O>,
pub scale: Vec3<S>,
}
impl<P: Zero, O: Zero + One, S: One> Default for Transform<P,O,S> {
fn default() -> Self {
Self {
position: Vec3::zero(),
orientation: Quaternion::identity(),
scale: Vec3::one(),
}
}
}
impl<P,O,S,Factor> Lerp<Factor> for Transform<P,O,S>
where Factor: Copy + Into<O>,
P: Lerp<Factor,Output=P>,
S: Lerp<Factor,Output=S>,
O: Lerp<O,Output=O> + Real + Sum,
{
type Output = Self;
fn lerp_unclamped(a: Self, b: Self, t: Factor) -> Self {
Transform {
position: Lerp::lerp_unclamped(a.position, b.position, t),
orientation: Slerp::slerp_unclamped(a.orientation, b.orientation, t),
scale: Lerp::lerp_unclamped(a.scale, b.scale, t),
}
}
fn lerp_unclamped_precise(a: Self, b: Self, t: Factor) -> Self {
Transform {
position: Lerp::lerp_unclamped_precise(a.position, b.position, t),
orientation: Slerp::slerp_unclamped(a.orientation, b.orientation, t),
scale: Lerp::lerp_unclamped_precise(a.scale, b.scale, t),
}
}
}
impl<'a,P,O,S,Factor> Lerp<Factor> for &'a Transform<P,O,S>
where Factor: Copy + Into<O>,
&'a P: Lerp<Factor,Output=P>,
&'a S: Lerp<Factor,Output=S>,
O: Lerp<O,Output=O> + Real + Sum,
{
type Output = Transform<P,O,S>;
fn lerp_unclamped(a: Self, b: Self, t: Factor) -> Self::Output {
Transform {
position: Lerp::lerp_unclamped(&a.position, &b.position, t),
orientation: Slerp::slerp_unclamped(&a.orientation, &b.orientation, t),
scale: Lerp::lerp_unclamped(&a.scale, &b.scale, t),
}
}
fn lerp_unclamped_precise(a: Self, b: Self, t: Factor) -> Self::Output {
Transform {
position: Lerp::lerp_unclamped_precise(&a.position, &b.position, t),
orientation: Slerp::slerp_unclamped(&a.orientation, &b.orientation, t),
scale: Lerp::lerp_unclamped_precise(&a.scale, &b.scale, t),
}
}
}
}
}
#[cfg(all(nightly, feature="repr_simd"))]
pub mod repr_simd {
transform_complete_mod!(repr_simd);
}
pub mod repr_c {
transform_complete_mod!(repr_c);
}
pub use self::repr_c::*;