Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="star"></param>
        public void AddStar(StarBufferIndex star)
        {
            Sector current = _root;

            while (current.HasSubdivided)
            {
                current = current.GetAppropriateChildSector(star);
            }

            _allStars.Add(star);

            current.AddStar(star);
        }
Example #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="star"></param>
 /// <returns></returns>
 public Sector GetAppropriateChildSector(StarBufferIndex star)
 {
     if (star.Buffer[star.Index].X < _averageX)
     {
         if (star.Buffer[star.Index].Y < _averageY)
         {
             if (star.Buffer[star.Index].Z < _averageZ)
             {
                 return _children[(int)SectorName.BottomLeftBack];
             }
             else
             {
                 return _children[(int)SectorName.BottomLeftFront];
             }
         }
         else
         {
             if (star.Buffer[star.Index].Z < _averageZ)
             {
                 return _children[(int)SectorName.TopLeftBack];
             }
             else
             {
                 return _children[(int)SectorName.TopLeftFront];
             }
         }
     }
     else
     {
         if (star.Buffer[star.Index].Y < _averageY)
         {
             if (star.Buffer[star.Index].Z < _averageZ)
             {
                 return _children[(int)SectorName.BottomRightBack];
             }
             else
             {
                 return _children[(int)SectorName.BottomRightFront];
             }
         }
         else
         {
             if (star.Buffer[star.Index].Z < _averageZ)
             {
                 return _children[(int)SectorName.TopRightFront];
             }
             else
             {
                 return _children[(int)SectorName.TopRightBack];
             }
         }
     }
 }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="star"></param>
        public void AddStar(StarBufferIndex star)
        {
            if (_stars == null)
                throw new Exception("Cannot add stars to a subdivided sector");

            _stars.AddLast(star);

            if (star.Buffer[star.Index].X > _maxX)
            {
                _maxX = (float)star.Buffer[star.Index].X;
            }
            else if (star.Buffer[star.Index].X < _minX)
            {
                _minX = (float)star.Buffer[star.Index].X;
            }

            if (star.Buffer[star.Index].Y > _maxY)
            {
                _maxY = (float)star.Buffer[star.Index].Y;
            }
            else if (star.Buffer[star.Index].Y < _minY)
            {
                _minY = (float)star.Buffer[star.Index].Y;
            }

            if (star.Buffer[star.Index].Z > _maxZ)
            {
                _maxZ = (float)star.Buffer[star.Index].Z;
            }
            else if (star.Buffer[star.Index].Z < _minZ)
            {
                _minZ = (float)star.Buffer[star.Index].Z;
            }

            _aggregateStarPosition.X += star.Buffer[star.Index].X;
            _aggregateStarPosition.Y += star.Buffer[star.Index].Y;
            _aggregateStarPosition.Z += star.Buffer[star.Index].Z;

            if (_stars.Count > MaxStarsPerSector)
            {
                DivideAndConquer();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public StarBufferIndex AddStar()
        {
            var starBufferIndex = new StarBufferIndex
            {
                Index  = _currentIndex,
                Buffer = _positionColorBuffer[_currentBuffer]
            };

            _starBufferIndexes[_currentBuffer][_currentIndex] = starBufferIndex;

            if (_currentIndex == _bufferSize - 1)
            {
                _currentIndex = 0;
                _currentBuffer++;
            }
            else
            {
                _currentIndex++;
            }

            return starBufferIndex;
        }