private Rect Simulate(List <IHit> hits, List <IObstacle> ignoring, IBox box, Rect origin, Rect destination, Func <ICollision, ICollisionResponse> filter) { IHit nearest = this.Hit(origin, destination, ignoring); if (nearest != null) { hits.Add(nearest); Rect impact = new Rect(nearest.Position, origin.Size); AABB.Collision collision = new AABB.Collision() { Box = box, Hit = nearest, Goal = destination, Origin = origin }; ICollisionResponse response = filter(collision); ignoring.Add(nearest.Box); if (response != null && destination != response.Destination) { return(this.Simulate(hits, ignoring, box, impact, response.Destination, filter));//hit something; estimate based on the new trajectory } else { return(this.Simulate(hits, ignoring, box, origin, destination, filter));//didn't hit something; estimate based on the current trajectory again } } return(destination); }
public virtual void RegisterCollisionResponse(string key, ICollisionResponse colResponse) { key = key.ToUpper(); if(!_collisionResponseTable.ContainsKey(key)) _collisionResponseTable.Add(key, new List<ICollisionResponse>()); _collisionResponseTable[key].Add(colResponse); }
public virtual void RemoveCollisionResponse(string key, ICollisionResponse colResponse) { if(_collisionResponseTable.ContainsKey(key)) { _collisionResponseTable[key].Remove(colResponse); if(_collisionResponseTable[key].Count == 0) _collisionResponseTable.Remove(key); } }