private void BuildShapeGeometry()
        {
            //
            // We are concatenating all the geometry into one big vertex/index buffer. So
            // define the regions in the buffer each submesh covers.
            //

            var vertices = new List <Vertex>();
            var indices  = new List <short>();

            SubmeshGeometry box      = AppendMeshData(GeometryGenerator.CreateBox(1.0f, 1.0f, 1.0f, 3), vertices, indices);
            SubmeshGeometry grid     = AppendMeshData(GeometryGenerator.CreateGrid(20.0f, 30.0f, 60, 40), vertices, indices);
            SubmeshGeometry sphere   = AppendMeshData(GeometryGenerator.CreateSphere(0.5f, 20, 20), vertices, indices);
            SubmeshGeometry cylinder = AppendMeshData(GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20), vertices, indices);
            SubmeshGeometry quad     = AppendMeshData(GeometryGenerator.CreateQuad(0.0f, 0.0f, 1.0f, 1.0f, 0.0f), vertices, indices);

            var geo = MeshGeometry.New(Device, CommandList, vertices.ToArray(), indices.ToArray(), "shapeGeo");

            geo.DrawArgs["box"]      = box;
            geo.DrawArgs["grid"]     = grid;
            geo.DrawArgs["sphere"]   = sphere;
            geo.DrawArgs["cylinder"] = cylinder;
            geo.DrawArgs["quad"]     = quad;

            _geometries[geo.Name] = geo;
        }
        private void BuildLandGeometry()
        {
            GeometryGenerator.MeshData grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50);

            //
            // Extract the vertex elements we are interested and apply the height function to
            // each vertex. In addition, color the vertices based on their height so we have
            // sandy looking beaches, grassy low hills, and snow mountain peaks.
            //

            var vertices = new Vertex[grid.Vertices.Count];

            for (int i = 0; i < grid.Vertices.Count; i++)
            {
                Vector3 p = grid.Vertices[i].Position;
                vertices[i].Pos    = p;
                vertices[i].Pos.Y  = GetHillsHeight(p.X, p.Z);
                vertices[i].Normal = GetHillsNormal(p.X, p.Z);
            }

            List <short> indices = grid.GetIndices16();

            var geo = MeshGeometry.New(Device, CommandList, vertices, indices.ToArray(), "landGeo");

            var submesh = new SubmeshGeometry
            {
                IndexCount         = indices.Count,
                StartIndexLocation = 0,
                BaseVertexLocation = 0
            };

            geo.DrawArgs["grid"] = submesh;

            _geometries["landGeo"] = geo;
        }
        private void BuildShapeGeometry()
        {
            //
            // We are concatenating all the geometry into one big vertex/index buffer. So
            // define the regions in the buffer each submesh covers.
            //

            var vertices = new List <Vertex>();
            var indices  = new List <short>();

            SubmeshGeometry box      = AppendMeshData(GeometryGenerator.CreateBox(1.5f, 0.5f, 1.5f, 3), Color.DarkGreen, vertices, indices);
            SubmeshGeometry grid     = AppendMeshData(GeometryGenerator.CreateGrid(50.0f, 15.0f, 2, 40), Color.ForestGreen, vertices, indices);
            SubmeshGeometry sphere   = AppendMeshData(GeometryGenerator.CreateSphere(0.5f, 20, 20), Color.Crimson, vertices, indices);
            SubmeshGeometry cylinder = AppendMeshData(GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20), Color.SteelBlue, vertices, indices);
            SubmeshGeometry pyramid  = AppendMeshData(GeometryGenerator.Pyramid(1.5f, 0.5f, 1.5f, 3), Color.Purple, vertices, indices);
            SubmeshGeometry wedge    = AppendMeshData(GeometryGenerator.Wedge(1.5f, 0.5f, 1.5f, 3), Color.RosyBrown, vertices, indices);
            SubmeshGeometry diamond  = AppendMeshData(GeometryGenerator.Diamond(1.5f, 0.5f, 1.5f, 3), Color.MintCream, vertices, indices);
            SubmeshGeometry triPrism = AppendMeshData(GeometryGenerator.TriangularPrism(1.5f, 0.5f, 1.5f, 3), Color.DarkOrchid, vertices, indices);
            SubmeshGeometry hexPrism = AppendMeshData(GeometryGenerator.HexagonalPrism(1.5f, 0.5f, 1.5f, 3), Color.RoyalBlue, vertices, indices);
            SubmeshGeometry cone     = AppendMeshData(GeometryGenerator.CreateCone(0.5f, 0.3f, 3.0f, 20, 20), Color.SteelBlue, vertices, indices);
            var             geo      = MeshGeometry.New(Device, CommandList, vertices, indices.ToArray(), "shapeGeo");

            geo.DrawArgs["box"]      = box;
            geo.DrawArgs["grid"]     = grid;
            geo.DrawArgs["sphere"]   = sphere;
            geo.DrawArgs["cylinder"] = cylinder;
            geo.DrawArgs["pyramid"]  = pyramid;
            geo.DrawArgs["wedge"]    = wedge;
            geo.DrawArgs["diamond"]  = diamond;
            geo.DrawArgs["triPrism"] = triPrism;
            geo.DrawArgs["hexPrism"] = hexPrism;
            geo.DrawArgs["cone"]     = cone;
            _geometries[geo.Name]    = geo;
        }
        private void BuildWavesGeometry()
        {
            GeometryGenerator.MeshData grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, _waves.RowCount, _waves.ColumnCount);

            var vertices = new Vertex[grid.Vertices.Count];

            for (int i = 0; i < grid.Vertices.Count; i++)
            {
                vertices[i].Pos    = grid.Vertices[i].Position;
                vertices[i].Normal = grid.Vertices[i].Normal;
                vertices[i].TexC   = grid.Vertices[i].TexC;
            }

            var indices = new int[3 * _waves.TriangleCount]; // 3 indices per face.

            Debug.Assert(_waves.VertexCount < int.MaxValue);

            // Iterate over each quad.
            int m = _waves.RowCount;
            int n = _waves.ColumnCount;
            int k = 0;

            for (int i = 0; i < m - 1; ++i)
            {
                for (int j = 0; j < n - 1; ++j)
                {
                    indices[k + 0] = i * n + j;
                    indices[k + 1] = i * n + j + 1;
                    indices[k + 2] = (i + 1) * n + j;

                    indices[k + 3] = (i + 1) * n + j;
                    indices[k + 4] = i * n + j + 1;
                    indices[k + 5] = (i + 1) * n + j + 1;

                    k += 6; // Next quad.
                }
            }

            var geo = MeshGeometry.New(Device, CommandList, vertices, indices, "waterGeo");

            geo.VertexByteStride     = Utilities.SizeOf <Vertex>();
            geo.VertexBufferByteSize = geo.VertexByteStride * _waves.VertexCount;

            var submesh = new SubmeshGeometry
            {
                IndexCount         = indices.Length,
                StartIndexLocation = 0,
                BaseVertexLocation = 0
            };

            geo.DrawArgs["grid"] = submesh;

            _geometries["waterGeo"] = geo;
        }
