예제 #1
0
 public void Set(MatrixView <T> mat, int x, int y, int z)
 {
     m_mat = mat.mat;
     m_x   = mat.x + x;
     m_y   = mat.y + y;
     m_z   = mat.z + z;
 }
예제 #2
0
        /// <inheritdoc />
        public CameraInfoCache(ICameraInfo cameraInfo)
        {
            // raw

            // world space -> camera space
            MatrixView        = Matrix4DEx.LookAtRH(cameraInfo.Position.ToVector3D(), cameraInfo.Target.ToVector3D(), cameraInfo.UpVector);
            MatrixViewInverse = MatrixView.Inverse();

            // camera space -> clip space
            MatrixProjection        = cameraInfo.Projection.GetMatrixProjection();
            MatrixProjectionInverse = MatrixProjection.Inverse();

            // clip space -> screen space
            MatrixViewport        = Matrix4DEx.Viewport(cameraInfo.Viewport);
            MatrixViewportInverse = MatrixViewport.Inverse();

            // multiplicatives

            // world space -> camera space -> clip space
            MatrixViewProjection        = MatrixView * MatrixProjection;
            MatrixViewProjectionInverse = MatrixViewProjection.Inverse();

            // world space -> camera space -> clip space -> screen space
            MatrixViewProjectionViewport        = MatrixViewProjection * MatrixViewport;
            MatrixViewProjectionViewportInverse = MatrixViewProjectionViewport.Inverse();
        }
예제 #3
0
        public static void Test2()
        {
            const uint MARGIN = 1;

            Matrix mA = new Matrix(2 + MARGIN, 3 + MARGIN);
            Matrix mB = new Matrix(3, 2);
            Matrix mC = new Matrix(2, 2);

            mA.SetValue(0 + MARGIN, 0 + MARGIN, 0.11);
            mA.SetValue(0 + MARGIN, 1 + MARGIN, 0.12);
            mA.SetValue(0 + MARGIN, 2 + MARGIN, 0.13);
            mA.SetValue(1 + MARGIN, 0 + MARGIN, 0.21);
            mA.SetValue(1 + MARGIN, 1 + MARGIN, 0.22);
            mA.SetValue(1 + MARGIN, 2 + MARGIN, 0.23);

            mB.SetValue(0, 0, 1011);
            mB.SetValue(0, 1, 1012);
            mB.SetValue(1, 0, 1021);
            mB.SetValue(1, 1, 1022);
            mB.SetValue(2, 0, 1031);
            mB.SetValue(2, 1, 1032);

            MatrixView mViewA = new MatrixView(mA, MARGIN, MARGIN, mA.Columns - MARGIN, mA.Rows - MARGIN);
            MatrixView mViewB = new MatrixView(mB, 0, 0, mB.Columns, mB.Rows);
            MatrixView mViewC = new MatrixView(mC, 0, 0, mC.Columns, mC.Rows);
            Blas.DGemm(Blas.TransposeType.NoTranspose, Blas.TransposeType.NoTranspose, 1.0, mViewA, mViewB, 0.0, ref mViewC);

            Console.WriteLine(mC.GetValue(0, 0) + " , " + mC.GetValue(0, 1));
            Console.WriteLine(mC.GetValue(1, 0) + " , " + mC.GetValue(1, 1));
        }
