public virtual void DoReduce() { if (mesh.TriangleCount == 0) // badness if we don't catch this... { return; } begin_pass(); begin_setup(); Precompute(); InitializeVertexQuadrics(); InitializeQueue(); end_setup(); begin_ops(); begin_collapse(); while (EdgeQueue.Count > 0) { // termination criteria if (ReduceMode == TargetModes.VertexCount) { if (mesh.VertexCount <= TargetCount) { break; } } else { if (mesh.TriangleCount <= TargetCount) { break; } } COUNT_ITERATIONS++; int eid = EdgeQueue.Dequeue(); if (!mesh.IsEdge(eid)) { continue; } int vKept; ProcessResult result = CollapseEdge(eid, EdgeQuadrics[eid].collapse_pt, out vKept); if (result == ProcessResult.Ok_Collapsed) { vertQuadrics[vKept] = EdgeQuadrics[eid].q; UpdateNeighbours(vKept); } } end_collapse(); end_ops(); Reproject(); end_pass(); }
public void generateMaze() { EdgeQueue allEdges = new EdgeQueue(); Random rand = new Random(); /** This code is supposed to get all the edges from the grid as long as no unordered pair repeats. @Darren **/ for(int x = 0; x < Room.ROOM_WIDTH; x++){ for(int y = 0; y < Room.ROOM_HEIGHT; y++) { for (int dir = Room.LEFT; dir <= Room.DOWN; dir++) { Room source, destination; source = getRoom(x, y); destination = getRoomAt(source, dir); if (source != null && destination != null) { Edge temporary = new Edge(destination, source); if (!allEdges.Contains(temporary)) { allEdges.Add(temporary); } } } } } while(allEdges.Count > 0){ /** Current edge being tested @Darren */ Edge temp; /** Indices of the stack lists, initialized @Darren */ int a = -1, b = -1; /** take random edge, and remove it from the list @Darren */ temp = allEdges.Remove(rand.Next(allEdges.Count)); // Get index of both a and i for(int i = 0; i < sets.Count; i++) { if( sets.ElementAt(i).Contains(temp.getLeft())) // search for the cell in the sets a = i; if( sets.ElementAt(i).Contains(temp.getRight())) // search for the cell in the sets b = i; } /* If A and B are in the same set, no point in connecting them because it will create a cycle. * However, if they are of different sets, intersect the sets and leave one as null, and tear down * the wall. */ if(a != b) { // sample function only; connect the two cells /** Not sample code anymore. @Darren */ setRoomRelation(temp.getRight(), isToTheDirectionOf(temp.getLeft(), temp.getRight()), temp.getLeft()); // Join the sets of the formerly divided cells List<Room> LeftSet = getListThatContains(sets, temp.getLeft()); List<Room> RightSet = getListThatContains(sets, temp.getRight()); mergeRooms(LeftSet, RightSet); sets.Remove(RightSet); // Null the second set, it is useless now // done in mergeRooms(); // Add cell connection //edgesListOfMaze.add(temp); // not used in this program } } foreach (Room r in listOfRooms) { r.Initialize(roomDatabaseReference); } }
public virtual IEnumerable <int> ReduceToTriangleCount_Interactive(int nCount) { ReduceMode = TargetModes.TriangleCount; TargetCount = Math.Max(1, nCount); MinEdgeLength = double.MaxValue; if (mesh.TriangleCount == 0) // badness if we don't catch this... { yield break; } begin_pass(); begin_setup(); Precompute(); InitializeVertexQuadrics(); InitializeQueue(); end_setup(); begin_ops(); begin_collapse(); int count = PerFrameCount; while (EdgeQueue.Count > 0) { // termination criteria if (ReduceMode == TargetModes.VertexCount) { if (mesh.VertexCount <= TargetCount) { break; } } else { if (mesh.TriangleCount <= TargetCount) { break; } } int eid = EdgeQueue.Dequeue(); if (!mesh.IsEdge(eid)) { continue; } int vKept; ProcessResult result = CollapseEdge(eid, EdgeQuadrics[eid].collapse_pt, out vKept); if (result == ProcessResult.Ok_Collapsed) { vertQuadrics[vKept] = EdgeQuadrics[eid].q; UpdateNeighbours(vKept); } if (count-- == 0) { count = PerFrameCount; yield return(0); } } end_collapse(); end_ops(); Reproject(); end_pass(); }
public void generateMaze() { EdgeQueue allEdges = new EdgeQueue(); Random rand = new Random(); /** This code is supposed to get all the edges from the grid as long as no unordered pair repeats. @Darren **/ for (int x = 0; x < Room.ROOM_WIDTH; x++) { for (int y = 0; y < Room.ROOM_HEIGHT; y++) { for (int dir = Room.LEFT; dir <= Room.DOWN; dir++) { Room source, destination; source = getRoom(x, y); destination = getRoomAt(source, dir); if (source != null && destination != null) { Edge temporary = new Edge(destination, source); if (!allEdges.Contains(temporary)) { allEdges.Add(temporary); } } } } } while (allEdges.Count > 0) { /** Current edge being tested @Darren */ Edge temp; /** Indices of the stack lists, initialized @Darren */ int a = -1, b = -1; /** take random edge, and remove it from the list @Darren */ temp = allEdges.Remove(rand.Next(allEdges.Count)); // Get index of both a and i for (int i = 0; i < sets.Count; i++) { if (sets.ElementAt(i).Contains(temp.getLeft())) // search for the cell in the sets { a = i; } if (sets.ElementAt(i).Contains(temp.getRight())) // search for the cell in the sets { b = i; } } /* If A and B are in the same set, no point in connecting them because it will create a cycle. * However, if they are of different sets, intersect the sets and leave one as null, and tear down * the wall. */ if (a != b) { // sample function only; connect the two cells /** Not sample code anymore. @Darren */ setRoomRelation(temp.getRight(), isToTheDirectionOf(temp.getLeft(), temp.getRight()), temp.getLeft()); // Join the sets of the formerly divided cells List <Room> LeftSet = getListThatContains(sets, temp.getLeft()); List <Room> RightSet = getListThatContains(sets, temp.getRight()); mergeRooms(LeftSet, RightSet); sets.Remove(RightSet); // Null the second set, it is useless now // done in mergeRooms(); // Add cell connection //edgesListOfMaze.add(temp); // not used in this program } } foreach (Room r in listOfRooms) { r.Initialize(roomDatabaseReference); } }