示例#1
0
        public Mesh CreateDiamondGrid(int numColumns, int numRows)
        {
            CustomMesh ret = new CustomMesh();
            List<Vector3> vBuf = new List<Vector3>();
            List<int> iBuf = new List<int>();
            DiamondSquare sq = new DiamondSquare();

            for (int r = -numColumns; r < numColumns; r+=2)
            {
                for (int c = -numColumns; c < numColumns; c+=2)
                {
                    sq.AppendTranslatedSquare(vBuf, iBuf, new Vector3(c, 0, r), DiamondSquare.SquareType.Normal);
                }
            }
            ret.SetVertexData<VertexTypes.Position>(vBuf, iBuf);
            return ret;
        }
        void Recreate(int numColumns,int numRows)
        {
            List<Vector3> vBuf = new List<Vector3>();
            List<int> iBuf = new List<int>();

            List<Vector3> tempBuf = new List<Vector3>();
            List<int> tempiBuf = new List<int>();

            DiamondSquare sq = new DiamondSquare();

            for (int row = 0; row < numRows; row += 2)
            {

                for (int column = 0; column <= numColumns + row; column += 2)
                {
                    DiamondSquare.SquareType st = DiamondSquare.SquareType.Normal;
                    if (row == numRows-2 && column == numColumns + row)
                        st = DiamondSquare.SquareType.TopRight;
                    else if (row == numRows-2)
                        st = DiamondSquare.SquareType.TopRow;
                    else if (column == numColumns + row)
                        st = DiamondSquare.SquareType.Right;
                    sq.AppendTranslatedSquare(tempBuf, tempiBuf, new Vector3(column, 0, row + numColumns), st);
                }
            }

            List<Vector3> rev;
            List<int> revi;
            MathExtensions.ReflectVerticesThroughXAxis(tempBuf, tempiBuf, out rev, out revi);
            MathExtensions.AppendVertices(tempBuf, tempiBuf, rev, revi);

            MathExtensions.AppendVertices(vBuf, iBuf, tempBuf, tempiBuf);

            Matrix m = Matrix.RotationY((float)(Math.PI / 2));
            MathExtensions.TransformVertices(tempBuf, out rev, m);
            MathExtensions.AppendVertices(vBuf, iBuf, rev, tempiBuf);

            m = Matrix.RotationY((float)(Math.PI));
            MathExtensions.TransformVertices(tempBuf, out rev, m);
            MathExtensions.AppendVertices(vBuf, iBuf, rev, tempiBuf);

            m = Matrix.RotationY((float)(3 * Math.PI / 2));
            MathExtensions.TransformVertices(tempBuf, out rev, m);
            MathExtensions.AppendVertices(vBuf, iBuf, rev, tempiBuf);

            this.SetVertexPositionData<VertexTypes.Position>(vBuf.ToArray(), iBuf.ToArray());
        }