예제 #1
0
 public CollisionCircle(CollisionCircle circle)
 {
     _center = circle.getCenter();
     _radius = circle.getRadius();
     _object = circle.getObject();
     _type   = circle.getType();
 }
예제 #2
0
        //Test where collisioncircle fits
        private int GetIndex(CollisionCircle circle)
        {
            //parent is -1 if circle cannot fit into the nodes it will belong to this leaf
            int index = -1;

            //test if the circle fits in the top quadrant of the rect
            bool top = (circle.getCenter().y + circle.getRadius() < _limits.getCenter().y + _limits.getHeight() / 2 && circle.getCenter().y - circle.getRadius() > _limits.getCenter().y);

            bool bottom = (circle.getCenter().y + circle.getRadius() < _limits.getCenter().y&& circle.getCenter().y - circle.getRadius() > _limits.getCenter().y - _limits.getHeight() / 2);

            //test if the circle fits completely in the left quadrant
            if (circle.getCenter().x + circle.getRadius() < _limits.getCenter().x&&
                circle.getCenter().x - circle.getRadius() > _limits.getCenter().x - _limits.getWidth() / 2)
            {
                if (top)
                {
                    index = 0;
                }
                else if (bottom)
                {
                    index = 2;
                }
            }
            //else test if it fits completely in the right quadrant
            else if (circle.getCenter().x + circle.getRadius() < _limits.getCenter().x + _limits.getWidth() / 2 &&
                     circle.getCenter().x - circle.getRadius() > _limits.getCenter().x)
            {
                if (top)
                {
                    index = 1;
                }
                else if (bottom)
                {
                    index = 3;
                }
            }

            //returns -1 if circle doesn't fit completely into any quadrant
            return(index);
        }