- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
create barcode c#.net s GENERATING A TERRAIN in Font
CHAPTER 10 s GENERATING A TERRAIN ECC200 Creator In None Using Barcode printer for Font Control to generate, create Data Matrix ECC200 image in Font applications. www.OnBarcode.comEncoding GS1 - 12 In None Using Barcode creator for Font Control to generate, create UPC-A Supplement 5 image in Font applications. www.OnBarcode.comprivate int[] GenerateTerrainIndices() { int numIndices = numTriangles * 3; int[] indices = new int[numIndices]; int indicesCount = 0; for (int i = 0; i < (vertexCountZ - 1); i++) { for (int j = 0; j < (vertexCountX - 1); j++) { int index = j + i * vertexCountZ; // First triangle indices[indicesCount++] indices[indicesCount++] indices[indicesCount++] // Second triangle indices[indicesCount++] indices[indicesCount++] indices[indicesCount++] } } return indices; } Code 39 Printer In None Using Barcode generator for Font Control to generate, create Code 39 image in Font applications. www.OnBarcode.comPDF417 Drawer In None Using Barcode printer for Font Control to generate, create PDF417 image in Font applications. www.OnBarcode.com= index; = index + 1; = index + vertexCountX + 1; = index + vertexCountX + 1; = index + vertexCountX; = index; EAN 128 Generation In None Using Barcode encoder for Font Control to generate, create GTIN - 128 image in Font applications. www.OnBarcode.comUSS Code 128 Creation In None Using Barcode generator for Font Control to generate, create Code128 image in Font applications. www.OnBarcode.comGenerating Vertices Position and Texture Coordinate
QR-Code Printer In None Using Barcode printer for Font Control to generate, create Denso QR Bar Code image in Font applications. www.OnBarcode.comBritish Royal Mail 4-State Customer Barcode Drawer In None Using Barcode drawer for Font Control to generate, create RM4SCC image in Font applications. www.OnBarcode.comIn this section you ll create the GenerateTerrainVertices method to generate the mesh s vertices. You ll place the terrain vertices over the world s XZ plane, centering the terrain at the world position (0, 0). To do that, you first need to calculate half the terrain size along the X and Z axes, and then set the terrain s start position at minus its half size along the X and Z axes (-halfTerrainWidth, -halfTerrainDepth). You can calculate the terrain size through the terrain attributes: vertexCountX, which stores the number of vertices of the terrain along the X axis; vertexCountZ, which stores the number of vertices of the terrain along the Z axis; and blockScale, which stores the distance between the vertices in the X and Z axes. After calculating the terrain size, you just need to divide it by two, as shown next: DataMatrix Generator In Objective-C Using Barcode printer for iPhone Control to generate, create Data Matrix image in iPhone applications. www.OnBarcode.comPrinting Data Matrix ECC200 In None Using Barcode creation for Microsoft Word Control to generate, create ECC200 image in Word applications. www.OnBarcode.comfloat float float float terrainWidth = (vertexCountX - 1) terrainDepth = (vertexCountZ - 1) halfTerrainWidth = terrainWidth * halfTerrainDepth = terrainDepth * * blockScale; * blockScale; 0.5f; 0.5f; Creating USS-128 In Java Using Barcode encoder for Android Control to generate, create UCC - 12 image in Android applications. www.OnBarcode.comRecognize Barcode In Java Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications. www.OnBarcode.comCHAPTER 10 s GENERATING A TERRAIN
GTIN - 128 Generator In Java Using Barcode encoder for Eclipse BIRT Control to generate, create GTIN - 128 image in BIRT reports applications. www.OnBarcode.comEAN / UCC - 13 Creation In None Using Barcode generation for Microsoft Excel Control to generate, create GS1 128 image in Office Excel applications. www.OnBarcode.comYou can generate the terrain s vertex grid beginning at the terrain s start position and going over each row of the vertex grid, placing the vertices (going from X to +X), where each row is placed in a different grid column (going from Z to +Z). In this way, the grid s vertices have its position incremented along the X and Z axes according to the block scale that you defined, as shown in Figure 10-2. While placing the vertices, you ll use the previously stored height map data to set the vertex height along the Y axis. You ll also scale the height of the terrain by multiplying the height of each vertex by a scale factor: the heightScale attribute of the Terrain class. You can use the following code to correctly position the vertices over the terrain s vertex grid: Encoding Code 128B In Visual Studio .NET Using Barcode creation for ASP.NET Control to generate, create Code 128 image in ASP.NET applications. www.OnBarcode.comGS1 - 13 Drawer In Java Using Barcode creation for BIRT Control to generate, create EAN / UCC - 13 image in Eclipse BIRT applications. www.OnBarcode.comfor (float i = -halfTerrainDepth; i <= halfTerrainDepth; i += blockScale) for (float j = -halfTerrainWidth; j <= halfTerrainWidth; j += blockScale) Position = (j, heightmap[vertexCount] * heightScale, i) Barcode Drawer In Visual Studio .NET Using Barcode creator for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comMaking Code-39 In Objective-C Using Barcode maker for iPhone Control to generate, create Code39 image in iPhone applications. www.OnBarcode.comEach vertex also has a U and V texture coordinate that should vary between (0, 0) and (1, 1), where (0, 0) is the initial texture coordinate and (1, 1) the final texture coordinate. Figure 10-5 shows the texture coordinates of some vertices in a grid. Code 39 Extended Recognizer In Visual C# Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comECC200 Maker In C#.NET Using Barcode drawer for VS .NET Control to generate, create Data Matrix ECC200 image in VS .NET applications. www.OnBarcode.comFigure 10-5. (Left) The texture coordinates for a grid of vertices. (Right) The UV axes over a texture map. To calculate the correct texture coordinate for each vertex in the terrain, you first need to calculate the increment of the texture coordinate in the UV axis. You do so by dividing the maximum texture coordinate value (1.0) by the number of vertices minus 1, in each axis: float tu = 0; float tv = 0; float tuDerivative = 1.0f / (vertexCountX - 1); float tvDerivative = 1.0f / (vertexCountZ - 1); CHAPTER 10 s GENERATING A TERRAIN
Then, you go through each vertex, setting its texture coordinate and incrementing it. Besides the position and texture coordinate, you still need to calculate the normal, tangent, and binormal for each vertex. To do that, create the GenerateTerrainNormals and GenerateTerrainTangentBinormal methods, which you call at the end of the GenerateTerrainVertices method. Next is the complete code for the GenerateTerrainVertices method: private VertexPositionNormalTangentBinormal[] GenerateTerrainVertices( int[] terrainIndices) { float halfTerrainWidth = (vertexCountX - 1) * blockScale * 0.5f; float halfTerrainDepth = (vertexCountZ - 1) * blockScale * 0.5f; // Texture coordinates float tu = 0; float tv = 0; float tuDerivative = 1.0f / (vertexCountX - 1); float tvDerivative = 1.0f / (vertexCountZ - 1); int vertexCount = 0; // Create the vertex array VertexPositionNormalTangentBinormal[] vertices = new VertexPositionNormalTangentBinormal[vertexCountX * vertexCountZ]; // Set position and texture coordinate of each vertex for (float i = -halfTerrainDepth; i <= halfTerrainDepth; i += blockScale) { tu = 0.0f; for (float j = -halfTerrainWidth; j <= halfTerrainWidth; j += blockScale) { // Set vertex position and UV vertices[vertexCount].Position = new Vector3(j, heightmap[vertexCount] * heightScale, i); vertices[vertexCount].TextureCoordinate = new Vector2(tu, tv); tu += tuDerivative; vertexCount++; } tv += tvDerivative; }
|
|