예제 #4
0
        public AddPage()
        {
            InitializeComponent();

            button1.Content = new ImageButton();
            button2.Content = new ImageButtonDelete();
            _sampleA = new ListBoxMatrixItem(new MatrixView(2, 2, false) { MatrixName = "SampleA" });
            _sampleB = new ListBoxMatrixItem(new MatrixView(3, 3, false) { MatrixName = "SampleB" });
            _listboxMatrixItems = new List<ListBoxMatrixItem> {_sampleA, _sampleB};

            if (IsolatedStorageSettings.ApplicationSettings.Contains("userData"))
            {
                List<PortableMatrix> matrixList = IsolatedStorageSettings.ApplicationSettings["userData"] as List<PortableMatrix>;
                if (matrixList != null)
                    foreach (PortableMatrix matrix in matrixList)
                    {
                        MatrixLibrary.Matrix newMatrix = new MatrixLibrary.Matrix(matrix.ToTwoDimensionalArray(matrix.MatrixArray));
                        MatrixView mView = new MatrixView(newMatrix.NoCols, newMatrix.NoRows, false);
                        mView.UpdateMatrix(newMatrix);
                        mView.MatrixName = matrix.MatrixName;
                        _listboxMatrixItems.Add(new ListBoxMatrixItem(mView));
                    }
            }
            listBox1.ItemsSource = _listboxMatrixItems;
            this.listBox1.SelectedItem = _sampleB;
            ApplicationBar = new ApplicationBar {IsVisible = true, Mode = ApplicationBarMode.Default, Opacity = 0.5};
            ApplicationBarIconButton saveButton = new ApplicationBarIconButton(){IconUri = new Uri("/Image/save.png", UriKind.Relative), IsEnabled = true, Text = "Save"};
            saveButton.Click += new EventHandler(SaveButtonClick);
            ApplicationBar.Buttons.Add(saveButton);
        }
예제 #5
0
        public static void Test2()
        {
            const uint MARGIN = 1;

            Matrix mA = new Matrix(2 + MARGIN, 3 + MARGIN);
            Matrix mB = new Matrix(3, 2);
            Matrix mC = new Matrix(2, 2);

            mA.SetValue(0 + MARGIN, 0 + MARGIN, 0.11);
            mA.SetValue(0 + MARGIN, 1 + MARGIN, 0.12);
            mA.SetValue(0 + MARGIN, 2 + MARGIN, 0.13);
            mA.SetValue(1 + MARGIN, 0 + MARGIN, 0.21);
            mA.SetValue(1 + MARGIN, 1 + MARGIN, 0.22);
            mA.SetValue(1 + MARGIN, 2 + MARGIN, 0.23);

            mB.SetValue(0, 0, 1011);
            mB.SetValue(0, 1, 1012);
            mB.SetValue(1, 0, 1021);
            mB.SetValue(1, 1, 1022);
            mB.SetValue(2, 0, 1031);
            mB.SetValue(2, 1, 1032);

            MatrixView mViewA = new MatrixView(mA, MARGIN, MARGIN, mA.Columns - MARGIN, mA.Rows - MARGIN);
            MatrixView mViewB = new MatrixView(mB, 0, 0, mB.Columns, mB.Rows);
            MatrixView mViewC = new MatrixView(mC, 0, 0, mC.Columns, mC.Rows);

            Blas.DGemm(Blas.TransposeType.NoTranspose, Blas.TransposeType.NoTranspose, 1.0, mViewA, mViewB, 0.0, ref mViewC);

            Console.WriteLine(mC.GetValue(0, 0) + " , " + mC.GetValue(0, 1));
            Console.WriteLine(mC.GetValue(1, 0) + " , " + mC.GetValue(1, 1));
        }
예제 #6
0
        public ViewMatrix(Matrix m)
        {
            InitializeComponent();
            MatrixView mv = new MatrixView();

            mv.Dock = DockStyle.Fill;
            this.Controls.Add(mv);
            mv.Matrix(m);
        }
예제 #7
0
 public static void ShowDistanceMatrixDialog()
 {
     PedanticCheck();
     if (DistanceMatrix.Matrix != null)
     {
         MatrixView window = new MatrixView();
         window.ShowDialog();
     }
     else
     {
         throw new InvalidOperationException("Distance matrix wasn't generated yet.");
     }
 }
