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
extern crate cgmath;
extern crate collision;
use cgmath::{BaseFloat, Decomposed, EuclideanSpace, One, Rotation, Transform};
pub use collision::{Interpolate, TranslationInterpolate};
pub trait Pose<P, R>: Transform<P>
where
P: EuclideanSpace,
{
fn new(position: P, rotation: R) -> Self;
fn set_rotation(&mut self, rotation: R);
fn set_position(&mut self, position: P);
fn rotation(&self) -> R;
fn position(&self) -> P;
}
pub trait PhysicsTime<S> {
fn delta_seconds(&self) -> S;
}
impl<P, R> Pose<P, R> for Decomposed<P::Diff, R>
where
P: EuclideanSpace,
P::Scalar: BaseFloat,
R: Rotation<P>,
{
fn new(position: P, rotation: R) -> Self {
Decomposed {
rot: rotation,
disp: position.to_vec(),
scale: P::Scalar::one(),
}
}
fn set_rotation(&mut self, rotation: R) {
self.rot = rotation;
}
fn set_position(&mut self, position: P) {
self.disp = position.to_vec();
}
fn rotation(&self) -> R {
self.rot
}
fn position(&self) -> P {
P::from_vec(self.disp)
}
}