예제 #1
0
        public static void MirrorZ(CopyState state, BlockDefinition[] defs)
        {
            int midZ = (state.Length + 1) / 2, maxZ = state.Length - 1;

            state.OriginZ  = state.OppositeOriginZ;
            state.Offset.Z = -state.Offset.Z;
            BlockID[] transform = Transform(defs, mirrorZ, null);

            for (int y = 0; y < state.Height; y++)
            {
                for (int z = 0; z < midZ; z++)
                {
                    int endZ = maxZ - z;
                    int beg  = state.GetIndex(0, y, z);
                    int end  = state.GetIndex(0, y, endZ);

                    for (int x = 0; x < state.Width; x++)
                    {
                        BlockID blockA = transform[state.Get(beg)];
                        BlockID blockB = transform[state.Get(end)];
                        state.Set(blockB, beg); state.Set(blockA, end);
                        beg++; end++;
                    }
                }
            }
        }
예제 #2
0
        public static void MirrorY(CopyState state, BlockDefinition[] defs)
        {
            int midY = (state.Height + 1) / 2, maxY = state.Height - 1;

            state.OriginY  = state.OppositeOriginY;
            state.Offset.Y = -state.Offset.Y;
            BlockID[] transform = Transform(defs, mirrorY, null);

            for (int y = 0; y < midY; y++)
            {
                int endY = maxY - y;
                int beg  = state.GetIndex(0, y, 0);
                int end  = state.GetIndex(0, endY, 0);

                for (int z = 0; z < state.Length; z++)
                {
                    for (int x = 0; x < state.Width; x++)
                    {
                        BlockID blockA = transform[state.Get(beg)];
                        BlockID blockB = transform[state.Get(end)];
                        state.Set(blockB, beg); state.Set(blockA, end);
                        beg++; end++;
                    }
                }
            }
        }
예제 #3
0
        public static void MirrorX(CopyState state, BlockDefinition[] defs)
        {
            // ceiling division by 2, because for odd length, we still want to
            // mirror the middle row to rotate directional blocks
            int midX = (state.Width + 1) / 2, maxX = state.Width - 1;

            state.OriginX  = state.OppositeOriginX;
            state.Offset.X = -state.Offset.X;
            BlockID[] transform = Transform(defs, mirrorX, null);

            for (int y = 0; y < state.Height; y++)
            {
                for (int z = 0; z < state.Length; z++)
                {
                    for (int x = 0; x < midX; x++)
                    {
                        int endX = maxX - x;
                        int beg  = state.GetIndex(x, y, z);
                        int end  = state.GetIndex(endX, y, z);

                        BlockID blockA = transform[state.Get(beg)];
                        BlockID blockB = transform[state.Get(end)];
                        state.Set(blockB, beg); state.Set(blockA, end);
                    }
                }
            }
        }
예제 #4
0
        public static void MirrorZ(CopyState state, BlockDefinition[] defs)
        {
            int midX = (state.Width + 1) / 2, maxX = state.Width - 1;

            state.OriginX  = state.OppositeOriginX;
            state.Offset.X = -state.Offset.X;
            BlockID[] transform = Transform(defs, mirrorZ, null);

            for (int y = 0; y < state.Height; y++)
            {
                for (int z = 0; z < state.Length; z++)
                {
                    for (int x = 0; x < midX; x++)
                    {
                        int endX  = maxX - x;
                        int start = state.GetIndex(x, y, z);
                        int end   = state.GetIndex(endX, y, z);

                        BlockID blockA = transform[state.Get(start)];
                        BlockID blockB = transform[state.Get(end)];
                        state.Set(blockB, start); state.Set(blockA, end);
                    }
                }
            }
        }
예제 #5
0
        public static void MirrorX(CopyState state, BlockDefinition[] defs)
        {
            // ceiling division by 2, because for odd length, we still want to
            // mirror the middle row to rotate directional blocks
            int midZ = (state.Length + 1) / 2, maxZ = state.Length - 1;

            state.OriginZ  = state.OppositeOriginZ;
            state.Offset.Z = -state.Offset.Z;
            BlockID[] transform = Transform(defs, mirrorX, null);

            for (int y = 0; y < state.Height; y++)
            {
                for (int z = 0; z < midZ; z++)
                {
                    int endZ  = maxZ - z;
                    int start = state.GetIndex(0, y, z);
                    int end   = state.GetIndex(0, y, endZ);

                    for (int x = 0; x < state.Width; x++)
                    {
                        BlockID blockA = transform[state.Get(start)];
                        BlockID blockB = transform[state.Get(end)];
                        state.Set(blockB, start); state.Set(blockA, end);
                        start++; end++;
                    }
                }
            }
        }
예제 #6
0
        static CopyState Rotate(CopyState state, CopyState flipped, int[] m, BlockID[] transform)
        {
            int volume = state.Volume;

            for (int i = 0; i < volume; i++)
            {
                ushort x, y, z;
                state.GetCoords(i, out x, out y, out z);
                BlockID block = transform[state.Get(i)];

                flipped.Set(block,
                            Rotate(m[0], x, y, z, state),
                            Rotate(m[1], x, y, z, state),
                            Rotate(m[2], x, y, z, state));
            }

            int oX = state.OriginX - state.X, oY = state.OriginY - state.Y, oZ = state.OriginZ - state.Z;

            flipped.OriginX = state.X + Rotate(m[0], oX, oY, oZ, state);
            flipped.OriginY = state.Y + Rotate(m[1], oX, oY, oZ, state);
            flipped.OriginZ = state.Z + Rotate(m[2], oX, oY, oZ, state);

            // Offset is relative to Origin
            oX += state.Offset.X; oY += state.Offset.Y; oZ += state.Offset.Z;
            flipped.Offset.X = state.X + Rotate(m[0], oX, oY, oZ, state) - flipped.OriginX;
            flipped.Offset.Y = state.Y + Rotate(m[1], oX, oY, oZ, state) - flipped.OriginY;
            flipped.Offset.Z = state.Z + Rotate(m[2], oX, oY, oZ, state) - flipped.OriginZ;
            return(flipped);
        }