private void Split() { float subWidth = Bounds[3] * 0.5f; float subLength = Bounds[4] * 0.5f; float subHeight = Bounds[5] * 0.5f; float x = Bounds[0]; float y = Bounds[1]; float z = Bounds[2]; // bottom half Nodes[0] = new OcTree(Level + 1, new[] { x + subWidth, y + subLength, z - subHeight, subWidth, subLength, subHeight }, _pathfinder); Nodes[1] = new OcTree(Level + 1, new[] { x - subWidth, y + subLength, z - subHeight, subWidth, subLength, subHeight }, _pathfinder); Nodes[2] = new OcTree(Level + 1, new[] { x - subWidth, y - subLength, z - subHeight, subWidth, subLength, subHeight }, _pathfinder); Nodes[3] = new OcTree(Level + 1, new[] { x + subWidth, y - subLength, z - subHeight, subWidth, subLength, subHeight }, _pathfinder); // top half Nodes[4] = new OcTree(Level + 1, new[] { x + subWidth, y + subLength, z + subHeight, subWidth, subLength, subHeight }, _pathfinder); Nodes[5] = new OcTree(Level + 1, new[] { x - subWidth, y + subLength, z + subHeight, subWidth, subLength, subHeight }, _pathfinder); Nodes[6] = new OcTree(Level + 1, new[] { x - subWidth, y - subLength, z + subHeight, subWidth, subLength, subHeight }, _pathfinder); Nodes[7] = new OcTree(Level + 1, new[] { x + subWidth, y - subLength, z + subHeight, subWidth, subLength, subHeight }, _pathfinder); }
private void split() { float subWidth = bounds[3] * 0.5f; float subLength = bounds[4] * 0.5f; float subHeight = bounds[5] * 0.5f; float x = bounds[0]; float y = bounds[1]; float z = bounds[2]; // bottom half nodes[0] = new OcTree(level + 1, new float[] { x + subWidth, y + subLength, z - subHeight, subWidth, subLength, subHeight }, pathfinder); nodes[1] = new OcTree(level + 1, new float[] { x - subWidth, y + subLength, z - subHeight, subWidth, subLength, subHeight }, pathfinder); nodes[2] = new OcTree(level + 1, new float[] { x - subWidth, y - subLength, z - subHeight, subWidth, subLength, subHeight }, pathfinder); nodes[3] = new OcTree(level + 1, new float[] { x + subWidth, y - subLength, z - subHeight, subWidth, subLength, subHeight }, pathfinder); // top half nodes[4] = new OcTree(level + 1, new float[] { x + subWidth, y + subLength, z + subHeight, subWidth, subLength, subHeight }, pathfinder); nodes[5] = new OcTree(level + 1, new float[] { x - subWidth, y + subLength, z + subHeight, subWidth, subLength, subHeight }, pathfinder); nodes[6] = new OcTree(level + 1, new float[] { x - subWidth, y - subLength, z + subHeight, subWidth, subLength, subHeight }, pathfinder); nodes[7] = new OcTree(level + 1, new float[] { x + subWidth, y - subLength, z + subHeight, subWidth, subLength, subHeight }, pathfinder); }
private void DrawTree() { Gizmos.color = Color.red; if (pathfinder != null && pathfinder.seekerManager != null) { if (pathfinder.seekerManager.quadTree != null) { //quad List <QuadTree> openList = new List <QuadTree>(); openList.Add(pathfinder.seekerManager.quadTree as QuadTree); QuadTree current = null; while (openList.Count > 0) { current = openList[0]; Vector3 origin = new Vector3(pathfinder.worldStart.x + current.bounds.xMin, pathfinder.worldStart.y + pathfinder.worldHeight + 1, pathfinder.worldStart.z - current.bounds.yMin); Gizmos.DrawLine(origin, origin + new Vector3(current.bounds.width, 0, 0)); Gizmos.DrawLine(origin + new Vector3(current.bounds.width, 0, 0), origin + new Vector3(current.bounds.width, 0, -current.bounds.height)); Gizmos.DrawLine(origin + new Vector3(current.bounds.width, 0, -current.bounds.height), origin + new Vector3(0, 0, -current.bounds.height)); Gizmos.DrawLine(origin + new Vector3(0, 0, -current.bounds.height), origin); if (current.nodesInUse) { openList.Add(current.nodes[0]); openList.Add(current.nodes[1]); openList.Add(current.nodes[2]); openList.Add(current.nodes[3]); } openList.Remove(current); } } else { // oct Gizmos.color = new Color(1, 0, 0, 0.04F); List <OcTree> openList = new List <OcTree>(); openList.Add(pathfinder.seekerManager.octTree as OcTree); OcTree current = null; while (openList.Count > 0) { current = openList[0]; Gizmos.color = new Color(1, 0, 0, 0.1F + current.level * 0.1f); Gizmos.DrawCube(new Vector3(current.bounds[0], current.bounds[2], current.bounds[1]), new Vector3(current.bounds[3] * 2f, current.bounds[5] * 2f, current.bounds[4] * 2f)); if (current.nodesInUse) { openList.Add(current.nodes[0]); openList.Add(current.nodes[1]); openList.Add(current.nodes[2]); openList.Add(current.nodes[3]); openList.Add(current.nodes[4]); openList.Add(current.nodes[5]); openList.Add(current.nodes[6]); openList.Add(current.nodes[7]); } openList.Remove(current); } } } }