rust/hwphysics/src/physics.rs
changeset 15381 52844baced17
parent 15380 6e3e5be8b2e2
child 15382 6ad92b6ac43c
--- a/rust/hwphysics/src/physics.rs	Wed Aug 28 23:06:34 2019 +0300
+++ b/rust/hwphysics/src/physics.rs	Thu Aug 29 00:06:31 2019 +0300
@@ -12,10 +12,6 @@
 #[repr(transparent)]
 pub struct VelocityData(pub FPPoint);
 
-pub struct PhysicsProcessor {
-    position_updates: PositionUpdates,
-}
-
 pub struct PositionUpdates {
     pub gear_ids: Vec<GearId>,
     pub shifts: Vec<(FPPoint, FPPoint)>,
@@ -48,6 +44,11 @@
     }
 }
 
+pub struct PhysicsProcessor {
+    gravity: FPNum,
+    position_updates: PositionUpdates,
+}
+
 impl PhysicsProcessor {
     pub fn register_components(data: &mut GearDataManager) {
         data.register::<PositionData>();
@@ -56,6 +57,7 @@
 
     pub fn new() -> Self {
         Self {
+            gravity: fp!(100),
             position_updates: PositionUpdates::new(64),
         }
     }
@@ -68,6 +70,7 @@
             |gear_id, (pos, vel): (&mut PositionData, &mut VelocityData)| {
                 if !vel.0.is_zero() {
                     let old_pos = pos.0;
+                    vel.0 -= self.gravity * fp_step;
                     pos.0 += vel.0 * fp_step;
                     self.position_updates.push(gear_id, &old_pos, &pos.0)
                 }