コード例 #1
0
    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;
        }
    }
コード例 #2
0
ファイル: QuadTreeLeaf.cs プロジェクト: alext90a/Planets
 public void VisitVisibleNodes(IAABBox cameraBox, INodeVisitor nodeVisitor)
 {
     if (!mBox.IsIntersect(cameraBox))
     {
         return;
     }
     VisitNodes(nodeVisitor);
 }
コード例 #3
0
ファイル: QuadTreeNode.cs プロジェクト: alext90a/Planets
 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);
 }
コード例 #4
0
ファイル: QuadTreeNode.cs プロジェクト: alext90a/Planets
 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;
 }
コード例 #5
0
    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);
    }
コード例 #6
0
    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);
    }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: AABBox.cs プロジェクト: alext90a/Planets
 public bool IsIntersect(IAABBox other)
 {
     return((Math.Abs(mX - other.GetX()) * 2 < (mWidth + other.GetWidth())) &&
            (Math.Abs(mY - other.GetY()) * 2 < (mHeight + other.GetHeight())));
 }
コード例 #9
0
 public bool IsIntersect(IAABBox other)
 {
     return((Math.Abs(GetX() - other.GetX()) * 2 < (GetWidth() + other.GetWidth())) &&
            (Math.Abs(GetY() - other.GetY()) * 2 < (+other.GetHeight())));
 }
コード例 #10
0
ファイル: QuadTreeLeaf.cs プロジェクト: alext90a/Planets
 public QuadTreeLeaf([NotNull] IAABBox box
                     , [NotNull] IConstants constants)
 {
     mBox       = box;
     mConstants = constants;
 }