add gravity
authoralfadur
Thu, 29 Aug 2019 00:06:31 +0300
changeset 15386 52844baced17
parent 15385 6e3e5be8b2e2
child 15387 6ad92b6ac43c
add gravity
rust/hwphysics/src/common.rs
rust/hwphysics/src/data.rs
rust/hwphysics/src/lib.rs
rust/hwphysics/src/physics.rs
--- a/rust/hwphysics/src/common.rs	Wed Aug 28 23:06:34 2019 +0300
+++ b/rust/hwphysics/src/common.rs	Thu Aug 29 00:06:31 2019 +0300
@@ -1,9 +1,5 @@
 use fpnum::FPNum;
-use std::{
-    collections::BinaryHeap,
-    num::NonZeroU16,
-    ops::{Add, Index, IndexMut},
-};
+use std::{collections::BinaryHeap, num::NonZeroU16, ops::Add};
 
 pub type GearId = NonZeroU16;
 
--- a/rust/hwphysics/src/data.rs	Wed Aug 28 23:06:34 2019 +0300
+++ b/rust/hwphysics/src/data.rs	Thu Aug 29 00:06:31 2019 +0300
@@ -2,7 +2,6 @@
 use std::{
     any::TypeId,
     fmt::{Debug, Error, Formatter},
-    io::Write,
     mem::{size_of, MaybeUninit},
     num::NonZeroU16,
     ptr::{copy_nonoverlapping, null_mut, NonNull},
--- a/rust/hwphysics/src/lib.rs	Wed Aug 28 23:06:34 2019 +0300
+++ b/rust/hwphysics/src/lib.rs	Thu Aug 29 00:06:31 2019 +0300
@@ -9,7 +9,7 @@
 use land2d::Land2D;
 
 use crate::{
-    collision::{CollisionData, CollisionProcessor, ContactData},
+    collision::CollisionProcessor,
     common::{GearAllocator, GearId, Millis},
     data::GearDataManager,
     physics::PhysicsProcessor,
--- 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)
                 }