EPhysics - Forces

The purpose of this example is to demonstrate the EPhysics Force usage - The code applies force over two cubes.

forces.png

For this example we'll have an EPhysics_World with gravity setted to zero, and two basic EPhysics_Bodys.

The basic concepts like - defining an EPhysics_World, render geometry, physics limiting boundaries, add an EPhysics_Body, associate it to evas objects, change restitution, friction and impulse properties, were already covered in EPhysics - Bouncing Ball

Adding a Force

We apply a force over the first body to change its linear and angular accelerations. Applying a force to a body will lead it to change its velocity gradually.

Note that in this blue cube we use an offset to apply the force, the two last parameters are responsible to set a relative position to apply the force.In other words, the force applied with an offset will make the body rotates. Otherwise (0, 0, 0) the force would be applied on the center of the body, in this case its recommended use the ephysics_body_central_force_apply();

ephysics_body_force_apply(box_body1, 60, 0, 0, 0, 10, 0);

Here we apply a central force over the second body avoiding affect the angular acceleration (rotate).

ephysics_body_central_force_apply(box_body2, 60, 0, 0);

We can also get all the forces applied over a body, including gravity, but in this case we setted to zero.

ephysics_body_forces_get(body, &x, &y, &z);

Here we finish the example. The full source code can be found at test_forces.c.