Example #1
0
        void DrawBoundingBox()
        {
            // TODO: set this stuff up once
            var vertices = new VertexPositionNormalColor[8];
            var indices  = new short[]
            {
                0, 1,
                1, 2,
                2, 3,
                3, 0,
                0, 4,
                1, 5,
                2, 6,
                3, 7,
                4, 5,
                5, 6,
                6, 7,
                7, 4,
            };

            Vector3[] corners = _boundingBox.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = corners[i];
                vertices[i].Color    = Color.DarkGreen;
                vertices[i].Normal   = Vector3.Up;
            }

            foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                _graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertices, 0, 8, indices, 0, indices.Length / 2);
            }
        }
Example #2
0
        VertexPositionNormalColor[] GenerateMeshVertices(HeightmapSample[] heightmapSamples)
        {
            var vertices = new VertexPositionNormalColor[_gridSize * _gridSize];

            for (int row = 0; row < _gridSize; row++)
            {
                for (int column = 0; column < _gridSize; column++)
                {
                    var vertex = GetVertexInMeshSpace(heightmapSamples[row * _gridSize + column], column, row);
                    AdjustBoundingBoxToInclude(vertex.Position);
                    vertices[row * _gridSize + column] = vertex;
                }
            }

            GenerateNormals(vertices);

            return(vertices);
        }
        public void Initialize(VertexPositionNormalColor[] vertices, short[] indices)
        {
            _effect = new BasicEffect(_graphicsDevice);

            CreateVertexBuffer(vertices);
            CreateIndexBuffer(indices);
        }
 private void CreateVertexBuffer(VertexPositionNormalColor[] vertices)
 {
     _numberOfVertices = vertices.Length;
     _vertexBuffer = new VertexBuffer(_graphicsDevice, typeof(VertexPositionNormalColor), _numberOfVertices, BufferUsage.WriteOnly);
     _vertexBuffer.SetData(vertices);
 }
        void DrawBoundingBox()
        {
            // TODO: set this stuff up once
            var vertices = new VertexPositionNormalColor[8];
            var indices = new short[]
            {
                0, 1,
                1, 2,
                2, 3,
                3, 0,
                0, 4,
                1, 5,
                2, 6,
                3, 7,
                4, 5,
                5, 6,
                6, 7,
                7, 4,
            };

            Vector3[] corners = _boundingBox.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = corners[i];
                vertices[i].Color = Color.DarkGreen;
                vertices[i].Normal = Vector3.Up;
            }

            foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                _graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertices, 0, 8, indices, 0, indices.Length / 2);
            }
        }
 public void Initialize(VertexPositionNormalColor[] vertices, short[] indices, BoundingBox boundingBox)
 {
     CreateVertexBuffer(vertices);
     CreateIndexBuffer(indices);
     _boundingBox = boundingBox;
 }