use prelude::*;
use ami::*;
use constants;
pub struct RigidBody {
#[allow(unused)] mass: Mass,
force: Vector, spin: Rotation, bbox: BBox,
position: Vector, rotation: Rotation, }
impl Collider for RigidBody {
fn bbox(&self) -> BBox {
self.bbox + self.position
}
}
impl RigidBody {
pub fn new(mass: Mass, bbox: BBox, position: Vector,
rotation: Rotation) -> Self
{
RigidBody {
mass, force: vector!(), bbox, position,
spin: Rotation::identity(), rotation,
}
}
pub fn apply_gravity(&mut self) {
self.apply_force(Vector{ x:0.0, y:constants::GRAVITY, z:0.0 });
}
pub fn apply_force(&mut self, force: Vector) {
self.force += force;
}
pub fn apply_spin(&mut self, spin: Rotation) {
self.spin = self.spin.then(spin);
}
pub fn stop_force(&mut self) {
self.force = vector!();
}
pub fn stop_spin(&mut self) {
self.spin = Rotation::identity();
}
pub fn update(&mut self, time: f32) -> Matrix {
self.position += self.force * time;
self.rotation.then(self.spin * time);
matrix!().rt(self.rotation,self.position)
}
}