예제 #8
0
    public override void Render(Vector3 pos, MatrixView <BlockData> neighbors, MeshParams <WorldVertexDefinition> meshParams)
    {
        var       block    = neighbors.GetCenter();
        ShapeType shape    = GetShapeTypeData(block.data);
        Rotation  rotation = GetRotationData(block.data);

        if (m_data == null)
        {
            m_data = new BlockRendererData(id, m_material);
        }
        m_data.SetFaceUV(new Rect(0.25f, 0, 0.25f, 1)
                         , new Rect(0.5f, 0, 0.25f, 1)
                         , new Rect(0.0f, 0, 0.25f, 1));
        m_data.rotation = rotation;

        SetDrawFacesFromNeighbors(m_data, neighbors);

        switch (shape)
        {
        case ShapeType.AntiTetrahedral:
            BlockRenderer.DrawAntiTetrahedral(pos, meshParams, m_data);
            break;

        case ShapeType.Cubic:
            BlockRenderer.DrawCubic(pos, meshParams, m_data);
            break;

        case ShapeType.HalfCubic:
            BlockRenderer.DrawHalfCubic(pos, meshParams, m_data);
            break;

        case ShapeType.HorizontalHalfCubic:
            BlockRenderer.DrawHorizontalHalfCubic(pos, meshParams, m_data);
            break;

        case ShapeType.SmallPyramid:
            BlockRenderer.DrawSmallPyramid(pos, meshParams, m_data);
            break;

        case ShapeType.Tetrahedral:
            BlockRenderer.DrawThetrahedral(pos, meshParams, m_data);
            break;

        default:
            Debug.Assert(false);
            break;
        }
    }
예제 #9
0
    public override BlockData UpdateBlock(MatrixView <BlockData> neighbors)
    {
        var data = neighbors.GetCenter();

        if (IsNoOverrideData(data.data))
        {
            return(neighbors.GetCenter());
        }

        ShapeType shape;
        Rotation  rotation;

        GetBlockType(neighbors, out shape, out rotation);
        data.data = MakeData(rotation, shape, false);
        return(data);
    }
예제 #10
0
        public CameraInfoCache(ICameraInfo cameraInfo)
        {
            MatrixView        = Matrix4DEx.LookAtRH(cameraInfo.Position.ToVector3D(), cameraInfo.Target.ToVector3D(), cameraInfo.UpVector);
            MatrixViewInverse = MatrixView.Inverse();

            MatrixProjection        = cameraInfo.Projection.GetMatrixProjection();
            MatrixProjectionInverse = MatrixProjection.Inverse();

            MatrixViewport        = Matrix4DEx.Viewport(cameraInfo.Viewport);
            MatrixViewportInverse = MatrixViewport.Inverse();

            MatrixViewProjection        = MatrixView * MatrixProjection;
            MatrixViewProjectionInverse = MatrixViewProjection.Inverse();

            MatrixViewProjectionViewport        = MatrixViewProjection * MatrixViewport;
            MatrixViewProjectionViewportInverse = MatrixViewProjectionViewport.Inverse();
        }
예제 #11
0
    static void UpdateWorldData(World world)
    {
        Matrix <BlockData>     mat  = new Matrix <BlockData>(Chunk.chunkSize + 2, Chunk.chunkSize + 2, Chunk.chunkSize + 2);
        MatrixView <BlockData> view = new MatrixView <BlockData>(mat, 0, 0, 0);

        for (int i = 0; i < world.chunkNb; i++)
        {
            for (int j = 0; j < world.chunkNb; j++)
            {
                var chunk  = world.GetChunk(i, j);
                var layers = chunk.GetLayers();

                foreach (var l in layers)
                {
                    world.GetLocalMatrix(i * Chunk.chunkSize - 1, l * Chunk.chunkSize - 1, j * Chunk.chunkSize - 1, mat);

                    for (int x = 0; x < Chunk.chunkSize; x++)
                    {
                        for (int y = 0; y < Chunk.chunkSize; y++)
                        {
                            for (int z = 0; z < Chunk.chunkSize; z++)
                            {
                                view.SetPos(x + 1, y + 1, z + 1);
                                view.Set(0, 0, 0, BlockTypeList.instance.Get(view.GetCenter().id).UpdateBlock(view));
                            }
                        }
                    }

                    for (int y = 0; y < Chunk.chunkSize; y++)
                    {
                        int height = chunk.LayerToHeight(l, y);
                        for (int x = 0; x < Chunk.chunkSize; x++)
                        {
                            for (int z = 0; z < Chunk.chunkSize; z++)
                            {
                                chunk.SetBlock(x, height, z, mat.Get(x + 1, y + 1, z + 1));
                            }
                        }
                    }
                }
            }
        }
    }
