Пример #1
0
bool Geometric2DCollection::Collides(const Box2D& box) const
{
  for(size_t i=0;i<aabbs.size();i++)
    if(box.intersects(aabbs[i])) return true;
  for(size_t i=0;i<boxes.size();i++) 
    if(box.intersects(boxes[i])) return true;
  for(size_t i=0;i<circles.size();i++)
    if(box.intersects(circles[i])) return true;
  for(size_t i=0;i<triangles.size();i++)
    if(box.intersects(triangles[i])) return true;
  return false;
}
Пример #2
0
bool Geometric2DCollection::Collides(const Box2D& box,int obstacle) const
{
  Type type=ObstacleType(obstacle);
  int index = ObstacleIndex(obstacle);
  switch(type) {
  case AABB:
    return box.intersects(aabbs[index]);
  case Triangle:
    return box.intersects(triangles[index]);
  case Box:
    return box.intersects(boxes[index]);
  case Circle:
    return box.intersects(circles[index]);
  }
  abort();
  return false;
}
Пример #3
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;
}
Пример #4
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;
}