Struct collider::Collider
[−]
[src]
pub struct Collider<P: HbProfile> { /* fields omitted */ }
A structure that tracks hitboxes and returns collide/separate events.
Collider manages events using a "simulation time" that the user updates as necessary.
This time starts at 0.0
.
Methods
impl<P: HbProfile> Collider<P>
[src]
pub fn new() -> Collider<P>
[src]
Constructs a new Collider
instance.
pub fn time(&self) -> f64
[src]
Returns the current simulation time.
pub fn next_time(&self) -> f64
[src]
Returns the time at which self.next()
needs to be called again.
Even if self.next_time() == self.time()
, there is a chance that
calling self.next()
will return None
, having processed an internal event.
Regardless, after self.next()
has been called repeatedly until it
returns None
, then self.next_time()
will be greater than self.time()
again.
This is a fast constant-time operation. The result may be infinity.
pub fn set_time(&mut self, time: f64)
[src]
Advances the simulation time to the given value.
The positions of all hitboxes will be updated based on the velocities of the hitboxes.
Will panic if time
exceeds self.next_time()
.
Will also panic if time
is less than self.time()
(i.e. cannot rewind time).
The hitboxes are updated implicitly, and this is actually a fast constant-time operation.
pub fn next(&mut self) -> Option<(HbEvent, P, P)>
[src]
Processes and returns the next Collide
or Separate
event,
or returns None
if there are no more events that occured at the given time
(although an internal event might have been processed if None
is returned).
Will always return None
if self.next_time() > self.time()
.
The returned value is a tuple, denoting the type of event (Collide
or Separate
)
and the two hitbox profiles involved, in increasing order by HbId
.
pub fn get_hitbox(&self, id: HbId) -> Hitbox
[src]
Returns the current state of the hitbox with the given id
.
pub fn add_hitbox(&mut self, profile: P, hitbox: Hitbox) -> Vec<P>
[src]
Adds a new hitbox to the collider.
The profile
is used to track the hitbox over time;
Collider will return this profile in certain methods,
and the ID in this profile can be used to make updates to the hitbox.
This method will panic if there is an ID clash.
hitbox
is the initial state of the hitbox.
Returns a vector of all hitbox profiles that this new hitbox collided with as it was added. Note that separate collision events will not be generated for these collisions.
pub fn set_hitbox_vel(&mut self, id: HbId, vel: HbVel)
[src]
Updates the velocity information of the hitbox with the given id
.
pub fn remove_hitbox(&mut self, id: HbId) -> Vec<P>
[src]
Removes the hitbox with the given id
from all tracking.
Returns a vector of all hitbox profiles that this hitbox separated from as it was removed. No further events will be generated for this hitbox.
pub fn get_overlaps(&self, id: HbId) -> Vec<P>
[src]
Returns the profiles of all currently tracked overlaps on the hitbox with the given id
.
pub fn is_overlapping(&self, id_1: HbId, id_2: HbId) -> bool
[src]
Returns true if there is a currently tracked overlap between the hitboxes with id_1
and id_2
.
pub fn query_overlaps(&self, shape: &PlacedShape, profile: &P) -> Vec<P>
[src]
Returns the profiles of all hitboxes that overlap the given shape
and interact with the given profile
.