Game Development Reference
In-Depth Information
Listing 5-38. Adding to the CreateCube2() Function
Vector3 GridColor = new Vector3(0,1,0);
m_Cube2.SetGridSpotLightColor(GridColor);
m_Cube2.GetObjectPhysics().SetMassEffectiveRadius(6);
We add a function UpdateGravityGrid() , which updates our gravity grid by resetting the grid to clear
out all the masses. Then we add the masses we want to appear on the grid. Let's add our first cube
with the red spotlight. (See Listing 5-39.)
Listing 5-39. Updating the Gravity Grid
void UpdateGravityGrid()
{
// Clear Masses from Grid from Previous Update
m_Grid.ResetGrid();
// Add Cubes to Grid
m_Grid.AddMass(m_Cube);
}
In the onSurfaceCreated() function, we add a call to the CreateGrid() function to create our new
gravity grid when our GL surface has been created. (See Listing 5-40.)
Listing 5-40. Modifying the onSurfaceCreated() Function
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config)
{
m_PointLight = new PointLight(m_Context);
SetupLights();
// Create a 3d Cube
CreateCube(m_Context);
// Create a Second Cube
CreateCube2(m_Context);
// Create a new gravity grid
CreateGrid(m_Context);
}
The onDrawFrame() function has to be modified to update and draw the gravity grid. The changes are
in bold print. (See Listing 5-41.)
Listing 5-41. Modifying the onDrawFrame() Function
@Override
public void onDrawFrame(GL10 unused)
{
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
 
Search WWH ::




Custom Search