rust/hwphysics/src/collision.rs
changeset 15263 24828281c9c5
parent 15261 501dfa1c8deb
child 15266 b58f98bbc120
equal deleted inserted replaced
15262:d8c4fd911b37 15263:24828281c9c5
    77 
    77 
    78     detected_collisions: DetectedCollisions,
    78     detected_collisions: DetectedCollisions,
    79 }
    79 }
    80 
    80 
    81 pub struct DetectedCollisions {
    81 pub struct DetectedCollisions {
    82     pub pairs: Vec<(GearId, GearId)>,
    82     pub pairs: Vec<(GearId, Option<GearId>)>,
    83     pub positions: Vec<Point>,
    83     pub positions: Vec<Point>,
    84 }
    84 }
    85 
    85 
    86 impl DetectedCollisions {
    86 impl DetectedCollisions {
    87     pub fn new(capacity: usize) -> Self {
    87     pub fn new(capacity: usize) -> Self {
    89             pairs: Vec::with_capacity(capacity),
    89             pairs: Vec::with_capacity(capacity),
    90             positions: Vec::with_capacity(capacity),
    90             positions: Vec::with_capacity(capacity),
    91         }
    91         }
    92     }
    92     }
    93 
    93 
    94     pub fn push(&mut self, contact_gear_id1: GearId, contact_gear_id2: GearId, position: &FPPoint) {
    94     pub fn push(
       
    95         &mut self,
       
    96         contact_gear_id1: GearId,
       
    97         contact_gear_id2: Option<GearId>,
       
    98         position: &FPPoint,
       
    99     ) {
    95         self.pairs.push((contact_gear_id1, contact_gear_id2));
   100         self.pairs.push((contact_gear_id1, contact_gear_id2));
    96         self.positions.push(fppoint_round(&position));
   101         self.positions.push(fppoint_round(&position));
    97     }
   102     }
    98 }
   103 }
    99 
   104 
   117                 .bounds
   122                 .bounds
   118                 .rows()
   123                 .rows()
   119                 .any(|(y, r)| (&land[y][r]).iter().any(|v| *v != 0))
   124                 .any(|(y, r)| (&land[y][r]).iter().any(|v| *v != 0))
   120             {
   125             {
   121                 self.detected_collisions
   126                 self.detected_collisions
   122                     .push(gear_id, 0, &collision.bounds.center)
   127                     .push(gear_id, None, &collision.bounds.center)
   123             }
   128             }
   124         }
   129         }
   125     }
   130     }
   126 }
   131 }
   127 
   132