EPhysics - Forces

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

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);
EAPI void ephysics_body_force_apply(EPhysics_Body *body, double x, double y, double z, Evas_Coord pos_x, Evas_Coord pos_y, Evas_Coord pos_z)
Apply a force over a body.

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);
EAPI void ephysics_body_central_force_apply(EPhysics_Body *body, double x, double y, double z)
Apply a force on the center of a body.

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);
EAPI void ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double *z)
Get physics body forces.

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