示例#1
0
        /// <summary>
        /// �ж�ָ����С�����������Ƿ��ཻ
        /// </summary>
        ///
        /// <param name="rectA"></param>
        /// <param name="dataA"></param>
        /// <param name="rectB"></param>
        /// <param name="dataB"></param>
        /// <returns></returns>
        public static bool Intersect(RectBox rectA, int[] dataA, RectBox rectB,
                int[] dataB)
        {
            int top = (int)Loon.Utils.MathUtils.Max(rectA.GetY(), rectB.GetY());
            int bottom = (int)Loon.Utils.MathUtils.Min(rectA.GetBottom(), rectB.GetBottom());
            int left = (int)Loon.Utils.MathUtils.Max(rectA.GetX(), rectB.GetX());
            int right = (int)Loon.Utils.MathUtils.Min(rectA.GetRight(), rectB.GetRight());

            for (int y = top; y < bottom; y++)
            {
                for (int x = left; x < right; x++)
                {

                    int colorA = dataA[(int)((x - rectA.x) + (y - rectA.y)
                            * rectA.width)];
                    int colorB = dataB[(int)((x - rectB.x) + (y - rectB.y)
                            * rectB.width)];
                    if ((int)(((uint)colorA) >> 24) != 0 && (int)(((uint)colorB) >> 24) != 0)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
示例#2
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);
        }
示例#3
0
 public static RectBox GetIntersection(RectBox a, RectBox b)
 {
     float a_x = a.GetX();
     float a_r = a.GetRight();
     float a_y = a.GetY();
     float a_t = a.GetBottom();
     float b_x = b.GetX();
     float b_r = b.GetRight();
     float b_y = b.GetY();
     float b_t = b.GetBottom();
     float i_x = MathUtils.Max(a_x, b_x);
     float i_r = MathUtils.Min(a_r, b_r);
     float i_y = MathUtils.Max(a_y, b_y);
     float i_t = MathUtils.Min(a_t, b_t);
     return (i_x < i_r && i_y < i_t) ? new RectBox(i_x, i_y, i_r - i_x, i_t
             - i_y) : null;
 }
示例#4
0
        public static RectBox GetIntersection(RectBox a, RectBox b)
        {
            float a_x = a.GetX();
            float a_r = a.GetRight();
            float a_y = a.GetY();
            float a_t = a.GetBottom();
            float b_x = b.GetX();
            float b_r = b.GetRight();
            float b_y = b.GetY();
            float b_t = b.GetBottom();
            float i_x = MathUtils.Max(a_x, b_x);
            float i_r = MathUtils.Min(a_r, b_r);
            float i_y = MathUtils.Max(a_y, b_y);
            float i_t = MathUtils.Min(a_t, b_t);

            return((i_x < i_r && i_y < i_t) ? new RectBox(i_x, i_y, i_r - i_x, i_t
                                                          - i_y) : null);
        }
示例#5
0
 public static RectBox GetIntersection(RectBox a, RectBox b, RectBox result)
 {
     float a_x = a.GetX();
     float a_r = a.GetRight();
     float a_y = a.GetY();
     float a_t = a.GetBottom();
     float b_x = b.GetX();
     float b_r = b.GetRight();
     float b_y = b.GetY();
     float b_t = b.GetBottom();
     float i_x = MathUtils.Max(a_x, b_x);
     float i_r = MathUtils.Min(a_r, b_r);
     float i_y = MathUtils.Max(a_y, b_y);
     float i_t = MathUtils.Min(a_t, b_t);
     if (i_x < i_r && i_y < i_t) {
         result.SetBounds(i_x, i_y, i_r - i_x, i_t - i_y);
         return result;
     }
     return null;
 }
示例#6
0
        public static RectBox GetIntersection(RectBox a, RectBox b, RectBox result)
        {
            float a_x = a.GetX();
            float a_r = a.GetRight();
            float a_y = a.GetY();
            float a_t = a.GetBottom();
            float b_x = b.GetX();
            float b_r = b.GetRight();
            float b_y = b.GetY();
            float b_t = b.GetBottom();
            float i_x = MathUtils.Max(a_x, b_x);
            float i_r = MathUtils.Min(a_r, b_r);
            float i_y = MathUtils.Max(a_y, b_y);
            float i_t = MathUtils.Min(a_t, b_t);

            if (i_x < i_r && i_y < i_t)
            {
                result.SetBounds(i_x, i_y, i_r - i_x, i_t - i_y);
                return(result);
            }
            return(null);
        }
示例#7
0
 protected internal void DrawChar(SpriteBatch batch, float x, float y, RectBox glyph,
         RectBox cropping, LColor color)
 {
     batch.Draw(texture, x + cropping.x, y + cropping.y, glyph.GetWidth(),
             glyph.GetHeight(), glyph.GetX(), glyph.GetY(),
             glyph.GetWidth(), glyph.GetHeight(), color);
 }