Exemple #1
0
        public void Initialize(Microsoft.Xna.Framework.Game game, Color color, float[] verts, int[] tris)
        {
            _game         = game;
            _vertexBuffer = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionColorNormal), verts.Length / 3, BufferUsage.None);
            _indexBuffer  = new IndexBuffer(game.GraphicsDevice, typeof(int), tris.Length, BufferUsage.None);
            var data = new VertexPositionColorNormal[verts.Length / 3];

            for (int i = 0; i < verts.Length / 3; i++)
            {
                data[i] = new VertexPositionColorNormal(new Vector3(-verts[(i * 3) + 0], verts[(i * 3) + 1], -verts[(i * 3) + 2]), color, new Vector3(0));
            }
            GenerateNormals(data, tris);
            _vertexBuffer.SetData(data);
            _indexBuffer.SetData(tris);
        }
Exemple #2
0
        public void Initialize(Microsoft.Xna.Framework.Game game, Color color, IEnumerable <Vector3> vertices, IEnumerable <Triangle <uint> > triangles)
        {
            _game = game;
            int vertCount = vertices.Count();
            int triCount  = triangles.Count();

            _vertexBuffer = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionColorNormal), vertCount, BufferUsage.None);
            _indexBuffer  = new IndexBuffer(game.GraphicsDevice, typeof(int), triCount * 3, BufferUsage.None);

            var data = new VertexPositionColorNormal[vertCount];
            int c    = 0;

            foreach (var vert in vertices)
            {
                data[c++] = new VertexPositionColorNormal(new Vector3(vert.Y, vert.Z, vert.X), color, new Vector3(0));
            }

            var triData = new int[triCount * 3];

            c = 0;
            foreach (var tri in triangles)
            {
                triData[c]     = (int)tri.V0;
                triData[c + 1] = (int)tri.V1;
                triData[c + 2] = (int)tri.V2;
                c += 3;

                switch (tri.Type)
                {
                case TriangleType.Water:
                    data[tri.V0].Color = Color.Blue;
                    data[tri.V1].Color = Color.Blue;
                    data[tri.V2].Color = Color.Blue;
                    break;
                }
            }

            GenerateNormals(data, triData);
            _vertexBuffer.SetData(data);
            _indexBuffer.SetData(triData);
        }