|Getting started with 3D XNA|
|Written by David Conrad|
|Friday, 30 July 2010|
Page 4 of 7
The left, right and top and bottom faces are created in the same way but after rotating the initial face through 90 degrees about the Y and X axis respectively. Again we need to pay attention to the order of the vertexes to make sure that they are anticlockwise on side of the face the faces out of the cube.
For example for the left face we need to rotate each point 90 degrees around the Y axis and then move the face in the X negative direction:
The rest of the faces are computed in the same way - a rotation and a translation:
There a few subtle points to notice. The first is that XNA provides a lot of useful classes and methods to make working with vectors and matrices easy.
It is very important that you understand how vectors and matrices work if you want to do 3D programming. The surface normals have been defined to point out of the cube and, as we will see later effect the way light reflects off each surface. In more sophisticated examples the surface normals don't always have to be the true geometric normals to the surface. Think of surface normals as defining the angle that light would have to hit the surface and bounce off at the same angle. By manipulating the surface normals you can make flat surfaces look curved.
In case you are wondering for large shapes you wouldn’t “hand code” the vertex array but use a modelling program to create a “mesh” that you would load into you XNA program. This said - every 3D programmer should know how to create a mesh programmatically and the cube is a good illustration of how this can be done and how geometry can be created.
|Last Updated ( Friday, 30 July 2010 )|