Skip to main content

gizmo_physics_rigid/components/
velocity.rs

1use gizmo_math::Vec3;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5pub struct Velocity {
6    pub linear: Vec3,
7    pub angular: Vec3,
8    /// Önceki karenin hızı (Diferansiyel hesap / Heun's method için)
9    #[serde(skip)]
10    pub pre_linear: Vec3,
11    #[serde(skip)]
12    pub pre_angular: Vec3,
13}
14
15impl Velocity {
16    pub fn new(linear: Vec3) -> Self {
17        Self {
18            linear,
19            angular: Vec3::ZERO,
20            pre_linear: linear,
21            pre_angular: Vec3::ZERO,
22        }
23    }
24
25    pub fn with_angular(mut self, angular: Vec3) -> Self {
26        self.angular = angular;
27        self.pre_angular = angular;
28        self
29    }
30}
31
32impl Default for Velocity {
33    fn default() -> Self {
34        Self::new(Vec3::ZERO)
35    }
36}
37
38gizmo_core::impl_component!(Velocity);