The purpose of this example is to demonstrate the EPhysics Collision Filter usage - The code adds four balls in 2 rows and 2 columns, two on each collision group, the collision only happens when the balls are in the same group (row),to make it easier, balls in the same group has the same color and size.
For this example we'll have an EPhysics_World and four basic EPhysics_Bodys, we'll apply an impulse on then and see what happens when they're in other collision group.
The basic concepts like - initializing 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 the balls
We'll use two arrays (color and size) to distinguish the groups.
_world_populate(Test_Data *test_data)
{
static const char *colors[] = {"blue-ball", "big-red-ball"};
static const int sizes[] = {54, 70};
int i, column, row;
struct _EPhysics_Body EPhysics_Body
Body handle, represents an object on EPhysics world.
Definition: EPhysics.h:655
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
The balls declaration was placed into a For loop, just to simplify the coding and divide them in two groups.
for (i = 0; i < 4; i++)
{
column = i % 2;
row = i / 2;
sphere, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj",
colors[row]);
(70 - sizes[row]) / 2,
100 + row * 60 + row / 2 * 20);
EAPI void ephysics_body_evas_object_set(EPhysics_Body *body, Evas_Object *evas_obj, Eina_Bool use_obj_pos)
Set an evas object to a physics body.
EAPI void ephysics_body_restitution_set(EPhysics_Body *body, double restitution)
Set body's coefficient of restitution.
EAPI void ephysics_body_friction_set(EPhysics_Body *body, double friction)
Set body's friction.
EAPI EPhysics_Body * ephysics_body_sphere_add(EPhysics_World *world)
Create a new sphere physics body.
EINA_API Eina_List * eina_list_append(Eina_List *list, const void *data)
Appends the given data to the given linked list.
Definition: eina_list.c:584
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
Evas_Object * elm_image_add(Evas_Object *parent)
Add a new image to the parent.
Definition: efl_ui_image.c:2735
Eina_Bool elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
Set the file that will be used as the image's source.
Definition: efl_ui_image.c:2435
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition: evas_object_main.c:1171
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
Note in this part we divide the balls in two groups by color (row).
EAPI Eina_Bool ephysics_body_collision_group_add(EPhysics_Body *body, const char *group)
Add a body to a given collision group.
The impulse will be applied in only 1 ball per group, in this case:
The 1st row 2nd column ball will be applied an impulse to the left (-300kg * p/s).
The 2nd row 1st column ball will be applied an impulse to the right (300kg * p/s).
And then saving the body into a list.
if (column + row == 1)
}
EAPI void ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y, double z)
Apply an impulse on the center of a body.
}
Here we finish the example. The full source code can be found at test_collision_filter.c.