Game Development Reference
In-Depth Information
The link to the vertex position variable in the shader is held in m_PositionHandle .
private int m_PositionHandle;
The color of the grid is held in m_GridColor .
private Vector3 m_GridColor;
The value to send to the modelviewprojection matrix in the shader is located in m_MVPMatrix .
private float[] m_MVPMatrix = new float[16];
The grid location boundaries along the x axis are held in the following variables:
private float m_XMinBoundary;
private float m_XMaxBoundary;
The grid location boundaries along the z axis are held in the following variables:
private float m_ZMinBoundary;
private float m_ZMaxBoundary;
The GravityGridEx constructor creates the grid, based on the input parameters to the constructor.
The following steps are performed in the creation of the gravity grid in the constructor:
The array that holds the vertex data m_Vertices is initialized by allocating
enough memory to hold all the vertex data.
1.
Two nested for loops, the outer loop running the length of the z axis of the
grid and the other inner loop running the length of the x axis of the grid,
create the points of the grid and puts them into the m_Vertices array.
2.
The array m_DrawOrder , which holds the indices into m_Vertices for the actual
method of how to draw the mesh, is initialized by allocating enough memory
to hold each line to be drawn.
3.
The m_DrawOrder array is filled with the indices of the vertices that need to
have lines drawn between them. Because we are drawing lines, each two
entries of m_DrawOrder would represent one line. This is done in two loops,
one for the horizontal lines, and the other for vertical lines of the grid.
4.
The actual grid is created using the m_Vertices and the m_DrawOrder arrays
created in the previous steps and stored in the m_LineMeshGrid variable.
5.
6.
The mesh type to draw is set to lines.
7. The call to the ClearMasses() function sets the mass value of all the objects
on the grid to 0.
See Listing 5-24 for details of the code that executes the preceding steps.
 
Search WWH ::




Custom Search