Example #1
0
 public int CheckIfShouldAdd(Gameobject a_go)//returns 0 = added , 1 = close smaller , 2 = close larger , 3 = far small , 4 = far larger
 {
     //check x coordinates
     if (a_go.v2Position.X >= v4Coord.X && a_go.v2Position.X <= v4Coord.Z)
     {
         //check y coordinate
         if (a_go.v2Position.Y >= v4Coord.Y && a_go.v2Position.Y <= v4Coord.W)
         {
             Add(a_go);
             return(0);
         }
         else if (a_go.v2Position.Y < v4Coord.Y)
         {
             //x is right but y is smaller so check smaller index
             return(1);
         }
         else
         {
             //x is right but y is too big, so check larger index
             return(2);
         }
     }
     else if (a_go.v2Position.X < v4Coord.X)
     {
         //x is smaller so check a lower index
         return(3);
     }
     //x must be larger, so check a bigger index
     return(4);
 }
Example #2
0
        public void AddToGrid(Gameobject a_go)
        {
            int iIndex = (int)(Math.Ceiling((double)(aCells.Length / 2)));
            int result = aCells[iIndex].CheckIfShouldAdd(a_go);

            while (result != 0)
            {
                switch (result)
                {
                case 1:
                    //close smaller
                    iIndex = (int)MathHelper.Clamp(CalculateIndexLowerClose(iIndex), 0, aCells.Length);
                    break;

                case 2:
                    //close large                           (current index divided by iCellcountheight times icellcountheight do get upper bounds of column
                    iIndex = (int)MathHelper.Clamp(CalculateIndexUpperClose(iIndex), 0, aCells.Length);
                    break;

                case 3:
                    //far small
                    iIndex = (int)MathHelper.Clamp(iIndex / 2, 0, aCells.Length);
                    break;

                case 4:
                    //far big                           find remaining amount of cells, half that and add it the current index
                    iIndex = (int)MathHelper.Clamp(iIndex + (aCells.Length - iIndex) / 2, 0, aCells.Length);
                    break;
                }
                result = aCells[iIndex].CheckIfShouldAdd(a_go);
            }
        }
Example #3
0
 public void Add(Gameobject a_go)
 {
     lGameobjects.Add(a_go);
 }