예제 #12
0
 private void Bbutton1Click(object sender, RoutedEventArgs e)
 {
     _vibrate.Start(TimeSpan.FromMilliseconds(10));
     if (((PopupControl)_pop.Child).textBox1.Text == string.Empty)
     {
         ((PopupControl) _pop.Child).textBox1.Text = "Unamed Matrix";
     }
     MatrixView matrix = new MatrixView(((PopupControl) _pop.Child).SelectedColumn,
                                        ((PopupControl) _pop.Child).SelectedRow, false)
                             {
                                 MatrixName = ((PopupControl) _pop.Child).SelectedName
                             };
     ListBoxMatrixItem listboxmatrix = new ListBoxMatrixItem(matrix);
     _listboxMatrixItems.Add(listboxmatrix);
     listBox1.ItemsSource = null;
     listBox1.ItemsSource = _listboxMatrixItems;
     listBox1.SelectedItem = listboxmatrix;
     _pop.IsOpen = false;
     this.IsEnabled = true;
 }
예제 #13
0
    public void SetBlock(int x, int y, int z, BlockData block, bool updateData = true)
    {
        if (updateData)
        {
            //create a local 5*5*5 matrix
            var matrix = GetLocalMatrix(x - 2, y - 2, z - 2, 5, 5, 5);
            var view   = new MatrixView <BlockData>(matrix, 2, 2, 2);
            view.Set(0, 0, 0, block);

            Vector3Int[] updatePositions = new Vector3Int[]
            {
                //center
                new Vector3Int(2, 2, 2),
                //cross
                new Vector3Int(2, 1, 2),
                new Vector3Int(1, 2, 2),
                new Vector3Int(2, 2, 1),
                new Vector3Int(3, 2, 2),
                new Vector3Int(2, 2, 3),
                new Vector3Int(2, 3, 2),
                //borders
                new Vector3Int(1, 1, 2), //down
                new Vector3Int(2, 1, 1),
                new Vector3Int(3, 1, 2),
                new Vector3Int(2, 1, 3),
                new Vector3Int(1, 2, 1), //midle
                new Vector3Int(3, 2, 1),
                new Vector3Int(1, 2, 3),
                new Vector3Int(3, 2, 3),
                new Vector3Int(1, 3, 2), //up
                new Vector3Int(2, 3, 1),
                new Vector3Int(3, 3, 2),
                new Vector3Int(2, 3, 3),
                //corners
                new Vector3Int(1, 1, 1), //down
                new Vector3Int(1, 1, 3),
                new Vector3Int(3, 1, 1),
                new Vector3Int(3, 1, 3),
                new Vector3Int(1, 3, 1), //up
                new Vector3Int(1, 3, 3),
                new Vector3Int(3, 3, 1),
                new Vector3Int(3, 3, 3),
            };

            foreach (var pos in updatePositions)
            {
                view.SetPos(pos.x, pos.y, pos.z);
                view.Set(0, 0, 0, BlockTypeList.instance.Get(view.GetCenter().id).UpdateBlock(view));
            }

            //only update the 3*3* center of the matrix
            SetBlocks(x - 1, y - 1, z - 1, matrix, 1, 1, 1, 3, 3, 3, false);
        }
        else
        {
            int chunkX;
            int chunkZ;
            int blockX;
            int blockZ;
            PosToBlockPosAndChunkPos(x, z, out blockX, out blockZ, out chunkX, out chunkZ);

            var chunk = GetChunk(chunkX, chunkZ);
            Debug.Assert(chunk != null);

            lock (dataLock)
            {
                chunk.SetBlock(blockX, y, blockZ, block);
            }
        }
    }
