예제 #1
0
bool Geometric2DCollection::Collides(const Geometric2DCollection& geom,int obstacle) const
{
  for(size_t i=0;i<geom.aabbs.size();i++) {
    Box2D box; box.set(geom.aabbs[i]);
    if(Collides(box,obstacle)) return true;
  }
  for(size_t i=0;i<geom.boxes.size();i++)
    if(Collides(geom.boxes[i],obstacle)) return true;
  for(size_t i=0;i<geom.circles.size();i++)
    if(Collides(geom.circles[i],obstacle)) return true;
  for(size_t i=0;i<geom.triangles.size();i++)
    if(Collides(geom.triangles[i],obstacle)) return true;
  return false;
}
예제 #2
0
bool Geometric2DCollection::Collides(const Triangle2D& tri) const
{
  for(size_t i=0;i<aabbs.size();i++) {
    Box2D box; box.set(aabbs[i]);
    if(box.intersects(tri)) return true;
  }
  for(size_t i=0;i<boxes.size();i++)
    if(boxes[i].intersects(tri)) return true;
  for(size_t i=0;i<circles.size();i++)
    if(tri.closestPoint(circles[i].center).distanceSquared(circles[i].center) < Sqr(circles[i].radius)) return true;
  for(size_t i=0;i<triangles.size();i++)
    if(tri.intersects(triangles[i])) return true;
  return false;
}
예제 #3
0
bool Geometric2DCollection::Collides(const Triangle2D& t,int obstacle) const
{
  Type type=ObstacleType(obstacle);
  int index = ObstacleIndex(obstacle);
  switch(type) {
  case AABB:
    {
      Box2D box; box.set(aabbs[index]);
      return box.intersects(t);
    }
  case Triangle:
    return triangles[index].intersects(t);
  case Box:
    return boxes[index].intersects(t);
  case Circle:
    {
      return (t.closestPoint(circles[index].center).distanceSquared(circles[index].center) < Sqr(circles[index].radius));
    }
  }
  abort();
  return false;
}