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
//! Constant linear and angular force generator.

use alga::general::Real;

use math::{Vector, Orientation};
use object::RigidBody;
use integration::Integrator;

/// A constant linear and angular force generator.
pub struct BodyForceGenerator<N: Real> {
    lin_acc: Vector<N>,
    ang_acc: Orientation<N>
}

impl<N: Real> BodyForceGenerator<N> {
    /// Creates a new `BodyForceGenerator`.
    ///
    /// # Arguments:
    ///
    /// * `lin_acc` - the linear acceleration to apply to every body on the scene.
    /// * `ang_acc` - the angular acceleration to apply to every body on the scene.
    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> {
    /// The linear acceleration applied by this force generator.
    #[inline]
    pub fn lin_acc(&self) -> Vector<N> {
        self.lin_acc.clone()
    }

    /// Sets the linear acceleration applied by this force generator.
    #[inline]
    pub fn set_lin_acc(&mut self, lin_acc: Vector<N>) {
        self.lin_acc = lin_acc;
    }

    /// The angular acceleration applied by this force generator.
    #[inline]
    pub fn ang_acc(&self) -> Orientation<N> {
        self.ang_acc.clone()
    }

    /// Sets the angular acceleration applied by this force generator.
    #[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());
        //rb.set_ang_acc(self.ang_acc.clone());
    }
}