public void Visit(IQuadTree aQuadTree) { IUserObject insertedUserObject = this.insertedPoint.GetUserObject(); IShape insertedShape = insertedUserObject.GetShape(); IRectangle targetBoundary = CalculateTargetBoundary(insertedShape); if (null != aQuadTree.GetRootPoints()) { List <IPoint <IUserObject> > pointsToBeDeleted = new List <IPoint <IUserObject> > (); foreach (IPoint <IUserObject> currentPoint in aQuadTree.GetRootPoints()) { Visit(currentPoint); if (currentPoint.GetUserObject().GetHealth() < 1) { pointsToBeDeleted.Add(currentPoint); this.userObjectSpawner.PushBackDeadObject(currentPoint.GetUserObject()); } if (insertedUserObject.GetHealth() < 1) { this.userObjectSpawner.PushBackDeadObject(insertedUserObject); break; } } aQuadTree.RemovePointsFromRoot(pointsToBeDeleted); } }
public void Visit(IQuadTree aQuadTree) { if (null != this.insertedPoint) { IUserObject insertedUserObject = this.insertedPoint.GetUserObject(); IShape insertedShape = insertedUserObject.GetShape(); IRectangle targetBoundary = calculateTargetBoundary(insertedShape); ICollection <IPoint <IUserObject> > points = aQuadTree.GetPoints(targetBoundary, false); foreach (IPoint <IUserObject> currentPoint in points) { visit(currentPoint); if (currentPoint.GetUserObject().GetHealth() < 1) { aQuadTree.RemovePointFromRoot(currentPoint); this.userObjectSpawner.PushBackDeadObject(currentPoint.GetUserObject()); } if (insertedUserObject.GetHealth() < 1) { aQuadTree.RemovePointFromRoot(this.insertedPoint); this.userObjectSpawner.PushBackDeadObject(insertedUserObject); break; } } } }
/// <summary> /// CONSTRUCTOR for class CollisionManager /// </summary> public CollisionManager(SceneEntitiesDelegate pSceneGraph, SceneEntitiesDelegate pStatics, IQuadTree <IShape> pQuadTree) { // SET _sceneGraphEntities delegat to the delegate passed into the // constructor _sceneGraphEntities = pSceneGraph; // SET QuadTree to the QuadTree variable passed into the constructor QuadTree = pQuadTree; // SET _sat as a new type of SAT _sat = new SAT(); _staticEntities = pStatics; QuadTree.SetDelegate(CheckEntityCollisions); }
void Start() { Camera cam = Camera.main; float height = 2f * cam.orthographicSize; float width = height * cam.aspect; IRectangle boundary = new Rectangle((int)-width / 2, (int)-height / 2, (int)width, (int)height); Debug.Log(height); quadTree = new QuadTree(4, boundary); userObjectSpawner = new DefaultUserObjectSpawner(boundary); insertQuadTreeVisitor = new InsertQuadTreeVisitor(1, userObjectSpawner); debugRenderingQuadTreeVisitor = new DebugRenderingQuadTreeVisitor(); userObjectSpawner.SetUpperSpawnLimit(1000); userObjectSpawner.SetObjectInitialHealth(5); }
void Init() { waitForObjectCreation = new WaitForSecondsRealtime(objectCreatePeriod); Camera cam = Camera.main; float height = 2f * cam.orthographicSize; float width = height * cam.aspect; IRectangle boundary = new Rectangle(-width / 2, -height / 2, width, height); quadTree = new QuadTree(4, boundary); userObjectSpawner = new DefaultUserObjectSpawner(boundary, prefabCircle, prefabRectangle); insertQuadTreeVisitor = new InsertQuadTreeVisitor(1, userObjectSpawner); debugRenderingQuadTreeVisitor = new DebugRenderingQuadTreeVisitor(); userObjectSpawner.SetUpperSpawnLimit(PlayerPrefs.GetInt("NumberOfEntities")); userObjectSpawner.SetObjectInitialHealth(PlayerPrefs.GetInt("InitialHealth")); suitableForSpawn = true; Selection.activeGameObject = gameObject; }
public void Visit(IQuadTree aQuadTree) { DrawBoundary(aQuadTree.GetBoundary()); }
public void Visit(IQuadTree aQuadTree) { DrawBoundary(aQuadTree.GetBoundary()); DrawPoints(aQuadTree.GetRootPoints()); }
public static Stack <float2> AStar(IQuadTree quadTree, float2 start, float2 end, bool outputDeltaTime = false) { if (quadTree.CheackInited() == false) { return(null); } if (outputDeltaTime) { Stopwatch.Restart(); } var resolution = quadTree.Resolution; var iStart = new int2((int)(start.x * resolution), (int)(start.y * resolution)); var iEnd = new int2((int)(end.x * resolution), (int)(end.y * resolution)); var head = quadTree.Head; if (_visited == null || _visited.Length < quadTree.Count) { _visited = new bool[quadTree.Count]; } else { for (var i = 0; i < _visited.Length; i++) { _visited[i] = false; } } TempList.Clear(); quadTree.FindNodesWithoutObjects(head, iStart, iStart, TempList); Open.FakeClear(); for (var i = 0; i < TempList.Count; i++) { var temp = math.abs(((TempList[i].Max + TempList[i].Min) / 2 - iEnd)); TempList[i].Value = temp.x + temp.y; TempList[i].Dist2Start = 0; TempList[i].LastNode = null; Open.Push(TempList[i]); _visited[TempList[i].Id] = true; } Ans.Clear(); if (Open.Count == 0) { return(Ans); } var now = Open.Peek(); var minS = new int2[4]; var maxS = new int2[4]; while (Open.Count > 0) { now = Open.Pop(); if (now.Min.x <= iEnd.x && now.Min.y <= iEnd.y && now.Max.x >= iEnd.x && now.Max.y >= iEnd.y) { break; } minS[0] = new int2(now.Min.x - 1, now.Min.y - 1); maxS[0] = new int2(now.Max.x + 1, now.Min.y - 1); minS[1] = new int2(now.Max.x + 1, now.Min.y); maxS[1] = new int2(now.Max.x + 1, now.Max.y + 1); minS[2] = new int2(now.Min.x - 1, now.Max.y + 1); maxS[2] = new int2(now.Max.x, now.Max.y + 1); minS[3] = new int2(now.Min.x - 1, now.Min.y); maxS[3] = new int2(now.Min.x - 1, now.Max.y); for (var k = 0; k < 4; k++) { TempList.Clear(); quadTree.FindNodesWithoutObjects(head, in minS[k], in maxS[k], TempList);