static public void DrawBounds(Bound2D box, Color c, Matrix4x4 mat) { Vector2 Extent = box.GetExtent(); Vector2 XExtent = new Vector2(Extent.x, 0.0f); Vector2 YExtent = new Vector2(0.0f, Extent.y); Vector2 C = box.center; Vector2 TM = C + YExtent + XExtent; Vector2 ML = C + YExtent - XExtent; Vector2 MR = C - YExtent - XExtent; Vector2 BM = C - YExtent + XExtent; GL.PushMatrix(); GL.MultMatrix(mat); GL.Begin(GL.LINES); GL.Color(c); GL.Vertex3(TM.x, 0, TM.y); GL.Vertex3(ML.x, 0, ML.y); GL.Vertex3(ML.x, 0, ML.y); GL.Vertex3(MR.x, 0, MR.y); GL.Vertex3(MR.x, 0, MR.y); GL.Vertex3(BM.x, 0, BM.y); GL.Vertex3(BM.x, 0, BM.y); GL.Vertex3(TM.x, 0, TM.y); GL.End(); GL.PopMatrix(); }
private void Split() { //check(bInternal == false); Vector2 Extent = treeBox.GetExtent(); Vector2 XExtent = new Vector2(Extent.x, 0.0f); Vector2 YExtent = new Vector2(0.0f, Extent.y); /************************************************************************ * ___________max * | | | * | | | * |-----c------ * | | | * min___|_____| * * We create new quads by adding xExtent and yExtent ************************************************************************/ Vector2 C = treeCenter; Vector2 TM = C + YExtent; Vector2 ML = C - XExtent; Vector2 MR = C + XExtent; Vector2 BM = C - YExtent; Vector2 BL = treeBox.min; Vector2 TR = treeBox.max; subTrees[TopLeft] = new QuadTree <T>(new Bound2D(ML, TM), minimumQuadSize); subTrees[TopRight] = new QuadTree <T>(new Bound2D(C, TR), minimumQuadSize); subTrees[BottomLeft] = new QuadTree <T>(new Bound2D(BL, C), minimumQuadSize); subTrees[BottomRight] = new QuadTree <T>(new Bound2D(BM, MR), minimumQuadSize); //mark as no longer a leaf bInternal = true; // Place existing nodes and place them into the new subtrees that contain them // If a node overlaps multiple subtrees, we retain the reference to it here in this quad List <QuadTreeNode> OverlappingNodes = new List <QuadTreeNode>(); foreach (var node in nodeList) { QuadTree <T>[] Quads; int NumQuads = GetQuads(node.bound, out Quads); if (NumQuads == 1) { Quads[0].nodeList.Add(node); } else { OverlappingNodes.Add(node); } } nodeList = OverlappingNodes; }