Skip to main content

resphys/object/
body.rs

1use super::collider_set::ColliderHandle;
2use glam::Vec2;
3
4/// Describes a body.
5///  
6/// It functions as a container for colliders.
7#[derive(Clone, Debug)]
8pub struct Body {
9    pub position: Vec2,
10    /// static body CAN have velocity - it just behaves as if it had infinite mass  
11    /// (this might change with introduction of kinematic body that pushes other objects)  
12    /// and doesn't collide with other static bodies
13    pub velocity: Vec2,
14    /// Type of body - `static` or `kinematic`
15    pub status: BodyStatus,
16    /// Whether colliders of the same body should collide
17    pub self_collide: bool,
18    // cached list of colliders belonging to body
19    pub(crate) colliders: Vec<ColliderHandle>,
20    // the distance body will want to cover during the next step
21    pub(crate) movement: Vec2,
22}
23
24impl Body {
25    pub fn new(position: Vec2, velocity: Vec2, status: BodyStatus, self_collide: bool) -> Self {
26        Self {
27            position,
28            velocity,
29            status,
30            self_collide,
31            colliders: Vec::new(),
32            movement: Vec2::zero(),
33        }
34    }
35}
36/// Status of the body, determines how it's affected by other bodies.
37#[derive(Copy, Clone, Debug)]
38pub enum BodyStatus {
39    /// Even when it moves it never collides with anything.
40    Static,
41    /// Collides with both static and kinematic bodies.
42    Kinematic,
43}