Exemple #1
0
        public eDirection GetNeighbours(VoxPos Position)
        {
            eDirection Directions = 0;

            if (Check(1, 0, 0))
            {
                Directions |= eDirection.Right;
            }
            if (Check(-1, 0, 0))
            {
                Directions |= eDirection.Left;
            }

            if (Check(0, 1, 0))
            {
                Directions |= eDirection.Up;
            }
            if (Check(0, -1, 0))
            {
                Directions |= eDirection.Down;
            }

            if (Check(0, 0, 1))
            {
                Directions |= eDirection.Forward;
            }
            if (Check(0, 0, -1))
            {
                Directions |= eDirection.Backwards;
            }

            return(Directions);

            bool Check(int X_Offset, int Y_Offset, int Z_Offset)
            {
                int Neighbour_X = Position.X + X_Offset;
                int Neighbour_Y = Position.Y + Y_Offset;
                int Neighbour_Z = Position.Z + Z_Offset;

                if (!VoxPos.IsValidVoxPos(Neighbour_X, Neighbour_Y, Neighbour_Z))
                {
                    return(false);
                }

                VoxPos Pos = new VoxPos(Neighbour_X, Neighbour_Y, Neighbour_Z);

                return(IsWithin(Pos) && Data[To1D(Pos)] != 0);
            }
        }
Exemple #2
0
        public Voxel?GetVoxel(VoxPos Pos)
        {
            if (!IsWithin(Pos))
            {
                return(null);
            }

            byte Index = Data[To1D(Pos)];

            if (Index == 0)
            {
                return(null);
            }

            return(new Voxel
            {
                Position = Pos,
                Index = Index,
                Neighbours = GetNeighbours(Pos)
            });
        }
Exemple #3
0
 public int To1D(VoxPos Pos)
 {
     return(Pos.X + Pos.Y * Size_X + Pos.Z * Size_X * Size_Y);
 }
Exemple #4
0
 public byte GetIndex(VoxPos Pos) => Data[To1D(Pos)];
Exemple #5
0
 public void SetIndex(VoxPos Pos, byte Index) => Data[To1D(Pos)] = Index;
Exemple #6
0
 public bool IsWithin(VoxPos Pos) => Pos.X < Size_X && Pos.Y < Size_Y && Pos.Z < Size_Z;