protected override void CreateGridInternal(Device device, float width, float depth, int xVerts, int zVerts) { var grid = GeometryGenerator.CreateGrid(width, depth, xVerts, zVerts); InitFromMeshData(device, grid); _meshCount = 1; }
public TerrainRenderable(float width, float depth, uint xsubs, uint zsubs) { Width = width; Depth = depth; XSubdivisions = xsubs; ZSubdivisions = zsubs; GeometryGenerator.CreateGrid(width, depth, xsubs, zsubs, out Vertices, out Indices); }
public TerrainRenderable() { Width = 100.0f; Depth = 100.0f; XSubdivisions = 5; ZSubdivisions = 5; GeometryGenerator.CreateGrid(Width, Depth, XSubdivisions, ZSubdivisions, out Vertices, out Indices); }
private void BuildShapeGeometryBuffers() { var box = GeometryGenerator.CreateBox(1, 1, 1); var grid = GeometryGenerator.CreateGrid(20, 30, 60, 40); var sphere = GeometryGenerator.CreateSphere(0.5f, 20, 20); var cylinder = GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20); _boxVertexOffset = 0; _gridVertexOffset = box.Vertices.Count; _sphereVertexOffset = _gridVertexOffset + grid.Vertices.Count; _cylinderVertexOffset = _sphereVertexOffset + sphere.Vertices.Count; _boxIndexCount = box.Indices.Count; _gridIndexCount = grid.Indices.Count; _sphereIndexCount = sphere.Indices.Count; _cylinderIndexCount = cylinder.Indices.Count; _boxIndexOffset = 0; _gridIndexOffset = _boxIndexCount; _sphereIndexOffset = _gridIndexOffset + _gridIndexCount; _cylinderIndexOffset = _sphereIndexOffset + _sphereIndexCount; var totalVertexCount = box.Vertices.Count + grid.Vertices.Count + sphere.Vertices.Count + cylinder.Vertices.Count; var totalIndexCount = _boxIndexCount + _gridIndexCount + _sphereIndexCount + _cylinderIndexCount; var vertices = box.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)).ToList(); vertices.AddRange(grid.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC))); vertices.AddRange(sphere.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC))); vertices.AddRange(cylinder.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC))); var vbd = new BufferDescription(Basic32.Stride * totalVertexCount, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _shapesVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd); var indices = new List <int>(); indices.AddRange(box.Indices); indices.AddRange(grid.Indices); indices.AddRange(sphere.Indices); indices.AddRange(cylinder.Indices); var ibd = new BufferDescription(sizeof(int) * totalIndexCount, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _shapesIB = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd); }
private void BuildLandGeometryBuffers() { var grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50); var vertices = new List <VertexPC>(); foreach (var vertex in grid.Vertices) { var pos = vertex.Position; pos.Y = GetHeight(pos.X, pos.Z); Color4 color; if (pos.Y < -10.0f) { color = new Color4(1.0f, 1.0f, 0.96f, 0.62f); } else if (pos.Y < 5.0f) { color = new Color4(1.0f, 0.48f, 0.77f, 0.46f); } else if (pos.Y < 12.0f) { color = new Color4(1.0f, 0.1f, 0.48f, 0.19f); } else if (pos.Y < 20.0f) { color = new Color4(1.0f, 0.45f, 0.39f, 0.34f); } else { color = new Color4(1, 1, 1, 1); } vertices.Add(new VertexPC(pos, color)); } var vbd = new BufferDescription(VertexPC.Stride * vertices.Count, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _landVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd); var ibd = new BufferDescription(sizeof(int) * grid.Indices.Count, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _landIB = new Buffer(Device, new DataStream(grid.Indices.ToArray(), false, false), ibd); _gridIndexCount = grid.Indices.Count; }
private void BuildLandGeometryBuffers() { var grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50); _landIndexCount = grid.Indices.Count; var vertices = new List <Basic32>(); foreach (var v in grid.Vertices) { var p = new Vector3(v.Position.X, GetHillHeight(v.Position.X, v.Position.Z), v.Position.Z); var n = GetHillNormal(p.X, p.Z); vertices.Add(new Basic32(p, n, v.TexC)); } var vbd = new BufferDescription(Basic32.Stride * vertices.Count, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _landVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd); var ibd = new BufferDescription(sizeof(int) * grid.Indices.Count, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _landIB = new Buffer(Device, new DataStream(grid.Indices.ToArray(), false, false), ibd); }
private void BuildLandGeometryBuffers() { GeometryGenerator.MeshData grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50); var vertices = new List <VertexPN>(); foreach (var vertex in grid.Vertices) { var pos = vertex.Position; pos.Y = GetHillHeight(pos.X, pos.Z); var normal = GetHillNormal(pos.X, pos.Z); vertices.Add(new VertexPN(pos, normal, vertex.TexC)); } var vbd = new D3D11.BufferDescription(VertexPN.Stride * vertices.Count, D3D11.ResourceUsage.Immutable, D3D11.BindFlags.VertexBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0); _groundVB = new D3D11.Buffer(Device, DataStream.Create <VertexPN>(vertices.ToArray(), false, false), vbd); var ibd = new D3D11.BufferDescription(sizeof(int) * grid.Indices.Count, D3D11.ResourceUsage.Immutable, D3D11.BindFlags.IndexBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0); _groundIB = new D3D11.Buffer(Device, DataStream.Create <Int32>(grid.Indices.ToArray(), false, false), ibd); _groundIndexCount = grid.Indices.Count; }
private void BuildGeometryBuffers() { var box = GeometryGenerator.CreateBox(1.0f, 1.0f, 1.0f); var grid = GeometryGenerator.CreateGrid(20.0f, 30.0f, 60, 40); var sphere = GeometryGenerator.CreateSphere(0.5f, 20, 20); var cylinder = GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20); _boxVertexOffset = 0; _gridVertexOffset = box.Vertices.Count; _sphereVertexOffset = _gridVertexOffset + grid.Vertices.Count; _cylinderVertexOffset = _sphereVertexOffset + sphere.Vertices.Count; _boxIndexCount = box.Indices.Count; _gridIndexCount = grid.Indices.Count; _sphereIndexCount = sphere.Indices.Count; _cylinderIndexCount = cylinder.Indices.Count; _boxIndexOffset = 0; _gridIndexOffset = _boxIndexCount; _sphereIndexOffset = _gridIndexOffset + _gridIndexCount; _cylinderIndexOffset = _sphereIndexOffset + _sphereIndexCount; var totalVertexCount = box.Vertices.Count + grid.Vertices.Count + sphere.Vertices.Count + cylinder.Vertices.Count; var totalIndexCount = _boxIndexCount + _gridIndexCount + _sphereIndexCount + _cylinderIndexCount; var vs = new List <VertexPC>(); foreach (var vertex in box.Vertices) { vs.Add(new VertexPC(vertex.Position, Color.Red)); } foreach (var v in grid.Vertices) { vs.Add(new VertexPC(v.Position, Color.Green)); } foreach (var v in sphere.Vertices) { vs.Add(new VertexPC(v.Position, Color.Blue)); } foreach (var v in cylinder.Vertices) { vs.Add(new VertexPC(v.Position, Color.Yellow)); } var vbd = new BufferDescription(VertexPC.Stride * totalVertexCount, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _vb = new Buffer(Device, new DataStream(vs.ToArray(), false, false), vbd); var indices = new List <int>(); indices.AddRange(box.Indices); indices.AddRange(grid.Indices); indices.AddRange(sphere.Indices); indices.AddRange(cylinder.Indices); var ibd = new BufferDescription(sizeof(int) * totalIndexCount, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _ib = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd); }
public override void CreateGrid(Device device, float width, float depth, int xVerts, int zVerts) { var grid = GeometryGenerator.CreateGrid(width, depth, xVerts, zVerts); InitFromMeshData(device, grid); }