veloren/common/src/comp/phys.rs

106 lines
2.5 KiB
Rust
Raw Normal View History

use crate::{sync::Uid, util::Dir};
use serde::{Deserialize, Serialize};
use specs::{Component, FlaggedStorage, NullStorage};
use specs_idvs::IdvStorage;
2019-07-29 19:54:58 +00:00
use vek::*;
2019-01-02 19:22:01 +00:00
// Position
#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
2019-01-02 19:22:01 +00:00
pub struct Pos(pub Vec3<f32>);
impl Component for Pos {
type Storage = IdvStorage<Self>;
2019-01-02 19:22:01 +00:00
}
// Velocity
#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
2019-01-02 19:22:01 +00:00
pub struct Vel(pub Vec3<f32>);
impl Component for Vel {
type Storage = IdvStorage<Self>;
2019-01-02 19:22:01 +00:00
}
// Orientation
#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Ori(pub Dir);
2019-01-02 19:22:01 +00:00
2020-07-15 15:45:47 +00:00
impl Ori {
pub fn vec(&self) -> &Vec3<f32> { &self.0.vec() }
}
impl Component for Ori {
type Storage = IdvStorage<Self>;
}
// Scale
#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Scale(pub f32);
impl Component for Scale {
type Storage = FlaggedStorage<Self, IdvStorage<Self>>;
}
2019-09-25 20:22:39 +00:00
// Mass
#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Mass(pub f32);
impl Component for Mass {
type Storage = FlaggedStorage<Self, IdvStorage<Self>>;
2019-09-25 20:22:39 +00:00
}
// Mass
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Collider {
Box { radius: f32, z_min: f32, z_max: f32 },
Point,
}
impl Component for Collider {
type Storage = FlaggedStorage<Self, IdvStorage<Self>>;
}
#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Gravity(pub f32);
impl Component for Gravity {
type Storage = FlaggedStorage<Self, IdvStorage<Self>>;
}
#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Sticky;
impl Component for Sticky {
type Storage = FlaggedStorage<Self, NullStorage<Self>>;
}
// PhysicsState
#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct PhysicsState {
pub on_ground: bool,
pub on_ceiling: bool,
pub on_wall: Option<Vec3<f32>>,
2019-09-21 12:43:24 +00:00
pub touch_entity: Option<Uid>,
pub in_fluid: bool,
}
2020-07-05 14:06:01 +00:00
impl PhysicsState {
pub fn on_surface(&self) -> Option<Vec3<f32>> {
self.on_ground
.then_some(-Vec3::unit_z())
.or_else(|| self.on_ceiling.then_some(Vec3::unit_z()))
.or(self.on_wall)
}
}
impl Component for PhysicsState {
type Storage = FlaggedStorage<Self, IdvStorage<Self>>;
}
// ForceUpdate
#[derive(Copy, Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ForceUpdate;
impl Component for ForceUpdate {
type Storage = NullStorage<Self>;
}