rust/hwphysics/src/physics.rs
changeset 15388 701ad89a9f2a
parent 15387 6ad92b6ac43c
child 15397 b387a51705ac
equal deleted inserted replaced
15387:6ad92b6ac43c 15388:701ad89a9f2a
    55         data.register::<VelocityData>();
    55         data.register::<VelocityData>();
    56     }
    56     }
    57 
    57 
    58     pub fn new() -> Self {
    58     pub fn new() -> Self {
    59         Self {
    59         Self {
    60             gravity: fp!(100),
    60             gravity: fp!(1 / 10),
    61             position_updates: PositionUpdates::new(64),
    61             position_updates: PositionUpdates::new(64),
    62         }
    62         }
    63     }
    63     }
    64 
    64 
    65     pub fn process(&mut self, data: &mut GearDataManager, time_step: Millis) -> &PositionUpdates {
    65     pub fn process_single_tick(&mut self, data: &mut GearDataManager) -> &PositionUpdates {
       
    66         self.position_updates.clear();
       
    67 
       
    68         data.iter_id(
       
    69             |gear_id, (pos, vel): (&mut PositionData, &mut VelocityData)| {
       
    70                 let old_pos = pos.0;
       
    71                 vel.0 -= self.gravity;
       
    72                 pos.0 += vel.0;
       
    73                 self.position_updates.push(gear_id, &old_pos, &pos.0)
       
    74             },
       
    75         );
       
    76 
       
    77         &self.position_updates
       
    78     }
       
    79 
       
    80     pub fn process_multiple_ticks(
       
    81         &mut self,
       
    82         data: &mut GearDataManager,
       
    83         time_step: Millis,
       
    84     ) -> &PositionUpdates {
    66         let fp_step = time_step.to_fixed();
    85         let fp_step = time_step.to_fixed();
    67         self.position_updates.clear();
    86         self.position_updates.clear();
    68 
    87 
    69         data.iter_id(
    88         data.iter_id(
    70             |gear_id, (pos, vel): (&mut PositionData, &mut VelocityData)| {
    89             |gear_id, (pos, vel): (&mut PositionData, &mut VelocityData)| {