示例#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 项目: keppelcao/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 LObjectCamera(RectBox r, object f, int width, int height,
         int horBorderPixel_0, int vertBorderPixel_1, Vector2f maxSpeed_2)
 {
     this.cameraX = 0;
     this.cameraY = 0;
     this.renderWidth = width;
     this.renderHeight = height;
     this.follow = new Bind(f);
     this.horBorderPixel = horBorderPixel_0;
     this.vertBorderPixel = vertBorderPixel_1;
     this.maxSpeed = maxSpeed_2;
     if (follow != null)
     {
         this.cameraX = follow.GetX() - (this.renderWidth / 2);
         this.cameraY = follow.GetY() - (this.renderHeight / 2);
     }
     this.cameraRect = r;
     this.visibleRect = new RectBox(cameraX - horBorderPixel_0, cameraY
             - vertBorderPixel_1, renderWidth + horBorderPixel_0, renderHeight
             + vertBorderPixel_1);
     this.moveRect = new RectBox(cameraX - horBorderPixel_0, cameraY
             - vertBorderPixel_1, renderWidth + horBorderPixel_0, renderHeight
             + vertBorderPixel_1);
     this.UpdateCamera();
 }
示例#4
0
        public static void CalculateBounds(Vector2f[] vertices, RectBox bounds)
        {
            bounds.x = System.Single.MaxValue;
            bounds.y = System.Single.MaxValue;

            bounds.width  = (int)-System.Int32.MaxValue;
            bounds.height = (int)-System.Int32.MaxValue;

            for (int i = 0; i < vertices.Length; i++)
            {
                Vector2f v = vertices[i];

                if (v.x < bounds.x)
                {
                    bounds.x = v.x;
                }

                if (v.y < bounds.y)
                {
                    bounds.y = v.y;
                }

                if (v.x > bounds.x + bounds.width)
                {
                    bounds.width = (int)(v.x - bounds.x);
                }

                if (v.y > bounds.y + bounds.height)
                {
                    bounds.height = (int)(v.y - bounds.y);
                }
            }
        }
