|Getting started with 3D XNA|
|Written by David Conrad|
|Friday, 30 July 2010|
Page 3 of 7
The first three vertexes, 0,1 and 2, correspond to the light green triangle:
The second three vertexes, 3, 4 and 5, correspond the the dark green triangle:
With this we can now move on and create the front face. Notice that all we have created so far is an array of vectors which give the location of the points that make up a flat face consisting of two triangles. We now have to use this basic geometry to create vertexes.
To do this we use the constructor which accepts the position of the vertex as a Vector3 as the first parameter, the normal to the surface as a Vector3 as the second parameter and a Vector2 given the texture co-ordinates of the point as the third parameter.
By default the XNA co-ordinate system is such that positive x is to the right, positive y is up and positive z is out of the screen towards the viewer.
The front face is constructed by moving the points forward in the z direction i.e. out of the screen -i.e. we simply add (0,0,1) or Vector3.UnitZ to the location of each point. The normal for the front face is simply a vector pointing out of the screen so it is Vector3.UnitZ for each vertex:
//front faceThe back face is constructed in the same way but now the translation is in the -Vector3.UnitZ direction and the normal is also -Vector3.UnitZ:
These definitions might look complicated but all that is happening is that the front face is created by moving the face one unit forward in the z direction and the back face one unit back in the z direction.
The front face has its vertexes listed in an anticlockwise order but the back face needs them in reverse order because it presents its clockwise back face to us in its present position.
|Last Updated ( Friday, 30 July 2010 )|