Exemplo n.º 1
0
 public CoordDir GetChunkCoord(CoordDir worldCoord, int chunkSize)          //gets chunk CoordDirinates using wholeterrain unit CoordDir
 {
     return(new CoordDir
            (
                worldCoord.x >= 0 ? (int)(worldCoord.x / chunkSize) : (int)((worldCoord.x + 1) / chunkSize) - 1,
                0,
                worldCoord.z >= 0 ? (int)(worldCoord.z / chunkSize) : (int)((worldCoord.z + 1) / chunkSize) - 1
            ));
 }
Exemplo n.º 2
0
        public Matrix3(CoordDir offset, CoordDir size, T[] array = null)
        {
            cube  = new CoordCube(offset, size);
            count = cube.size.x * cube.size.y * cube.size.z;

            if (array != null && array.Length < count)
            {
                Debug.LogError("Array length: " + array.Length + " is lower then matrix capacity: " + count);
            }
            if (array != null && array.Length >= count)
            {
                this.array = array;
            }
            else
            {
                this.array = new T[count];
            }
        }
Exemplo n.º 3
0
        public int GetPos(CoordDir c)
        {
                        #if WDEBUG
            if (c.x < offset.x || c.x >= offset.x + size.x)
            {
                throw new System.ArgumentOutOfRangeException("x", "Index Out Of Range (" + offset.x + "-" + (offset.x + size.x) + "): " + c.x);
            }
            if (c.y < offset.y || c.y >= offset.y + size.y)
            {
                throw new System.ArgumentOutOfRangeException("y", "Index Out Of Range (" + offset.y + "-" + (offset.y + size.y) + "): " + c.y);
            }
            if (c.z < offset.z || c.z >= offset.z + size.z)
            {
                throw new System.ArgumentOutOfRangeException("z", "Index Out Of Range (" + offset.z + "-" + (offset.z + size.z) + "): " + c.z);
            }
                        #endif

            return((c.z - offset.z) * size.x * size.y + (c.y - offset.y) * size.x + c.x - offset.x);
        }
Exemplo n.º 4
0
        public static CoordDir Max(CoordDir[] coords)
        {
            CoordDir max = new CoordDir(int.MinValue, int.MinValue, int.MinValue, 7);

            for (int i = 0; i < coords.Length; i++)
            {
                if (coords[i].x > max.x)
                {
                    max.x = coords[i].x;
                }
                if (coords[i].y > max.y)
                {
                    max.y = coords[i].y;
                }
                if (coords[i].z > max.z)
                {
                    max.z = coords[i].z;
                }
            }
            return(max);
        }
Exemplo n.º 5
0
        public static CoordDir Min(CoordDir[] coords)
        {
            CoordDir min = new CoordDir(int.MaxValue, int.MaxValue, int.MaxValue, 7);

            for (int i = 0; i < coords.Length; i++)
            {
                if (coords[i].x < min.x)
                {
                    min.x = coords[i].x;
                }
                if (coords[i].y < min.y)
                {
                    min.y = coords[i].y;
                }
                if (coords[i].z < min.z)
                {
                    min.z = coords[i].z;
                }
            }
            return(min);
        }
Exemplo n.º 6
0
        public T this[CoordDir c]
        {
            get {
                                #if WDEBUG
                if (c.x < cube.offset.x || c.x >= cube.offset.x + cube.size.x)
                {
                    throw new System.ArgumentOutOfRangeException("c", "Index Out Of Range (" + cube.offset.x + "-" + cube.offset.x + cube.size.x + "): " + c.x);
                }
                if (c.y < cube.offset.y || c.y >= cube.offset.y + cube.size.y)
                {
                    throw new System.ArgumentOutOfRangeException("c", "Index Out Of Range (" + cube.offset.y + "-" + cube.offset.y + cube.size.y + "): " + c.y);
                }
                if (c.z < cube.offset.z || c.z >= cube.offset.z + cube.size.z)
                {
                    throw new System.ArgumentOutOfRangeException("c", "Index Out Of Range (" + cube.offset.z + "-" + cube.offset.z + cube.size.z + "): " + c.z);
                }
                                #endif

                return(array[(c.z - cube.offset.z) * cube.size.x * cube.size.y + (c.y - cube.offset.y) * cube.size.x + c.x - cube.offset.x]);
            }

            set {
                                #if WDEBUG
                if (c.x < cube.offset.x || c.x >= cube.offset.x + cube.size.x)
                {
                    throw new System.ArgumentOutOfRangeException("x", "Index Out Of Range (" + cube.offset.x + "-" + cube.offset.x + cube.size.x + "): " + c.x);
                }
                if (c.y < cube.offset.y || c.y >= cube.offset.y + cube.size.y)
                {
                    throw new System.ArgumentOutOfRangeException("y", "Index Out Of Range (" + cube.offset.y + "-" + cube.offset.y + cube.size.y + "): " + c.y);
                }
                if (c.z < cube.offset.z || c.z >= cube.offset.z + cube.size.z)
                {
                    throw new System.ArgumentOutOfRangeException("z", "Index Out Of Range (" + cube.offset.z + "-" + cube.offset.z + cube.size.z + "): " + c.z);
                }
                                #endif

                array[(c.z - cube.offset.z) * cube.size.x * cube.size.y + (c.y - cube.offset.y) * cube.size.x + c.x - cube.offset.x] = value;
            }
        }
Exemplo n.º 7
0
 public CoordDir(CoordDir c, byte d)
 {
     this.x = c.x; this.y = c.y; this.z = c.z; this.dir = d;
 }
Exemplo n.º 8
0
 public bool Contains(CoordDir c)
 {
     return(c.x >= offset.x && c.x < offset.x + size.x &&
            c.y >= offset.y && c.y < offset.y + size.y &&
            c.z >= offset.z && c.z < offset.z + size.z);
 }
Exemplo n.º 9
0
 public int this[CoordDir c] {
     get { return((c.z - offset.z) * size.x * size.y + (c.y - offset.y) * size.x + c.x - offset.x); }
 }
Exemplo n.º 10
0
 public CoordCube(int offsetX, int offsetY, int offsetZ, int sizeX, int sizeY, int sizeZ)
 {
     this.offset = new CoordDir(offsetX, offsetY, offsetZ, 7); this.size = new CoordDir(sizeX, sizeY, sizeZ, 7);
 }
Exemplo n.º 11
0
 public CoordCube(CoordDir offset, CoordDir size)
 {
     this.offset = offset; this.size = size;
 }