示例#5
0
 public void Copy(RectBox other)
 {
     this.x      = other.x;
     this.y      = other.y;
     this.width  = other.width;
     this.height = other.height;
 }
        public EmulatorButton(LTexture img, int w, int h, int x, int y,
                bool flag, int sizew, int sizeh)
        {
            this.color = new LColor(LColor.gray.R, LColor.gray.G,
                            LColor.gray.B, 125);
            img.LoadTexture();
            if (flag)
               {
                this.bitmap = img.GetSubTexture(x, y, w, h);
            }
            else
            {
                this.bitmap = img;
            }
            if (bitmap.GetWidth() != sizew || bitmap.GetHeight() != sizeh)
            {

                LTexture tmp = bitmap;
                this.bitmap = bitmap.Scale(sizew, sizeh);

                if (tmp != null)
                {
                    tmp.Dispose();
                    tmp = null;
                }
            }
            this.bounds = new RectBox(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
        }
示例#7
0
		public static LNFollow Action(LNNode followedNode, RectBox rect) {
			LNFollow follow = new LNFollow();
			follow._followedNode = followedNode;
			follow._boundarySet = true;
			follow._boundaryFullyCovered = false;
	
			follow.winRect = LSystem.screenRect;
			follow.fullScreenSize = new Vector2f(follow.winRect.width,
					follow.winRect.height);
            follow.halfScreenSize = follow.fullScreenSize.Mul(0.5f);
	
			follow.leftBoundary = -((rect.x + rect.width) - follow.fullScreenSize.x);
			follow.rightBoundary = -rect.x;
			follow.topBoundary = -rect.y;
			follow.bottomBoundary = -((rect.y + rect.height) - follow.fullScreenSize.y);
	
			if (follow.rightBoundary < follow.leftBoundary) {
				follow.rightBoundary = follow.leftBoundary = (follow.leftBoundary + follow.rightBoundary) / 2;
			}
	
			if (follow.topBoundary < follow.bottomBoundary) {
				follow.topBoundary = follow.bottomBoundary = (follow.topBoundary + follow.bottomBoundary) / 2;
			}
			if ((follow.topBoundary == follow.bottomBoundary)
					&& (follow.leftBoundary == follow.rightBoundary)) {
				follow._boundaryFullyCovered = true;
			}
			return follow;
		}
示例#8
0
 /// <summary>
 /// 判断两个圆形是否发生了碰撞
 /// </summary>
 ///
 /// <param name="rect1"></param>
 /// <param name="rect2"></param>
 /// <returns></returns>
 public static bool IsCircToCirc(RectBox rect1, RectBox rect2)
 {
     Point middle1 = GetMiddlePoint(rect1);
     Point middle2 = GetMiddlePoint(rect2);
     float distance = middle1.DistanceTo(middle2);
     float radius1 = rect1.GetWidth() / 2;
     float radius2 = rect2.GetWidth() / 2;
     return (distance - radius2) < radius1;
 }
示例#9
0
        public RectBox GetIntersection(RectBox rect)
        {
            int x1 = (int)MathUtils.Max(x, rect.x);
            int x2 = (int)MathUtils.Min(x + width, rect.x + rect.width);
            int y1 = (int)MathUtils.Max(y, rect.y);
            int y2 = (int)MathUtils.Min(y + height, rect.y + rect.height);

            return(new RectBox(x1, y1, x2 - x1, y2 - y1));
        }
示例#10
0
 public virtual void SetRotation(float r)
 {
     this.rotation = r;
     if (rect != null)
     {
         rect = MathUtils.GetBounds(location.x, location.y, GetWidth(),
                 GetHeight(), r, rect);
     }
 }
示例#11
0
 public OutEffect(LTexture t, RectBox limit, int code)
 {
     this.texture = t;
     this.type = code;
     this.width = t.Width;
     this.height = t.Height;
     this.multiples = 1;
     this.limit = limit;
     this.visible = true;
 }
示例#12
0
		public EmulatorButton(LTextureRegion img, int w, int h, int x, int y,
				bool flag, int sizew, int sizeh) {
			if (flag) {
				this.bitmap = new LTextureRegion(img, x, y, w, h);
			} else {
				this.bitmap = new LTextureRegion(img);
			}
			this.scaleWidth = sizew;
			this.scaleHeight = sizeh;
			this.bounds = new RectBox(0, 0, scaleWidth, scaleHeight);
		}
示例#13
0
        public static bool Contains(int[] xPoints, int[] yPoints,
                int nPoints,RectBox bounds, int x1, int y1)
        {
            if ((bounds != null && bounds.Inside(x1, y1))
                    || (bounds == null && GetBoundingBox(xPoints, yPoints, nPoints)
                            .Inside(x1, y1)))
            {
                int hits = 0;
                int ySave = 0;
                int i = 0;

                while (i < nPoints && yPoints[i] == y1)
                {
                    i++;
                }
                for (int n = 0; n < nPoints; n++)
                {
                    int j = (i + 1) % nPoints;

                    int dx = xPoints[j] - xPoints[i];
                    int dy = yPoints[j] - yPoints[i];

                    if (dy != 0)
                    {

                        int rx = x1 - xPoints[i];
                        int ry = y1 - yPoints[i];

                        if (yPoints[j] == y1 && xPoints[j] >= x1)
                        {
                            ySave = yPoints[i];
                        }
                        if (yPoints[i] == y1 && xPoints[i] >= x1)
                        {
                            if ((ySave > y1) != (yPoints[j] > y1))
                            {
                                hits--;
                            }
                        }
                        if (ry * dy >= 0
                                && (ry <= dy && ry >= 0 || ry >= dy && ry <= 0)
                                && Round(dx * ry, dy) >= rx)
                        {
                            hits++;
                        }
                    }
                    i = j;
                }
                return (hits % 2) != 0;
            }

            return false;
        }
示例#14
0
 public override bool Equals(object obj)
 {
     if (obj  is  RectBox)
     {
         RectBox rect = (RectBox)obj;
         return(Equals(rect.x, rect.y, rect.width, rect.height));
     }
     else
     {
         return(false);
     }
 }
示例#15
0
文件: Shape.cs 项目: vb0067/LGame
 public virtual RectBox GetRect()
 {
     if (rect == null)
     {
         rect = new RectBox(x, y, GetWidth(), GetHeight());
     }
     else
     {
         rect.SetBounds(x, y, GetWidth(), GetHeight());
     }
     return(rect);
 }
        public bool CheckCollision(Actor actor)
        {

            obj0 = actor.GetRectBox();

            dx = MathUtils.Abs(obj0.GetCenterX() - x);
            dy = MathUtils.Abs(obj0.GetCenterY() - y);

            dist =  MathUtils.Sqrt(dx * dx + dy * dy);

            return dist <= this.r;
        }
示例#17
0
 public static RectBox GetBounds(float x, float y, float width,
         float height, float rotate, RectBox result)
 {
     int[] rect = GetLimit(x, y, width, height, rotate);
     if (result == null)
     {
         result = new RectBox(rect[0], rect[1], rect[2], rect[3]);
     }
     else
     {
         result.SetBounds(rect[0], rect[1], rect[2], rect[3]);
     }
     return result;
 }
示例#18
0
		public SpriteBatchObject(float x, float y, float dw, float dh,
				Animation animation, TileMap map) {
			this.SetLocation(x, y);
			this.tiles = map;
			this.animation = animation;
			this.dstWidth = dw;
			this.dstHeight = dh;
            Loon.Core.Graphics.Opengl.LTexture texture = animation.GetSpriteImage();
			if (dw < 1 && dh < 1) {
                this.rectBox = new RectBox(x, y, texture
                        .GetWidth(), texture.GetHeight());
			} else {
				this.rectBox = new RectBox(x, y, dw, dh);
			}
		}
示例#19
0
        public SpriteBatchObject(float x, float y, float dw, float dh,
				Animation animation, TileMap map)
        {
            this.SetLocation(x, y);
            this.tiles = map;
            this.animation = animation;
            this.dstWidth = dw;
            this.dstHeight = dh;
            if (dw < 1 && dh < 1) {
                this.rectBox = new RectBox(x, y, animation.GetSpriteImage()
                        .GetWidth(), animation.GetSpriteImage().GetHeight());
            } else {
                this.rectBox = new RectBox(x, y, dw, dh);
            }
        }
示例#20
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;
 }
