コード例 #1
0
ファイル: Circle.cs プロジェクト: vb0067/LGame
        private bool Intersects(RectBox other)
        {
            RectBox box    = other;
            Circle  circle = this;

            if (box.Contains(x + radius, y + radius))
            {
                return(true);
            }

            float x1 = box.GetX();
            float y1 = box.GetY();
            float x2 = box.GetX() + box.GetWidth();
            float y2 = box.GetY() + box.GetHeight();

            Line[] lines = new Line[4];
            lines[0] = new Line(x1, y1, x2, y1);
            lines[1] = new Line(x2, y1, x2, y2);
            lines[2] = new Line(x2, y2, x1, y2);
            lines[3] = new Line(x1, y2, x1, y1);

            float r2 = circle.GetRadius() * circle.GetRadius();

            Vector2f pos = new Vector2f(circle.GetCenterX(), circle.GetCenterY());

            for (int i = 0; i < 4; i++)
            {
                float dis = lines[i].DistanceSquared(pos);
                if (dis < r2)
                {
                    return(true);
                }
            }

            return(false);
        }