Game Development Reference
In-Depth Information
// Set Color of Line
m_Shader.SetShaderUniformVariableValue("vColor", m_GridColor);
// Set View Proj Matrix
m_Shader.SetShaderVariableValueFloatMatrix4Array("uMVPMatrix", 1, false, m_MVPMatrix, 0);
}
The function GenerateMatrices() builds the modelviewprojection matrix from the view matrix and
the projection matrix. The grid does not need to be moved or rotated anywhere, so we can skip the
step where the model is translated and rotated into the world space. (See Listing 5-31.)
Listing 5-31. Generating the modelviewprojection Matrix
void GenerateMatrices(Camera Cam)
{
Matrix.multiplyMM(m_MVPMatrix, 0, Cam.GetProjectionMatrix(), 0, Cam.GetViewMatrix(), 0);
}
The DrawGrid() function creates the needed matrices, sets up the vertex shader for rendering, and
then draws the actual gravity grid mesh. (See Listing 5-32.)
Listing 5-32. Drawing the Gravity Grid Mesh
void DrawGrid(Camera Cam)
{
// Set up Shader
GenerateMatrices(Cam);
SetUpShader();
// Draw Mesh
m_LineMeshGrid.DrawMesh(m_PositionHandle, -1, -1);
}
Creating the New Vertex Shader
A new vertex shader needs to be created in order to change the way vertices are placed in the 3D
world for the grid mesh object. The basic idea of this new vertex shader is that each vertex or point
on the gravity grid will have all the attractive gravitational forces from all the masses on the grid
calculated, and the sum of these forces will help determine the final position of each grid point. The
spotlight color contribution from all the objects on the grid are also calculated for each grid point and
added to the original color. (See Figure 5-27 .)
 
Search WWH ::




Custom Search