private void InspectLeaf([NotNull] QuadTreeLeaf visitedLeaf, [NotNull] IAABBox viewBox) { var planetRawData = visitedLeaf.GetPlanetsRawData(); if (planetRawData == null) { return; } for (int i = 0; i < planetRawData.Length; ++i) { if (!IsPlanetInCamera(i, viewBox, visitedLeaf)) { continue; } var posToInsert = FindPosToInsert(mVisiblePlanets, i, visitedLeaf); if (posToInsert != -1) { mVisiblePlanets.Insert(posToInsert, visitedLeaf.GetPlanetData(i)); if (mVisiblePlanets.Count > mConstants.GetPlanetsToVisualize()) { mVisiblePlanets.RemoveAt(mVisiblePlanets.Count - 1); } continue; } if (mVisiblePlanets.Count < mConstants.GetPlanetsToVisualize()) { mVisiblePlanets.Add(visitedLeaf.GetPlanetData(i)); continue; } break; } }
public void VisitVisibleNodes(IAABBox cameraBox, INodeVisitor nodeVisitor) { if (!mBox.IsIntersect(cameraBox)) { return; } VisitNodes(nodeVisitor); }
public void VisitVisibleNodes(IAABBox cameraBox, INodeVisitor nodeVisitor) { if (!mBox.IsIntersect(cameraBox)) { return; } mTopLeft.VisitVisibleNodes(cameraBox, nodeVisitor); mTopRight.VisitVisibleNodes(cameraBox, nodeVisitor); mBottomLeft.VisitVisibleNodes(cameraBox, nodeVisitor); mBottomRight.VisitVisibleNodes(cameraBox, nodeVisitor); }
public QuadTreeNode([NotNull] IAABBox box , [NotNull] IQuadTreeNode topLeft , [NotNull] IQuadTreeNode topRight , [NotNull] IQuadTreeNode bottomLeft , [NotNull] IQuadTreeNode bottomRight) { mBox = box; mTopLeft = topLeft; mTopRight = topRight; mBottomLeft = bottomLeft; mBottomRight = bottomRight; }
public IReadOnlyList <PlanetData> GetVisiblePlanets(IAABBox viewBBox) { mVisiblePlanets.Clear(); mNodeVisitor.Clear(); mRootNodeProvider.GetRootNote().VisitVisibleNodes(viewBBox, mNodeVisitor); var leafCollection = mNodeVisitor.GetVisibleLeaves(); for (int i = 0; i < leafCollection.Count; ++i) { // ReSharper disable once AssignNullToNotNullAttribute InspectLeaf(leafCollection[i], viewBBox); } return(mVisiblePlanets); }
private bool IsPlanetInCamera(int planetIndex, [NotNull] IAABBox cameraBox, [NotNull] QuadTreeLeaf visitedLeaf) { var planetData = visitedLeaf.GetPlanetData(planetIndex); var cameraTop = cameraBox.GetY() + cameraBox.GetHeight() / 2f; var cameraBottom = cameraTop - cameraBox.GetHeight(); var cameraLeft = cameraBox.GetX() - cameraBox.GetWidth() / 2f; var cameraRight = cameraLeft + cameraBox.GetWidth(); if ((cameraTop >= planetData.Y && cameraBottom <= planetData.Y) && (cameraLeft <= planetData.X && cameraRight >= planetData.X)) { return(true); } return(false); }
public void Run(IAABBox startViewBox, IQuadTreeNode rootNode, IArrayBackgroundWorkerListener listener) { var visibleNodesCollector = new VisibleNodesCollector(); rootNode.VisitVisibleNodes(startViewBox, visibleNodesCollector); var planetFactory = mPlanetFactoryCreator.CreatePlanetFactory(); foreach (var curLeaf in visibleNodesCollector.GetVisibleLeaves()) { // ReSharper disable once PossibleNullReferenceException curLeaf.SetPlanets(planetFactory.CreatePlanetsForSector()); } var nodesInCameraCollector = new VisibleNodesCollector(); rootNode.VisitVisibleNodes(new AABBox(0f, 0f, mConstants.GetMaxCameraSize(), mConstants.GetMaxCameraSize()), nodesInCameraCollector); mBackgroundWorker.AddListener(listener); mBackgroundWorker.Run(nodesInCameraCollector.GetVisibleLeaves(), mPlanetFactoryCreator); }
public bool IsIntersect(IAABBox other) { return((Math.Abs(mX - other.GetX()) * 2 < (mWidth + other.GetWidth())) && (Math.Abs(mY - other.GetY()) * 2 < (mHeight + other.GetHeight()))); }
public bool IsIntersect(IAABBox other) { return((Math.Abs(GetX() - other.GetX()) * 2 < (GetWidth() + other.GetWidth())) && (Math.Abs(GetY() - other.GetY()) * 2 < (+other.GetHeight()))); }
public QuadTreeLeaf([NotNull] IAABBox box , [NotNull] IConstants constants) { mBox = box; mConstants = constants; }