create barcode c#.net Generating the Terrain s Mesh in Font

Generating Data Matrix in Font Generating the Terrain s Mesh

Generating the Terrain s Mesh
DataMatrix Maker In None
Using Barcode generation for Font Control to generate, create Data Matrix ECC200 image in Font applications.
www.OnBarcode.com
USS-128 Generator In None
Using Barcode printer for Font Control to generate, create GS1-128 image in Font applications.
www.OnBarcode.com
To generate the terrain s mesh, you need to generate its vertices and indices. The mesh s indices store the order in which the mesh s vertices should be combined to generate
ANSI/AIM Code 128 Creator In None
Using Barcode creation for Font Control to generate, create Code 128B image in Font applications.
www.OnBarcode.com
Draw PDF417 In None
Using Barcode generation for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
CHAPTER 10 s GENERATING A TERRAIN
Make Code 39 In None
Using Barcode printer for Font Control to generate, create Code 39 Extended image in Font applications.
www.OnBarcode.com
Make Barcode In None
Using Barcode drawer for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
triangles. Meanwhile, each mesh s vertex contains a spatial coordinate and stores some attributes needed for rendering, such as normal and texture coordinate. You should generate the mesh s indices prior to its vertices because you can only calculate some of the vertex attributes, such as the vertex normal, if you know which vertices are used in each triangle. You ll create two separate methods to generate the mesh s indices and vertices, respectively named GenerateTerrainIndices and GenerateTerrainVertices. You ll call these methods from the GenerateTerrain method to generate the mesh s vertices and indices. Then, you ll create an XNA VertexBuffer to store the mesh s vertices and an XNA IndexBuffer to store the mesh s indices. Vertex and index buffers are memory buffers that store its data in system memory and copy it to the video memory as needed. Use the following code for the GenerateTerrain method, which calls the GenerateTerrainIndices and GenerateTerrainVertices methods to generate the indices and vertices of the terrain s mesh. Following is the code for the GenerateTerrainMesh method:
Create Barcode In None
Using Barcode maker for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Making Uniform Symbology Specification Codabar In None
Using Barcode creator for Font Control to generate, create Rationalized Codabar image in Font applications.
www.OnBarcode.com
private void GenerateTerrainMesh() { numVertices = vertexCountX * vertexCountZ; numTriangles = (vertexCountX - 1) * (vertexCountZ - 1) * 2; // You must generate the terrain indices first int[] indices = GenerateTerrainIndices(); // Then, generate terrain vertices VertexPositionNormalTangentBinormal[] vertices = GenerateTerrainVertices(indices); // Create a vertex buffers to hold all the vertices vb = new VertexBuffer(GraphicsDevice, numVertices * VertexPositionNormalTangentBinormal.SizeInBytes, BufferUsage.WriteOnly); vb.SetData<VertexPositionNormalTangentBinormal>(vertices); // Create an index buffers to hold all the indices ib = new IndexBuffer(GraphicsDevice, numTriangles * 3 * sizeof(int), BufferUsage.WriteOnly, IndexElementSize.ThirtyTwoBits); ib.SetData<int>(indices); }
Data Matrix 2d Barcode Drawer In None
Using Barcode creation for Software Control to generate, create ECC200 image in Software applications.
www.OnBarcode.com
Generating Data Matrix 2d Barcode In Java
Using Barcode maker for Android Control to generate, create Data Matrix 2d barcode image in Android applications.
www.OnBarcode.com
Notice that the terrain vertices are stored as an array of the
Read Code 3 Of 9 In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Scan ECC200 In VS .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
VertexPositionNormalTangentBinormal struct. You must create this helper struct to store
Code 39 Generator In .NET Framework
Using Barcode drawer for Reporting Service Control to generate, create Code-39 image in Reporting Service applications.
www.OnBarcode.com
Scan Code 3 Of 9 In Visual C#
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
the vertex data because you ll need to store the position, texture coordinate, normal, tangent, and binormal of each vertex, and XNA doesn t have a class that stores all these
USS Code 128 Generation In None
Using Barcode drawer for Office Word Control to generate, create Code 128 Code Set B image in Office Word applications.
www.OnBarcode.com
Code 128C Generator In None
Using Barcode printer for Software Control to generate, create Code128 image in Software applications.
www.OnBarcode.com
CHAPTER 10 s GENERATING A TERRAIN
UPC-A Scanner In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Recognize Data Matrix 2d Barcode In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
vertex attributes. Following is the code for the VertexPositionNormalTangentBinormal struct:
Denso QR Bar Code Encoder In None
Using Barcode generator for Excel Control to generate, create Denso QR Bar Code image in Excel applications.
www.OnBarcode.com
Scan EAN 128 In VB.NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
public struct VertexPositionNormalTangentBinormal { public Vector3 Position; public Vector3 Normal; public Vector2 TextureCoordinate; public Vector3 Tanget; public Vector3 Binormal; public static int SizeInBytes { get { return (3 + 3 + 2 + 3 + 3) * sizeof(float); } } public static VertexElement[] VertexElements = new VertexElement[] { new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0), new VertexElement(0, 12, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Normal, 0), new VertexElement(0, 24, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0), new VertexElement(0, 32, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Tangent, 0), new VertexElement(0, 44, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Binormal, 0) }; }
The VertexPositionNormalTangentBinormal struct has all the attributes that you need for a vertex: position, texture coordinate, normal, tangent, and binormal. This structure also declares a VertexElement array containing the format of the vertex data, which has the type and size of each element in the vertex.
CHAPTER 10 s GENERATING A TERRAIN
Generating the Mesh s Indices
In this section you ll create the GenerateTerrainIndices method to generate the indices of the terrain s mesh. The mesh s indices define in which order the vertices should be combined to generate triangles. Figure 10-4 shows the indices of the vertices in a grid and how they are combined to form triangles.
Figure 10-4. Indexing grid vertices to create triangles
Each quad in the terrain has two triangles: a gray triangle and a white triangle. In the first quad of the grid the gray triangle has the vertices 0, 1, and 7, while the white triangle has the vertices 0, 7, and 6. Notice that the order of the triangle s indices is important: it should be clockwise, because the XNA pipeline culls counterclockwise triangles by default. Notice that there is a pattern between the indices used to create the triangles, where the indices of the first and second triangles of every quadrant follow the same order, as shown in the next equation.
In the preceding equation, the VertexCountX variable is equal to the number of vertices per row in the vertex grid. Using the preceding equation, you can loop through all the quadrants of the vertex grid, generating the indices of its triangles. You ll generate the mesh s indices as an array of integers that have three values for each triangle. Following is the code for the GenerateTerrainIndices method:
Copyright © OnBarcode.com . All rights reserved.