示例#21
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);
        }
示例#22
0
 public SplitEffect(LTexture t, RectBox limit_0, int d)
 {
     this.texture = t;
     this.width = texture.GetWidth();
     this.height = texture.GetHeight();
     this.halfWidth = width / 2;
     this.halfHeight = height / 2;
     this.multiples = 2;
     this.direction = d;
     this.limit = limit_0;
     this.timer = new LTimer(10);
     this.visible = true;
     this.v1 = new Vector2f();
     this.v2 = new Vector2f();
     switch (direction)
     {
         case Config.UP:
         case Config.DOWN:
             special = true;
             {
                 v1.Set(0, 0);
                 v2.Set(halfWidth, 0);
                 break;
             }
         case Config.TLEFT:
         case Config.TRIGHT:
             v1.Set(0, 0);
             v2.Set(halfWidth, 0);
             break;
         case Config.LEFT:
         case Config.RIGHT:
             special = true;
             {
                 v1.Set(0, 0);
                 v2.Set(0, halfHeight);
                 break;
             }
         case Config.TUP:
         case Config.TDOWN:
             v1.Set(0, 0);
             v2.Set(0, halfHeight);
             break;
     }
 }
示例#23
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;
 }
示例#24
0
 /// <summary>
 /// ����������
 /// </summary>
 ///
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="width_0"></param>
 /// <param name="height_1"></param>
 public LComponent(int x, int y, int width_0, int height_1)
 {
     this.alpha = 1.0f;
     this.visible = true;
     this.enabled = true;
     this.focusable = true;
     this.selected = false;
     this.desktop = Desktop.EMPTY_DESKTOP;
     this.SetLocation(x, y);
     this.width = width_0;
     this.height = height_1;
     this.screenRect = LSystem.screenRect;
     if (this.width == 0)
     {
         this.width = 10;
     }
     if (this.height == 0)
     {
         this.height = 10;
     }
 }
示例#25
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);
        }
示例#26
0
 /// <summary>
 /// 检查矩形与圆形是否发生了碰撞
 /// </summary>
 ///
 /// <param name="rect1"></param>
 /// <param name="rect2"></param>
 /// <returns></returns>
 public static bool IsRectToCirc(RectBox rect1, RectBox rect2)
 {
     float radius = rect2.GetWidth() / 2;
     Point middle = GetMiddlePoint(rect2);
     Point upperLeft = new Point(rect1.GetMinX(), rect1.GetMinY());
     Point upperRight = new Point(rect1.GetMaxX(), rect1.GetMinY());
     Point downLeft = new Point(rect1.GetMinX(), rect1.GetMaxY());
     Point downRight = new Point(rect1.GetMaxX(), rect1.GetMaxY());
     bool collided = true;
     if (!IsPointToLine(upperLeft, upperRight, middle, radius))
     {
         if (!IsPointToLine(upperRight, downRight, middle, radius))
         {
             if (!IsPointToLine(upperLeft, downLeft, middle, radius))
             {
                 if (!IsPointToLine(downLeft, downRight, middle, radius))
                 {
                     collided = false;
                 }
             }
         }
     }
     return collided;
 }
