Game Development Reference
In-Depth Information
The ApplyRotationalForce() function is used to apply the actual force to the arena objects.
(See Listing 11-14.)
Listing 11-14. Modifying the Arena Objects Set Creation Function
void CreateArenaObjectsSet(Context iContext)
{
m_ArenaObjectsSet = new ArenaObjectSet(iContext);
// Cube
float RotationalForce = 5000;
float MaxVelocity = 0.1f;
ArenaObject3d Obj = CreateArenaObjectCube1(iContext);
Obj.SetArenaObjectID("cube1");
Obj.GetObjectStats().SetDamageValue(10);
Obj.GetObjectPhysics().GetMaxVelocity().Set(MaxVelocity, 1, MaxVelocity);
Obj.GetObjectPhysics().ApplyRotationalForce(RotationalForce, 1);
// Add new Object
boolean result = m_ArenaObjectsSet.AddNewArenaObject(Obj);
///////////////////////////////////////////////
Obj = CreateArenaObjectCube2(iContext);
Obj.SetArenaObjectID("cube2");
Obj.GetObjectStats().SetDamageValue(10);
Obj.GetObjectPhysics().GetMaxVelocity().Set(MaxVelocity, 1, MaxVelocity);
Obj.GetObjectPhysics().ApplyRotationalForce(RotationalForce, 1);
// Add new Object
result = m_ArenaObjectsSet.AddNewArenaObject(Obj);
}
Calculating the Reaction Force for a Collision from Native Code
In order to calculate the reaction force for a collision, modifications must be made to the
hello-jni.c file and the Physics class.
Modifying the hello-jni.c File
The hello-jni.c file has to be modified by adding two functions.
The DotProduct() function calculates the dot product between two vectors (x1,y1,z1) and (x2,y2,z2)
and returns it. (See Listing 11-15.)
Listing 11-15. Calculating the Dot Product of Two Vectors
float DotProduct(float x1, float y1, float z1,
float x2, float y2, float z2)
{
return ((x1 * x2) + (y1 * y2) + (z1 * z2));
}
 
Search WWH ::




Custom Search