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
use ncollide::math::Scalar;
use math::Matrix;
use detection::joint::anchor::Anchor;
use detection::joint::joint::Joint;
pub struct Fixed<N: Scalar> {
up_to_date: bool,
anchor1: Anchor<N, Matrix<N>>,
anchor2: Anchor<N, Matrix<N>>,
}
impl<N: Scalar> Fixed<N> {
pub fn new(anchor1: Anchor<N, Matrix<N>>, anchor2: Anchor<N, Matrix<N>>) -> Fixed<N> {
Fixed {
up_to_date: false,
anchor1: anchor1,
anchor2: anchor2
}
}
pub fn up_to_date(&self) -> bool {
self.up_to_date
}
#[doc(hidden)]
pub fn update(&mut self) {
self.up_to_date = true
}
pub fn set_local1(&mut self, local1: Matrix<N>) {
if local1 != self.anchor1.position {
self.up_to_date = false;
self.anchor1.position = local1
}
}
pub fn set_local2(&mut self, local2: Matrix<N>) {
if local2 != self.anchor2.position {
self.up_to_date = false;
self.anchor2.position = local2
}
}
}
impl<N: Scalar> Joint<N, Matrix<N>> for Fixed<N> {
#[inline]
fn anchor1(&self) -> &Anchor<N, Matrix<N>> {
&self.anchor1
}
#[inline]
fn anchor2(&self) -> &Anchor<N, Matrix<N>> {
&self.anchor2
}
#[inline]
fn anchor1_pos(&self) -> Matrix<N> {
match self.anchor1.body {
Some(ref b) => {
*b.borrow().position() * self.anchor1.position
},
None => self.anchor1.position.clone()
}
}
#[inline]
fn anchor2_pos(&self) -> Matrix<N> {
match self.anchor2.body {
Some(ref b) => {
*b.borrow().position() * self.anchor2.position
},
None => self.anchor2.position.clone()
}
}
}