Game Development Reference
In-Depth Information
// Create a 3d Cube
CreateCube(m_Context);
// Create a Second Cube
CreateCube2(m_Context);
}
In the onDrawFrame() function, the physics properties of the second cube are updated through the
UpdateObject3d() function. The two spheres are checked for a valid collision type, and if true, then
appropriate linear forces are applied to each object. (See Listing 5-22.)
Listing 5-22. onDrawFrame() Modifications
@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);
m_Camera.UpdateCamera();
////////////////////////// Update Object Physics
// Cube1
m_Cube.UpdateObject3d();
boolean HitGround = m_Cube.GetObjectPhysics().GetHitGroundStatus();
if (HitGround)
{
m_Cube.GetObjectPhysics().ApplyTranslationalForce(m_Force1);
m_Cube.GetObjectPhysics().ApplyRotationalForce(m_RotationalForce, 10.0f);
m_Cube.GetObjectPhysics().ClearHitGroundStatus();
}
// Cube2
m_Cube2.UpdateObject3d();
// Process Collisions
Physics.CollisionStatus TypeCollision = m_Cube.GetObjectPhysics().
CheckForCollisionSphereBounding(m_Cube, m_Cube2);
if ((TypeCollision == Physics.CollisionStatus.COLLISION) ||
(TypeCollision == Physics.CollisionStatus.PENETRATING_COLLISION))
{
m_Cube.GetObjectPhysics().ApplyLinearImpulse(m_Cube, m_Cube2);
}
//////////////////////////// Draw Objects
m_Cube.DrawObject(m_Camera, m_PointLight);
m_Cube2.DrawObject(m_Camera, m_PointLight);
}
Figure 5-24 shows the final result, with two cubes continuously colliding with each other along the
vertical y axis.
 
Search WWH ::




Custom Search