# Figure 6-3. Two triangles sharing one edge in Office Word Draw DataMatrix in Office Word Figure 6-3. Two triangles sharing one edge

Figure 6-3. Two triangles sharing one edge
Data Matrix ECC200 Printer In None
Using Barcode printer for Microsoft Word Control to generate, create Data Matrix image in Word applications.
www.OnBarcode.com
Code 128B Printer In None
Using Barcode creator for Word Control to generate, create Code128 image in Office Word applications.
www.OnBarcode.com
How It Works
Create PDF-417 2d Barcode In None
Using Barcode drawer for Office Word Control to generate, create PDF 417 image in Microsoft Word applications.
www.OnBarcode.com
QR Code Drawer In None
Using Barcode drawer for Microsoft Word Control to generate, create QR Code image in Word applications.
www.OnBarcode.com
In this recipe, you ll define the two triangles using two approaches. First, you ll render the two triangles so all vertices of the same triangle have the same normal, which will result in equal shading for all pixels inside one triangle. Next, you ll make sure the normals in the shared vertices are the same so you ll get smooth shading across the border of the triangle.
GS1 128 Maker In None
Using Barcode creator for Office Word Control to generate, create EAN / UCC - 14 image in Office Word applications.
www.OnBarcode.com
UPC - 13 Printer In None
Using Barcode encoder for Word Control to generate, create European Article Number 13 image in Word applications.
www.OnBarcode.com
Each Triangle Its Normal
UPC Code Generation In None
Using Barcode creation for Microsoft Word Control to generate, create GS1 - 12 image in Microsoft Word applications.
www.OnBarcode.com
Royal Mail Barcode Printer In None
Using Barcode encoder for Microsoft Word Control to generate, create British Royal Mail 4-State Customer Barcode image in Word applications.
www.OnBarcode.com
This approach comes down to finding the direction perpendicular to the triangle and storing this direction in each of its vertices, as done in recipe 6-1. The following code defines the six vertices shown on the left side of Figure 6-3. All three vertices of each triangle have the same normal direction, perpendicular to the triangle. The left triangle is positioned vertically, so its normal points to the left. The second triangle is positioned horizontally, so its vertices point up.
Data Matrix Creator In Java
Using Barcode creator for Java Control to generate, create DataMatrix image in Java applications.
www.OnBarcode.com
Data Matrix Scanner In VB.NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
CHAPTER 6 ADDIN G LIGHT TO Y OUR SCE NE IN XNA 2.0
Barcode Encoder In VS .NET
Using Barcode generator for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
Drawing Barcode In None
Using Barcode encoder for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
private void InitVertices() { vertices = new VertexPositionNormalTexture[6]; vertices[0] = new VertexPositionNormalTexture(new Vector3(0, -1, 0), new Vector3(-1, 0, 0), new Vector2(0,1)); vertices[1] = new VertexPositionNormalTexture(new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector2(0.5f, 0)); vertices[2] = new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(-1, 0, 0), new Vector2(0.5f, 1)); vertices[3] = new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector2(0.5f,1)); vertices[4] = new VertexPositionNormalTexture(new Vector3(0, 0, -1), new Vector3(0, 1, 0), new Vector2(0.5f,1)); vertices[5] = new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector2(1,1)); myVertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements); } Next, define a light that is shining mostly to the right but also a bit down. Make sure you normalize the direction so its length becomes exactly 1: Vector3 lightDirection = new Vector3(10, -2, 0); lightDirection.Normalize(); basicEffect.DirectionalLight0.Direction = lightDirection; Next, render both triangles using the code from the previous chapter: basicEffect.Begin(); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); device.VertexDeclaration = myVertexDeclaration; device.DrawUserPrimitives<VertexPositionNormalTexture> (PrimitiveType.TriangleList, vertices, 0, 2); pass.End(); } basicEffect.End(); Read the section Normalize Your Normals in recipe 6-1 to understand why you need to normalize the light direction. You should see two triangles, both of which have a solid color, as shown on the left side of Figure 6-4. Because of this, you can easily see the border between them, which is definitely not what you want with larger objects.
Creating Code 128 Code Set A In None
Using Barcode printer for Font Control to generate, create Code128 image in Font applications.
www.OnBarcode.com
Drawing USS Code 39 In None
Using Barcode maker for Font Control to generate, create Code 3/9 image in Font applications.
www.OnBarcode.com
CH A PT ER 6 A DD I NG LI GHT T O YOUR SC ENE I N XN A 2.0
Barcode Generator In Java
Using Barcode generator for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Encoding ANSI/AIM Code 39 In Java
Using Barcode generation for Eclipse BIRT Control to generate, create ANSI/AIM Code 39 image in BIRT reports applications.
www.OnBarcode.com
UCC - 12 Encoder In Java
Using Barcode generator for Java Control to generate, create GS1 128 image in Java applications.
www.OnBarcode.com
Barcode Generation In Java
Using Barcode encoder for Eclipse BIRT Control to generate, create Barcode image in BIRT applications.
www.OnBarcode.com
Shared Normals
Making Data Matrix ECC200 In Objective-C
Using Barcode creator for iPhone Control to generate, create DataMatrix image in iPhone applications.
www.OnBarcode.com
UPC Symbol Creator In VS .NET
Using Barcode encoder for .NET Control to generate, create UPC Symbol image in .NET framework applications.
www.OnBarcode.com
This time, you re going to give both vertices 1 and 4, as well as vertices 2 and 3, the same normal direction. One question that comes up is which direction you should pick. To obtain the smoothest effect, you ll simply take the average of the usual normals. You can do this with the following code: private void InitVertices() vertices = new VertexPositionNormalTexture[6]; Vector3 normal1 = new Vector3(-1, 0, 0); Vector3 normal2 = new Vector3(0, 1, 0); Vector3 sharedNormal = normal1 + normal2; sharedNormal.Normalize(); vertices[0] = new VertexPositionNormalTexture(new Vector3(0, -1, 0), normal1, new Vector2(0,1)); vertices[1] = new VertexPositionNormalTexture(new Vector3(0, 0, -1), sharedNormal, new Vector2(0.5f, 0)); vertices[2] = new VertexPositionNormalTexture(new Vector3(0, 0, 0), sharedNormal, new Vector2(0.5f, 1)); vertices[3] = new VertexPositionNormalTexture(new Vector3(0, 0, 0), sharedNormal, new Vector2(0.5f,1)); vertices[4] = new VertexPositionNormalTexture(new Vector3(0, 0, -1), sharedNormal, new Vector2(0.5f,1)); vertices[5] = new VertexPositionNormalTexture(new Vector3(1, 0, 0), normal2, new Vector2(1,1)); myVertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements); }
CHAPTER 6 ADDIN G LIGHT TO Y OUR SCE NE IN XNA 2.0
First you sum the two normals of the two triangles. Make sure you normalize the result so the length becomes 1 again (see the section Normalize Your Normals in recipe 6-1). The resulting direction will be pointing exactly in the middle between Left and Up. Next, you define the six vertices. The two outer vertices are not shared, so they get their old normal. The shared vertices, however, all get the same normal. Now, when you render the two triangles, the shading inside the triangles will smoothly change from the outer vertex to the shared edge, as shown in the right part of Figure 6-4. This makes it hard to find the edge between the two triangles, so the user will not see the object consists of separate triangles.