Exemplo n.º 1
0
        public bool Intersects(GridBounds3D bounds)
        {
            GridPoint3D otherMin = bounds.Min;
            GridPoint3D otherMax = bounds.Max;

            return(!(Min.X > otherMax.X || Min.Y > otherMax.Y || Min.Z > otherMax.Z ||
                     Max.X < otherMin.X || Max.Y < otherMin.Y || Max.Z < otherMin.Z));
        }
Exemplo n.º 2
0
 public bool Contains(GridPoint3D point, bool inclusive = false)
 {
     if (Min.X <= point.X && Min.Y <= point.Y && Min.Z <= point.Z)
     {
         if (inclusive)
         {
             return(Max.X >= point.X && Max.Y >= point.Y && Max.Z >= point.Z);
         }
         return(Max.X > point.X && Max.Y > point.Y && Max.Z > point.Z);
     }
     return(false);
 }
Exemplo n.º 3
0
        public GridCoord3D(GridSize3D size, int index)
        {
            Index = index;

            int x = (index % size.X);

            index /= size.X;
            int y = (index % size.Y);

            index /= size.Y;
            int z = index;

            Point = new GridPoint3D(x, y, z);
        }
Exemplo n.º 4
0
        public static GridCoord3D Create(GridSize3D size, GridAxes3D axes, int a, int b, int c)
        {
            GridPoint3D point = GridPoint3D.Create(axes, a, b, c);

            return(new GridCoord3D(size, point));
        }
Exemplo n.º 5
0
 public GridCoord3D(GridSize3D size, GridPoint3D point)
 {
     Point = point;
     Index = (point.Z * size.X * size.Y) + (point.Y * size.X) + point.X;
 }
Exemplo n.º 6
0
 public GridCoord3D(GridPoint3D point, int index)
 {
     Point = point;
     Index = index;
 }
Exemplo n.º 7
0
 public GridBounds3D(GridPoint3D min, GridPoint3D max)
 {
     Min = min;
     Max = max;
 }
Exemplo n.º 8
0
 public GridBounds3D(GridSize3D size)
 {
     Min = new GridPoint3D(0, 0, 0);
     Max = new GridPoint3D(size.X, size.Y, size.Z);
 }
Exemplo n.º 9
0
 public GridBounds3D(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
 {
     Min = new GridPoint3D(minX, minY, minZ);
     Max = new GridPoint3D(maxX, maxY, maxZ);
 }
Exemplo n.º 10
0
 public GridBounds3D(int maxX, int maxY, int maxZ)
 {
     Min = new GridPoint3D(0, 0, 0);
     Max = new GridPoint3D(maxX, maxY, maxZ);
 }
Exemplo n.º 11
0
 public bool Contains(GridPoint3D point)
 {
     return(point.X < X && point.Y < Y && point.Z < Z &&
            point.X >= 0 && point.Y >= 0 && point.Z >= 0);
 }
Exemplo n.º 12
0
 public GridHit3D(GridPoint3D point, EDirection3D face)
 {
     Point = point;
     Face  = face;
 }
Exemplo n.º 13
0
        public static int Raycast(float startX, float startY, float startZ, float directionX, float directionY, float directionZ, GridHit3D[] hitBuffer)
        {
            int stepX = Math.Sign(directionX);
            int stepY = Math.Sign(directionY);
            int stepZ = Math.Sign(directionZ);

            if (stepX == 0 && stepY == 0 && stepZ == 0)
            {
                return(0);
            }

            int bufferSize = hitBuffer.Length;

            int currentX = (int)Math.Floor(startX);
            int currentY = (int)Math.Floor(startY);
            int currentZ = (int)Math.Floor(startZ);

            currentX = Math.Max(currentX, 0);
            currentY = Math.Max(currentY, 0);
            currentZ = Math.Max(currentZ, 0);

            float nextBoundX = CalculateBound(currentX, startX, stepX);
            float nextBoundY = CalculateBound(currentY, startY, stepY);
            float nextBoundZ = CalculateBound(currentZ, startZ, stepZ);

            float deltaX = (1f / directionX) * stepX;
            float deltaY = (1f / directionY) * stepY;
            float deltaZ = (1f / directionZ) * stepZ;

            float travelX = nextBoundX / directionX;
            float travelY = nextBoundY / directionY;
            float travelZ = nextBoundZ / directionZ;

            int iterator = 0;

            EDirection3D xExitFace = (stepX > 0 ? EDirection3D.Left : EDirection3D.Right);
            EDirection3D yExitFace = (stepY > 0 ? EDirection3D.Down : EDirection3D.Up);
            EDirection3D zExitFace = (stepZ > 0 ? EDirection3D.Back : EDirection3D.Front);

            EDirection3D selectedFace;
            float        startDecimalX = startX - (float)Math.Truncate(startX);
            float        startDecimalY = startY - (float)Math.Truncate(startY);
            float        startDecimalZ = startZ - (float)Math.Truncate(startZ);

            if (startDecimalX < startDecimalY && startDecimalX < startDecimalZ)
            {
                selectedFace = (directionX > 0 ? EDirection3D.Left : EDirection3D.Right);
            }
            else if (startDecimalY < startDecimalX && startDecimalY < startDecimalZ)
            {
                selectedFace = (directionY > 0 ? EDirection3D.Down : EDirection3D.Up);
            }
            else
            {
                selectedFace = (directionZ > 0 ? EDirection3D.Back : EDirection3D.Front);
            }

            while (iterator < bufferSize)
            {
                GridPoint3D point = new GridPoint3D(currentX, currentY, currentZ);
                if (travelX < travelY)
                {
                    if (travelX < travelZ)
                    {
                        hitBuffer[iterator++] = new GridHit3D(point, selectedFace);
                        selectedFace          = xExitFace;

                        currentX += stepX;
                        travelX  += deltaX;
                    }
                    else
                    {
                        hitBuffer[iterator++] = new GridHit3D(point, selectedFace);
                        selectedFace          = zExitFace;

                        currentZ += stepZ;
                        travelZ  += deltaZ;
                    }
                }
                else
                {
                    if (travelY < travelZ)
                    {
                        hitBuffer[iterator++] = new GridHit3D(point, selectedFace);
                        selectedFace          = yExitFace;

                        currentY += stepY;
                        travelY  += deltaY;
                    }
                    else
                    {
                        hitBuffer[iterator++] = new GridHit3D(point, selectedFace);
                        selectedFace          = zExitFace;

                        currentZ += stepZ;
                        travelZ  += deltaZ;
                    }
                }
            }

            return(iterator);
        }