コード例 #1
0
        private void CreateGeometry(AssetLoadContext loadContext,
                                    Vector2[] points, uint height)
        {
            Triangulator.Triangulate(
                points,
                WindingOrder.CounterClockwise,
                out var trianglePoints,
                out var triangleIndices);

            var vertices = trianglePoints
                           .Select(x =>
                                   new WaterShaderResources.WaterVertex
            {
                Position = new Vector3(x.X, x.Y, height)
            })
                           .ToArray();

            _boundingBox = AxisAlignedBoundingBox.CreateFromPoints(vertices.Select(x => x.Position));

            _vertexBuffer = AddDisposable(loadContext.GraphicsDevice.CreateStaticBuffer(
                                              vertices,
                                              BufferUsage.VertexBuffer));

            _numIndices = (uint)triangleIndices.Length;

            _indexBuffer = AddDisposable(loadContext.GraphicsDevice.CreateStaticBuffer(
                                             triangleIndices,
                                             BufferUsage.IndexBuffer));

            _world             = Matrix4x4.Identity;
            _world.Translation = new Vector3(0, height, 0);
        }
コード例 #2
0
        public void CreateFromPoints(IEnumerable <Vector3> points, Vector3 expectedMin, Vector3 expectedMax)
        {
            var sut = AxisAlignedBoundingBox.CreateFromPoints(points);

            Assert.Equal(expectedMin, sut.Min);
            Assert.Equal(expectedMax, sut.Max);
        }
コード例 #3
0
ファイル: TerrainPatch.cs プロジェクト: lanyizi/OpenSAGE
        private static DeviceBuffer CreateVertexBuffer(
            GraphicsDevice graphicsDevice,
            HeightMap heightMap,
            Rectangle patchBounds,
            ushort[] indices,
            out AxisAlignedBoundingBox boundingBox,
            out Triangle[] triangles)
        {
            var numVertices = patchBounds.Width * patchBounds.Height;

            var vertices = new TerrainShaderResources.TerrainVertex[numVertices];
            var points   = new Vector3[numVertices];

            var vertexIndex = 0;

            for (var y = patchBounds.Y; y < patchBounds.Y + patchBounds.Height; y++)
            {
                for (var x = patchBounds.X; x < patchBounds.X + patchBounds.Width; x++)
                {
                    var position = heightMap.GetPosition(x, y);
                    points[vertexIndex]     = position;
                    vertices[vertexIndex++] = new TerrainShaderResources.TerrainVertex
                    {
                        Position = position,
                        Normal   = heightMap.Normals[x, y],
                        UV       = new Vector2(x, y)
                    };
                }
            }

            boundingBox = AxisAlignedBoundingBox.CreateFromPoints(points);

            triangles = new Triangle[(patchBounds.Width - 1) * (patchBounds.Height) * 2];

            var triangleIndex = 0;
            var indexIndex    = 0;

            for (var y = 0; y < patchBounds.Height - 1; y++)
            {
                for (var x = 0; x < patchBounds.Width - 1; x++)
                {
                    // Triangle 1
                    triangles[triangleIndex++] = new Triangle(
                        points[indices[indexIndex++]],
                        points[indices[indexIndex++]],
                        points[indices[indexIndex++]]);

                    // Triangle 2
                    triangles[triangleIndex++] = new Triangle(
                        points[indices[indexIndex++]],
                        points[indices[indexIndex++]],
                        points[indices[indexIndex++]]);
                }
            }

            return(graphicsDevice.CreateStaticBuffer(vertices, BufferUsage.VertexBuffer));
        }