private void DrawSubdivision(ref Matrix4 mvp, Vector3 min, Vector3 size, List <KCL.OctreeNode> modelOctrees, int subdiv) { var BoxSize = size / 2f; var QuarterSize = BoxSize / 2f; int index = 0; for (int z = 0; z < 2; z++) { for (int y = 0; y < 2; y++) { for (int x = 0; x < 2; x++) { var Boxmin = min + BoxSize * new Vector3(x, y, z); var pos = BoxSize * new Vector3(x, y, z); if (modelOctrees[index].IsSelected) { DrawableBoundingBox.DrawBoundingBox(mvp, QuarterSize, Boxmin + QuarterSize, System.Drawing.Color.Red); } else { DrawableBoundingBox.DrawBoundingBox(mvp, QuarterSize, Boxmin + QuarterSize, System.Drawing.Color.Green); } if (modelOctrees[index].Nodes.Count > 0) { DrawSubdivision(ref mvp, Boxmin, BoxSize, modelOctrees[index].Children, subdiv++); } index++; } } } }
private void DrawBoundingBoxes() { var boundings = GetSelectionBox(); DrawableBoundingBox.DrawBoundingBox( new Vector3(boundings.minX, boundings.minY, boundings.minZ), new Vector3(boundings.maxX, boundings.maxY, boundings.maxZ), new Vector3(0) ); return; }
/// <summary> /// Forced updated of the boundingbox scanning all the /// vertices of the cell for their height position /// </summary> private void UpdateBoundingBox() { float minH = float.MaxValue; float maxH = float.MinValue; float height = 0f; for (int y = 0; y < divisions.Y; y++) { for (int x = 0; x < divisions.X; x++) { height = vertices[x + y * divisions.X].Position.Y; if(height < minH) minH = height; if(height > maxH) maxH = height; } } Vector3 Min = new Vector3(position.X, minH, position.Z); Vector3 Max = new Vector3(position.X + divisions.X * cellsize.X - cellsize.X, maxH, position.Z + divisions.Y * cellsize.Y - cellsize.Y); center.Y = Min.Y + (Max.Y - Min.Y) / 2f; boundingBox = new BoundingBox(Min, Max); boundingBoxWire = new DrawableBoundingBox(Vector3.Zero, Min, Max); minHeight = minH; maxHeight = maxH; }
private void UpdateBoundingBox(float minHeight, float maxHeight) { if (minHeight < this.minHeight) this.minHeight = minHeight; if (maxHeight > this.maxHeight) this.maxHeight = maxHeight; Vector3 Min = new Vector3(position.X, this.minHeight, position.Z); Vector3 Max = new Vector3(position.X + divisions.X * cellsize.X - cellsize.X, this.maxHeight, position.Z + divisions.Y * cellsize.Y - cellsize.Y); center.Y = Min.Y + (Max.Y - Min.Y) / 2f; boundingBox = new BoundingBox(Min, Max); boundingBoxWire = new DrawableBoundingBox(Vector3.Zero, Min, Max); }