Exemple #5
0
        private void BuildLandGeometry()
        {
            GeometryGenerator.MeshData grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50);

            //
            // Extract the vertex elements we are interested and apply the height function to
            // each vertex. In addition, color the vertices based on their height so we have
            // sandy looking beaches, grassy low hills, and snow mountain peaks.
            //

            var vertices = new Vertex[grid.Vertices.Count];

            for (int i = 0; i < grid.Vertices.Count; i++)
            {
                Vector3 p = grid.Vertices[i].Position;
                vertices[i].Pos   = p;
                vertices[i].Pos.Y = GetHillsHeight(p.X, p.Z);

                // Color the vertex based on its height.
                if (vertices[i].Pos.Y < -10.0f)
                {
                    // Sandy beach color.
                    vertices[i].Color = new Vector4(1.0f, 0.96f, 0.62f, 1.0f);
                }
                else if (vertices[i].Pos.Y < 5.0f)
                {
                    // Light yellow-green.
                    vertices[i].Color = new Vector4(0.48f, 0.77f, 0.46f, 1.0f);
                }
                else if (vertices[i].Pos.Y < 12.0f)
                {
                    // Dark yellow-green.
                    vertices[i].Color = new Vector4(0.1f, 0.48f, 0.19f, 1.0f);
                }
                else if (vertices[i].Pos.Y < 20.0f)
                {
                    // Dark brown.
                    vertices[i].Color = new Vector4(0.45f, 0.39f, 0.34f, 1.0f);
                }
                else
                {
                    // White snow.
                    vertices[i].Color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                }
            }

            List <short> indices = grid.GetIndices16();

            var geo = MeshGeometry.New(Device, CommandList, vertices, indices.ToArray(), "landGeo");

            var submesh = new SubmeshGeometry
            {
                IndexCount         = indices.Count,
                StartIndexLocation = 0,
                BaseVertexLocation = 0
            };

            geo.DrawArgs["grid"] = submesh;

            _geometries["landGeo"] = geo;
        }