예제 #14
0
        public static void TestInverse()
        {
            //----------------------
            //| 0.18 | 0.41 | 0.14 |
            //| 0.60 | 0.24 | 0.30 |
            //| 0.57 | 0.99 | 0.97 |
            //----------------------

            Matrix matrix  = new Matrix(3, 3);
            Matrix matrix2 = new Matrix(4, 4);

            matrix.SetValue(0, 0, 0.18);
            matrix.SetValue(0, 1, 0.41);
            matrix.SetValue(0, 2, 0.14);
            matrix.SetValue(1, 0, 0.60);
            matrix.SetValue(1, 1, 0.24);
            matrix.SetValue(1, 2, 0.30);
            matrix.SetValue(2, 0, 0.57);
            matrix.SetValue(2, 1, 0.99);
            matrix.SetValue(2, 2, 0.97);
            double[,] test = matrix.ToArray();
            for (uint i = 0; i < matrix.Columns; i++)
            {
                for (uint j = 0; j < matrix.Rows; j++)
                {
                    matrix2.SetValue(i + 1, j + 1, matrix.GetValue(i, j));
                }
            }

            //LU分解による方法
            Matrix      inv = new Matrix(3, 3);
            int         sig;
            Permutation perm = new Permutation(3);

            perm.Initialize();
            LinearAlgebra.LUDecomposition(ref matrix, ref perm, out sig);
            LinearAlgebra.LUInvert(matrix, perm, ref inv);
            for (uint i = 0; i < inv.Columns; i++)
            {
                for (uint j = 0; j < inv.Rows; j++)
                {
                    Console.Write(inv.GetValue(i, j).ToString("F4").PadLeft(8) + " | ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            //部分行列のテスト
            perm.Initialize();
            Matrix     inv2     = new Matrix(4, 4);
            MatrixView mView    = new MatrixView(matrix2, 1, 1, 3, 3);
            MatrixView mViewINV = new MatrixView(inv2, 0, 1, 3, 3);

            LinearAlgebra.LUDecomposition(ref mView, ref perm, out sig);
            LinearAlgebra.LUInvert(mView, perm, ref mViewINV);
            for (uint i = 0; i < mViewINV.ColumnSize; i++)
            {
                for (uint j = 0; j < mViewINV.RowSize; j++)
                {
                    Console.Write(mViewINV.GetValue(i, j).ToString("F4").PadLeft(8) + " | ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            for (uint i = 0; i < inv2.Columns; i++)
            {
                for (uint j = 0; j < inv2.Rows; j++)
                {
                    Console.Write(inv2.GetValue(i, j).ToString("F4").PadLeft(8) + " | ");
                }
                Console.WriteLine();
            }

            Console.Read();
        }
예제 #15
0
 private static MatrixView ToMatrixView(PortableMatrix portableMatrix)
 {
     MatrixView mView = new MatrixView(portableMatrix.Columns, portableMatrix.Rows, false);
     mView.UpdateMatrix(new MatrixLibrary.Matrix(portableMatrix.ToTwoDimensionalArray(portableMatrix.MatrixArray)));
     mView.MatrixName = portableMatrix.MatrixName;
     return mView;
 }
예제 #16
0
 public override BlockData UpdateBlock(MatrixView <BlockData> neighbors)
 {
     return(neighbors.GetCenter());
 }
예제 #17
0
 public override void Render(Vector3 pos, MatrixView <BlockData> neighbors, MeshParams <WorldVertexDefinition> meshParams)
 {
     //do nothing here, it's an empty block
 }
예제 #18
0
 public void Set(MatrixView <T> mat, int x, int z)
 {
     Set(mat, x, 0, z);
 }
예제 #19
0
 public abstract void Render(Vector3 pos, MatrixView <BlockData> neighbors, MeshParams <WorldVertexDefinition> meshParams);
예제 #20
0
 public MatrixView(MatrixView <T> mat, int x, int z)
 {
     Set(mat, x, z);
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ListBoxMatrixItem"/> class.
 /// </summary>
 /// <param name="matrixView">The matrix view.</param>
 public ListBoxMatrixItem(MatrixView matrixView)
 {
     _matrixView = matrixView;
 }
예제 #22
0
        public static void TestInverse()
        {
            //----------------------
            //| 0.18 | 0.41 | 0.14 |
            //| 0.60 | 0.24 | 0.30 |
            //| 0.57 | 0.99 | 0.97 |
            //----------------------

            Matrix matrix = new Matrix(3, 3);
            Matrix matrix2 = new Matrix(4, 4);
            matrix.SetValue(0, 0, 0.18);
            matrix.SetValue(0, 1, 0.41);
            matrix.SetValue(0, 2, 0.14);
            matrix.SetValue(1, 0, 0.60);
            matrix.SetValue(1, 1, 0.24);
            matrix.SetValue(1, 2, 0.30);
            matrix.SetValue(2, 0, 0.57);
            matrix.SetValue(2, 1, 0.99);
            matrix.SetValue(2, 2, 0.97);
            double[,] test = matrix.ToArray();
            for (uint i = 0; i < matrix.Columns; i++)
            {
                for (uint j = 0; j < matrix.Rows; j++)
                {
                    matrix2.SetValue(i + 1, j + 1, matrix.GetValue(i, j));
                }
            }

            //LU分解による方法
            Matrix inv = new Matrix(3, 3);
            int sig;
            Permutation perm = new Permutation(3);
            perm.Initialize();
            LinearAlgebra.LUDecomposition(ref matrix, ref perm, out sig);
            LinearAlgebra.LUInvert(matrix, perm, ref inv);
            for (uint i = 0; i < inv.Columns; i++)
            {
                for (uint j = 0; j < inv.Rows; j++)
                {
                    Console.Write(inv.GetValue(i, j).ToString("F4").PadLeft(8) + " | ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            //部分行列のテスト
            perm.Initialize();
            Matrix inv2 = new Matrix(4, 4);
            MatrixView mView = new MatrixView(matrix2, 1, 1, 3, 3);
            MatrixView mViewINV = new MatrixView(inv2, 0, 1, 3, 3);
            LinearAlgebra.LUDecomposition(ref mView, ref perm, out sig);
            LinearAlgebra.LUInvert(mView, perm, ref mViewINV);
            for (uint i = 0; i < mViewINV.ColumnSize; i++)
            {
                for (uint j = 0; j < mViewINV.RowSize; j++)
                {
                    Console.Write(mViewINV.GetValue(i, j).ToString("F4").PadLeft(8) + " | ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            for (uint i = 0; i < inv2.Columns; i++)
            {
                for (uint j = 0; j < inv2.Rows; j++)
                {
                    Console.Write(inv2.GetValue(i, j).ToString("F4").PadLeft(8) + " | ");
                }
                Console.WriteLine();
            }

            Console.Read();
        }
예제 #23
0
    public static void GetBlockType(MatrixView <BlockData> neighbors, out ShapeType shape, out Rotation rotation)
    {
        ushort id = neighbors.GetCenter().id;

        Matrix <bool> blocks = new Matrix <bool>(3, 3, 3);

        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                for (int k = -1; k <= 1; k++)
                {
                    var b = neighbors.Get(i, j, k);

                    blocks.Set(i + 1, j + 1, k + 1, b.id == id || BlockTypeList.instance.Get(b.id).IsFull());
                }
            }
        }

        foreach (var b in m_shapes)
        {
            foreach (var rot in Enum.GetValues(typeof(Rotation)))
            {
                bool validBlock = true;

                for (int i = -1; i <= 1; i++)
                {
                    for (int j = -1; j <= 1; j++)
                    {
                        for (int k = -1; k <= 1; k++)
                        {
                            bool block = blocks.Get(i + 1, j + 1, k + 1);
                            int  state = b.GetState(i, j, k, (Rotation)rot);
                            if (state == 2)
                            {
                                continue;
                            }

                            if ((state == 0 && !block) || (state == 1 && block))
                            {
                                continue;
                            }

                            validBlock = false;
                            break;
                        }
                        if (!validBlock)
                        {
                            break;
                        }
                    }
                    if (!validBlock)
                    {
                        break;
                    }
                }

                if (validBlock)
                {
                    shape    = b.shape;
                    rotation = RotationEx.SubRotations(b.rotation, (Rotation)rot);
                    return;
                }
            }
        }

        Debug.Assert(false);
        shape    = ShapeType.Cubic;
        rotation = Rotation.Rot0;
    }
예제 #24
0
    void SetDrawFacesFromNeighbors(BlockRendererData data, MatrixView <BlockData> neighbors)
    {
        var left    = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Left));
        var right   = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Right));
        var up      = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Up));
        var down    = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Down));
        var front   = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Front));
        var back    = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Back));
        var current = neighbors.GetCenter();

        bool drawLeft  = !BlockTypeList.instance.Get(left.id).IsFaceFull(BlockFace.Right, left.data);
        bool drawRight = !BlockTypeList.instance.Get(right.id).IsFaceFull(BlockFace.Left, right.data);
        bool drawUp    = !BlockTypeList.instance.Get(up.id).IsFaceFull(BlockFace.Down, up.data);
        bool drawDown  = !BlockTypeList.instance.Get(down.id).IsFaceFull(BlockFace.Up, down.data);
        bool drawFront = !BlockTypeList.instance.Get(front.id).IsFaceFull(BlockFace.Back, front.data);
        bool drawBack  = !BlockTypeList.instance.Get(back.id).IsFaceFull(BlockFace.Front, back.data);

        m_data.SetFaceDraw(drawLeft, BlockFace.Left);
        m_data.SetFaceDraw(drawRight, BlockFace.Right);
        m_data.SetFaceDraw(drawUp, BlockFace.Up);
        m_data.SetFaceDraw(drawDown, BlockFace.Down);
        m_data.SetFaceDraw(drawFront, BlockFace.Front);
        m_data.SetFaceDraw(drawBack, BlockFace.Back);

        ShapeType shape    = GetShapeTypeData(current.data);
        Rotation  rotation = GetRotationData(current.data);

        if (shape == ShapeType.HalfCubic)
        {
            var leftFace  = BlockFaceEx.Rotate(BlockFace.Left, rotation);
            var rightFace = BlockFaceEx.Rotate(BlockFace.Right, rotation);

            if (m_data.GetFaceDraw(leftFace))
            {
                var leftBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(leftFace));

                if (BlockTypeList.instance.Get(leftBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType leftShape    = GetShapeTypeData(leftBlock.data);
                    Rotation  leftRotation = GetRotationData(leftBlock.data);

                    if (leftShape == ShapeType.HalfCubic && leftRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, leftFace);
                    }

                    if (leftShape == ShapeType.Tetrahedral && leftRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, leftFace);
                    }

                    if (leftShape == ShapeType.AntiTetrahedral && RotationEx.SubRotations(leftRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, leftFace);
                    }
                }
            }

            if (m_data.GetFaceDraw(rightFace))
            {
                var rightBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(rightFace));

                if (BlockTypeList.instance.Get(rightBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType rightShape    = GetShapeTypeData(rightBlock.data);
                    Rotation  rightRotation = GetRotationData(rightBlock.data);

                    if (rightShape == ShapeType.HalfCubic && rightRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.Tetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }
                }
            }
        }

        if (shape == ShapeType.Tetrahedral)
        {
            var backFace  = BlockFaceEx.Rotate(BlockFace.Back, rotation);
            var rightFace = BlockFaceEx.Rotate(BlockFace.Right, rotation);

            if (m_data.GetFaceDraw(BlockFace.Down))
            {
                var downBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Down));

                if (BlockTypeList.instance.Get(downBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType downShape    = GetShapeTypeData(downBlock.data);
                    Rotation  downRotation = GetRotationData(downBlock.data);

                    if (downShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(downRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Down);
                    }

                    if (downShape == ShapeType.HorizontalHalfCubic && downRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Down);
                    }
                }
            }

            if (m_data.GetFaceDraw(backFace))
            {
                var backBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(backFace));

                if (BlockTypeList.instance.Get(backBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType backShape    = GetShapeTypeData(backBlock.data);
                    Rotation  backRotation = GetRotationData(backBlock.data);

                    if (backShape == ShapeType.HalfCubic && RotationEx.SubRotations(backRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }

                    if (backShape == ShapeType.Tetrahedral && RotationEx.SubRotations(backRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }

                    if (backShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(backRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }
                }
            }

            if (m_data.GetFaceDraw(rightFace))
            {
                var rightBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(rightFace));

                if (BlockTypeList.instance.Get(rightBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType rightShape    = GetShapeTypeData(rightBlock.data);
                    Rotation  rightRotation = GetRotationData(rightBlock.data);

                    if (rightShape == ShapeType.HalfCubic && rightRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.Tetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }
                }
            }
        }

        if (shape == ShapeType.AntiTetrahedral)
        {
            var backFace  = BlockFaceEx.Rotate(BlockFace.Back, rotation);
            var rightFace = BlockFaceEx.Rotate(BlockFace.Right, rotation);

            if (m_data.GetFaceDraw(BlockFace.Up))
            {
                var upBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Up));

                if (BlockTypeList.instance.Get(upBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType upShape    = GetShapeTypeData(upBlock.data);
                    Rotation  upRotation = GetRotationData(upBlock.data);

                    if (upShape == ShapeType.Tetrahedral && RotationEx.AddRotations(upRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Up);
                    }

                    if (upShape == ShapeType.HorizontalHalfCubic && RotationEx.AddRotations(upRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Up);
                    }
                }
            }

            if (m_data.GetFaceDraw(backFace))
            {
                var backBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(backFace));

                if (BlockTypeList.instance.Get(backBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType backShape    = GetShapeTypeData(backBlock.data);
                    Rotation  backRotation = GetRotationData(backBlock.data);

                    if (backShape == ShapeType.HalfCubic && RotationEx.AddRotations(backRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }

                    if (backShape == ShapeType.Tetrahedral && RotationEx.AddRotations(backRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }

                    if (backShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(backRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }
                }
            }

            if (m_data.GetFaceDraw(rightFace))
            {
                var rightBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(rightFace));

                if (BlockTypeList.instance.Get(rightBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType rightShape    = GetShapeTypeData(rightBlock.data);
                    Rotation  rightRotation = GetRotationData(rightBlock.data);

                    if (rightShape == ShapeType.HalfCubic && RotationEx.AddRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.Tetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.AntiTetrahedral && RotationEx.SubRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }
                }
            }
        }

        if (shape == ShapeType.HorizontalHalfCubic)
        {
            if (m_data.GetFaceDraw(BlockFace.Up))
            {
                var upBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Up));

                if (BlockTypeList.instance.Get(upBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType upShape    = GetShapeTypeData(upBlock.data);
                    Rotation  upRotation = GetRotationData(upBlock.data);

                    if (upShape == ShapeType.HorizontalHalfCubic && upRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Up);
                    }

                    if (upShape == ShapeType.Tetrahedral && upRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Up);
                    }
                }
            }

            if (m_data.GetFaceDraw(BlockFace.Down))
            {
                var downBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Down));

                if (BlockTypeList.instance.Get(downBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType downShape    = GetShapeTypeData(downBlock.data);
                    Rotation  downRotation = GetRotationData(downBlock.data);

                    if (downShape == ShapeType.HorizontalHalfCubic && downRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Down);
                    }

                    if (downShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(downRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Down);
                    }
                }
            }
        }
    }
예제 #25
0
 public abstract BlockData UpdateBlock(MatrixView <BlockData> neighbors);