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
use alga::general::Real;
use math::{Vector, Orientation};
use object::RigidBody;
use integration::Integrator;
pub struct BodyForceGenerator<N: Real> {
lin_acc: Vector<N>,
ang_acc: Orientation<N>
}
impl<N: Real> BodyForceGenerator<N> {
pub fn new(lin_acc: Vector<N>, ang_acc: Orientation<N>) -> BodyForceGenerator<N> {
BodyForceGenerator {
lin_acc: lin_acc,
ang_acc: ang_acc
}
}
}
impl<N: Real> BodyForceGenerator<N> {
#[inline]
pub fn lin_acc(&self) -> Vector<N> {
self.lin_acc.clone()
}
#[inline]
pub fn set_lin_acc(&mut self, lin_acc: Vector<N>) {
self.lin_acc = lin_acc;
}
#[inline]
pub fn ang_acc(&self) -> Orientation<N> {
self.ang_acc.clone()
}
#[inline]
pub fn set_ang_acc(&mut self, ang_acc: Orientation<N>) {
self.ang_acc = ang_acc;
}
}
impl<N: Real> Integrator<N, RigidBody<N>> for BodyForceGenerator<N> {
#[inline]
fn update(&mut self, _: N, rb: &mut RigidBody<N>) {
rb.set_gravity(self.lin_acc.clone());
}
}