linear_sim/
force.rs

1//! Simulation force entities
2
3use enumflags2::bitflags;
4#[cfg(feature = "derive_serdes")]
5use serde::{Deserialize, Serialize};
6
7use crate::{math, object};
8
9/// Force interface trait
10pub trait Force {
11  fn impulse <O : object::Inertial> (&self,
12    object : &O, step : u64, duration : f64) -> math::Vector3 <f64>;
13}
14
15/// Bitflags for specifying certain forces
16#[derive(Copy, Clone, Debug)]
17#[bitflags]
18#[repr(u8)]
19pub enum Flag {
20  Gravity = 0b_0000_0001
21}
22
23/// A gravitational field.
24///
25/// This is intended to imitate a gravitational field such as that found on the
26/// surface of the earth where objects are small enough that their relative mass
27/// is negligable, resulting in a constant acceleration for all objects.
28#[cfg_attr(feature = "derive_serdes", derive(Deserialize, Serialize))]
29#[derive(Clone, Debug, PartialEq)]
30pub struct Gravity {
31  pub acceleration : math::Vector3 <f64>
32}
33
34impl Force for Gravity {
35  fn impulse <O : object::Inertial> (&self,
36    object : &O, _step : u64, duration : f64) -> math::Vector3 <f64>
37  {
38    duration * object.mass().mass() * self.acceleration
39  }
40}