示例#27
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);
        }
示例#28
0
 /// <summary>
 /// 检查两个矩形是否发生了碰撞
 /// </summary>
 ///
 /// <param name="rect1"></param>
 /// <param name="rect2"></param>
 /// <returns></returns>
 public static bool IsRectToRect(RectBox rect1, RectBox rect2)
 {
     return rect1.Intersects(rect2);
 }
示例#29
0
 public bool Intersects(RectBox rect)
 {
     return(Intersects(rect.x, rect.y, rect.width, rect.height));
 }
示例#30
0
 public void Intersection(RectBox rect)
 {
     Intersection(rect.x, rect.y, rect.width, rect.height);
 }
示例#31
0
        public void AddObject(Actor actor)
        {
            RectBox bounds = this.GetActorBounds(actor);
            float by;
            if (this.bspTree == null)
            {
                byte treeArea;
                if (bounds.width > bounds.height)
                {
                    treeArea = 0;
                    by = bounds.GetMiddleX();
                }
                else
                {
                    treeArea = 1;
                    by = bounds.GetMiddleY();
                }

                this.bspTree = GetBSPNode();
                this.bspTree.GetArea().Copy(bounds);
                this.bspTree.SetSplitAxis(treeArea);
                this.bspTree.SetSplitPos(by);
                this.bspTree.AddActor(actor);
            }
            else
            {
                int idx = 0;
                RectBox treeArea1 = this.bspTree.GetArea();
                RectBox result1 = new RectBox();
                RectBox result2 = new RectBox();
                for (; !treeArea1.Contains(bounds) && idx < MAX_SIZE; )
                {
                    RectBox newArea;
                    BSPCollisionNode newTop;
                    if (bounds.GetX() < treeArea1.GetX())
                    {
                        by = (treeArea1.GetX() - treeArea1.width);
                        newArea = new RectBox(by, treeArea1.GetY(),
                                treeArea1.GetRight() - by, treeArea1.height);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(0);
                        newTop.SetSplitPos(treeArea1.GetX());
                        newTop.SetChild(1, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1 = newArea;
                    }
                    if (bounds.GetRight() > treeArea1.GetRight())
                    {
                        by = (treeArea1.GetRight() + treeArea1.width);
                        newArea = new RectBox(treeArea1.GetX(), treeArea1.GetY(),
                                by - treeArea1.GetX(), treeArea1.height);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(0);
                        newTop.SetSplitPos(treeArea1.GetRight());
                        newTop.SetChild(0, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1 = newArea;
                    }
                    if (bounds.GetY() < treeArea1.GetY())
                    {
                        by = (treeArea1.GetY() - treeArea1.height);
                        newArea = new RectBox(treeArea1.GetX(), by,
                                treeArea1.width, treeArea1.GetBottom() - by);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(1);
                        newTop.SetSplitPos(treeArea1.GetY());
                        newTop.SetChild(1, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1 = newArea;
                    }
                    if (bounds.GetBottom() > treeArea1.GetBottom())
                    {
                        by = (treeArea1.GetBottom() + treeArea1.height);
                        newArea = new RectBox(treeArea1.GetX(), treeArea1.GetY(),
                                treeArea1.width, by - treeArea1.GetY());
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(1);
                        newTop.SetSplitPos(treeArea1.GetBottom());
                        newTop.SetChild(0, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1 = newArea;
                    }
                    idx++;
                }

                this.InsertObject(actor, bounds, bounds, treeArea1, this.bspTree,
                        result1, result2);
            }

        }
示例#32
0
 public bool Contains(RectBox rect)
 {
     return(Contains(rect.x, rect.y, rect.width, rect.height));
 }
示例#33
0
        private Actor GetOnlyIntersectingDown(RectBox r,
                CollisionQuery query, Actor actor)
        {
            if (this.bspTree == null)
            {
                return null;
            }
            else
            {
                lock (cacheNodeStack)
                {
                    cacheNodeStack.Clear();
                    CollectionUtils.Add(cacheNodeStack, this.bspTree);
                    int idx = 0;
                    for (; !(cacheNodeStack.Count == 0) && idx < MAX_SIZE; )
                    {
                        BSPCollisionNode node = (BSPCollisionNode)cacheNodeStack
                                .RemoveLast();
                        if (node.GetArea().Contains(r))
                        {
                            Actor res = this.CheckForOnlyCollision(actor, node,
                                    query);
                            if (res != null)
                            {
                                return res;
                            }

                            BSPCollisionNode left = node.GetLeft();
                            BSPCollisionNode right = node.GetRight();
                            if (left != null)
                            {
                                CollectionUtils.Add(cacheNodeStack, left);
                            }
                            if (right != null)
                            {
                                CollectionUtils.Add(cacheNodeStack, right);
                            }
                        }
                    }
                }
                return null;
            }
        }
示例#34
0
        private void InsertObject(Actor actor, RectBox actorBounds, RectBox bounds,
                RectBox area, BSPCollisionNode node, RectBox result1,
                RectBox result2)
        {
            if (!node.ContainsActor(actor))
            {
                if (!node.IsEmpty()
                        && (area.width > actorBounds.width || area.height > actorBounds.height))
                {
                    RectBox leftArea = node.GetLeftArea();
                    RectBox rightArea = node.GetRightArea();
                    RectBox leftIntersects = RectBox.GetIntersection(leftArea,
                            bounds, result1);
                    RectBox rightIntersects = RectBox.GetIntersection(rightArea,
                            bounds, result2);
                    BSPCollisionNode newRight;
                    if (leftIntersects != null)
                    {
                        if (node.GetLeft() == null)
                        {
                            newRight = this.CreateNewNode(leftArea);
                            newRight.AddActor(actor);
                            node.SetChild(0, newRight);
                        }
                        else
                        {
                            this.InsertObject(actor, actorBounds, leftIntersects,
                                    leftArea, node.GetLeft(), result1, result2);
                        }
                    }
                    if (rightIntersects != null)
                    {
                        if (node.GetRight() == null)
                        {
                            newRight = this.CreateNewNode(rightArea);
                            newRight.AddActor(actor);
                            node.SetChild(1, newRight);
                        }
                        else
                        {
                            this.InsertObject(actor, actorBounds, rightIntersects,
                                    rightArea, node.GetRight(), result1, result2);
                        }
                    }

                }
                else
                {
                    node.AddActor(actor);
                }
            }
        }
示例#35
0
 public void SetLocation(RectBox r)
 {
     this.x = r.x;
     this.y = r.y;
 }
示例#36
0
 public bool Overlaps(RectBox rectangle)
 {
     return(!(x > rectangle.x + rectangle.width || x + width < rectangle.x ||
              y > rectangle.y + rectangle.height || y + height < rectangle.y));
 }
示例#37
0
        private void UpdateObject(Actor o) {
			ActorNode node = GetNodeForActor(o);
			if (node != null) {
				RectBox newBounds = this.GetActorBounds(o);
				BSPCollisionNode bspNode;
				if (!this.bspTree.GetArea().Contains(newBounds)) {
					for (; node != null;) {
						bspNode = node.GetBSPNode();
						node.Remove();
						this.CheckRemoveNode(bspNode);
						node = node.GetNext();
					}
					this.AddObject(o);
				} else {
					RectBox bspArea;
					RectBox result1 = new RectBox();
					RectBox result2 = new RectBox();
					while (node != null) {
						bspNode = node.GetBSPNode();
						bspArea = bspNode.GetArea();
						if (bspArea.Contains(newBounds)) {
							for (ActorNode rNode2 = GetNodeForActor(o); rNode2 != null; rNode2 = rNode2
									.GetNext()) {
								if (rNode2 != node) {
									BSPCollisionNode rNode1 = rNode2.GetBSPNode();
									rNode2.Remove();
									this.CheckRemoveNode(rNode1);
								}
							}
							return;
						}
						if (!bspArea.Intersects(newBounds)) {
							BSPCollisionNode rNode = node.GetBSPNode();
							node.Remove();
							this.CheckRemoveNode(rNode);
						}
						node.ClearMark();
						node = node.GetNext();
					}
					node = GetNodeForActor(o);
					if (node != null) {
						for (bspNode = node.GetBSPNode(); bspNode != null
								&& !bspNode.GetArea().Contains(newBounds); bspNode = bspNode
								.GetParent()) {
							
						}
						if (bspNode == null) {
							while (node != null) {
								bspNode = node.GetBSPNode();
								node.Remove();
								this.CheckRemoveNode(bspNode);
								node = node.GetNext();
							}
	
							this.AddObject(o);
							return;
						}
					} else {
						bspNode = this.bspTree;
					}
	
					bspArea = bspNode.GetArea();
					this.InsertObject(o, newBounds, newBounds, bspArea,
							bspNode, result1, result2);
					for (node = GetNodeForActor(o); node != null; node = node
							.GetNext()) {
						if (!node.CheckMark()) {
							bspNode = node.GetBSPNode();
							node.Remove();
							this.CheckRemoveNode(bspNode);
						}
					}
	
				}
			}
		}
示例#38
0
 public void SetBounds(RectBox rect)
 {
     SetBounds(rect.x, rect.y, rect.width, rect.height);
 }
示例#39
0
 /// <summary>
 /// 获得两个矩形间距离
 /// </summary>
 ///
 /// <param name="box1"></param>
 /// <param name="box2"></param>
 /// <returns></returns>
 public static float GetDistance(RectBox box1, RectBox box2)
 {
     float xdiff = box1.x - box2.x;
     float ydiff = box1.y - box2.y;
     return Loon.Utils.MathUtils.Sqrt(xdiff * xdiff + ydiff * ydiff);
 }
示例#40
0
 public void Draw(LTexture texture, Vector2f pos, Vector2f origin,
         float scale, RectBox src, bool flipX, bool flipY)
 {
     Draw(texture, pos.x, pos.y, origin.x, origin.y, src.width, src.height,
             scale, scale, 0, src.x, src.y, src.width, src.height, flipX,
             flipY, false);
 }
示例#41
0
 public Actor GetOnlyIntersectingUp(RectBox r,
         CollisionQuery query, Actor actor, BSPCollisionNode start)
 {
     for (; start != null && !start.GetArea().Contains(r); )
     {
         Actor res = this.CheckForOnlyCollision(actor, start, query);
         if (res != null)
         {
             return res;
         }
         start = start.GetParent();
     }
     return null;
 }
示例#42
0
 public void Union(RectBox rect)
 {
     Union(rect.x, rect.y, rect.width, rect.height);
 }
示例#43
0
        private BSPCollisionNode CreateNewNode(RectBox area)
        {
            byte splitAxis;
            float splitPos;
            if (area.width > area.height)
            {
                splitAxis = 0;
                splitPos = area.GetMiddleX();
            }
            else
            {
                splitAxis = 1;
                splitPos = area.GetMiddleY();
            }

            BSPCollisionNode newNode = GetBSPNode();
            newNode.SetArea(area);
            newNode.SetSplitAxis(splitAxis);
            newNode.SetSplitPos(splitPos);
            return newNode;
        }
示例#44
0
 public void Draw(LTexture texture, Vector2f pos, RectBox src,
         bool flipX, bool flipY)
 {
     Draw(texture, pos.x, pos.y, src.width / 2, src.height / 2, src.width,
             src.height, 1f, 1f, 0, src.x, src.y, src.width, src.height,
             flipX, flipY, false);
 }
示例#45
0
 private Actor GetOnlyObjectDownTree(Actor ignore, RectBox r,
         CollisionQuery query, BSPCollisionNode startNode)
 {
     if (startNode == null)
     {
         return null;
     }
     else
     {
         lock (cacheNodeStack)
         {
             cacheNodeStack.Clear();
             if (startNode != null)
             {
                 CollectionUtils.Add(cacheNodeStack, startNode);
             }
             while (!(cacheNodeStack.Count == 0))
             {
                 BSPCollisionNode node = (BSPCollisionNode)cacheNodeStack
                         .RemoveLast();
                 if (node.GetArea().Intersects(r))
                 {
                     Actor res = this.CheckForOnlyCollision(ignore, node,
                             query);
                     if (res != null)
                     {
                         return res;
                     }
                     BSPCollisionNode left = node.GetLeft();
                     BSPCollisionNode right = node.GetRight();
                     if (left != null)
                     {
                         CollectionUtils.Add(cacheNodeStack, left);
                     }
                     if (right != null)
                     {
                         CollectionUtils.Add(cacheNodeStack, right);
                     }
                 }
             }
         }
         return null;
     }
 }