/// <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); }
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); }
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); } }
public int GetY() { return((int)bounds.GetY()); }