ephysics: support multiple evas objects associated to

body




SVN revision: 79041
This commit is contained in:
Bruno Dilly 2012-11-09 18:52:42 +00:00
parent 7af37b3980
commit 61d7e5e30e
3 changed files with 900 additions and 0 deletions

View File

@ -1841,6 +1841,66 @@ typedef enum _EPhysics_Body_Cloth_Anchor_Side
EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_LAST,
} EPhysics_Body_Cloth_Anchor_Side;
/**
* @enum _EPhysics_Body_Box_Face
* @typedef EPhysics_Body_Box_Face
*
* Define in wich box's face the evas object should be set.
*
* @see ephysics_body_box_face_evas_object_set()
*
* @ingroup EPhysics_Body
*/
typedef enum _EPhysics_Body_Box_Face
{
EPHYSICS_BODY_BOX_FACE_MIDDLE_FRONT,
EPHYSICS_BODY_BOX_FACE_MIDDLE_BACK,
EPHYSICS_BODY_BOX_FACE_FRONT,
EPHYSICS_BODY_BOX_FACE_BACK,
EPHYSICS_BODY_BOX_FACE_LEFT,
EPHYSICS_BODY_BOX_FACE_RIGHT,
EPHYSICS_BODY_BOX_FACE_TOP,
EPHYSICS_BODY_BOX_FACE_BOTTOM,
EPHYSICS_BODY_BOX_FACE_LAST,
} EPhysics_Body_Box_Face;
/**
* @enum _EPhysics_Body_Cylinder_Face
* @typedef EPhysics_Body_Cylinder_Face
*
* Define in wich cylinder's face the evas object should be set.
*
* @see ephysics_body_cylinder_face_evas_object_set()
*
* @ingroup EPhysics_Body
*/
typedef enum _EPhysics_Body_Cylinder_Face
{
EPHYSICS_BODY_CYLINDER_FACE_MIDDLE_FRONT,
EPHYSICS_BODY_CYLINDER_FACE_MIDDLE_BACK,
EPHYSICS_BODY_CYLINDER_FACE_FRONT,
EPHYSICS_BODY_CYLINDER_FACE_BACK,
EPHYSICS_BODY_CYLINDER_FACE_CURVED,
EPHYSICS_BODY_CYLINDER_FACE_LAST,
} EPhysics_Body_Cylinder_Face;
/**
* @enum _EPhysics_Body_Cloth_Face
* @typedef EPhysics_Body_Cloth_Face
*
* Define in wich cloth's face the evas object should be set.
*
* @see ephysics_body_cloth_face_evas_object_set()
*
* @ingroup EPhysics_Body
*/
typedef enum _EPhysics_Body_Cloth_Face
{
EPHYSICS_BODY_CLOTH_FACE_FRONT,
EPHYSICS_BODY_CLOTH_FACE_BACK,
EPHYSICS_BODY_CLOTH_FACE_LAST,
} EPhysics_Body_Cloth_Face;
/**
* @typedef EPhysics_Body_Collision
*
@ -2084,6 +2144,8 @@ EAPI void ephysics_body_soft_body_triangle_move(EPhysics_Body *body, int idx, Ev
* @return a new body or @c NULL, on errors.
*
* @see ephysics_body_del().
* @see ephysics_body_evas_object_set().
* @see ephysics_body_cylinder_face_evas_object_set().
*
* @ingroup EPhysics_Body
*/
@ -2113,6 +2175,8 @@ EAPI EPhysics_Body *ephysics_body_circle_add(EPhysics_World *world);
* @return a new body or @c NULL, on errors.
*
* @see ephysics_body_del().
* @see ephysics_body_evas_object_set().
* @see ephysics_body_cylinder_face_evas_object_set().
* @see ephysics_world_simulation_set().
*
* @ingroup EPhysics_Body
@ -2134,6 +2198,7 @@ EAPI EPhysics_Body *ephysics_body_soft_circle_add(EPhysics_World *world);
*
* @see ephysics_body_del().
* @see ephysics_body_evas_object_set().
* @see ephysics_body_box_face_evas_object_set().
*
* @ingroup EPhysics_Body
*/
@ -2159,6 +2224,7 @@ EAPI EPhysics_Body *ephysics_body_box_add(EPhysics_World *world);
*
* @see ephysics_body_del().
* @see ephysics_body_evas_object_set().
* @see ephysics_body_box_face_evas_object_set().
* @see ephysics_world_simulation_set().
*
* @ingroup EPhysics_Body
@ -2188,6 +2254,7 @@ EAPI EPhysics_Body *ephysics_body_soft_box_add(EPhysics_World *world);
*
* @see ephysics_body_del().
* @see ephysics_body_evas_object_set().
* @see ephysics_body_cloth_face_evas_object_set().
* @see ephysics_world_simulation_set().
* @see ephysics_body_cloth_anchor_add().
* @see ephysics_body_cloth_anchor_full_add().
@ -2429,6 +2496,12 @@ EAPI EPhysics_World *ephysics_body_world_get(const EPhysics_Body *body);
* updates of associated evas objects, or complement updates, like changing
* evas objects properties under certain conditions of position or rotation.
*
* If it's required to associate evas object to specific faces of the body,
* the following functions could be used, depending on the body's shape:
* @li @ref ephysics_body_box_face_evas_object_set();
* @li @ref ephysics_body_cylinder_face_evas_object_set();
* @li @ref ephysics_body_cloth_face_evas_object_set().
*
* @param body The body to associate to an evas object.
* @param evas_obj The evas object that will be associated to this @p body.
* @param use_obj_pos If @c EINA_TRUE it will set the physics body position
@ -2473,6 +2546,185 @@ EAPI Evas_Object *ephysics_body_evas_object_unset(EPhysics_Body *body);
*/
EAPI Evas_Object *ephysics_body_evas_object_get(const EPhysics_Body *body);
/**
* @brief
* Set an evas object to a physics box body face.
*
* It will create a direct association between a specific face of the physics
* body and an evas object.
* With that EPhysics will be able to update evas object
* position and rotation automatically.
*
* If it's required to associate only one evas object to this body, a more
* generic function @see ephysics_body_evas_object_set() can be used.
*
* @param body The body to associate to an evas object.
* @param face The specific face of @p body where the evas object will be
* placed.
* @param evas_obj The evas object that will be associated to this @p body.
* @param use_obj_pos If @c EINA_TRUE it will set the physics body position
* to match evas object position taking world rate on consideration.
*
* @see ephysics_body_box_face_evas_object_unset().
* @see ephysics_body_box_face_evas_object_get().
* @see ephysics_body_box_add().
* @see ephysics_body_soft_box_add().
* @see ephysics_body_evas_object_set().
* @see ephysics_world_rate_set().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_box_face_evas_object_set(EPhysics_Body *body, EPhysics_Body_Box_Face face, Evas_Object *evas_obj, Eina_Bool use_obj_pos);
/**
* @brief
* Get the evas object associated to a physics box body face.
*
* @param body The body to get an evas object from.
* @param face The specific face of @p body where the evas object was placed.
* @return The associated evas object, or @c NULL if no object is associated
* or on error.
*
* @see ephysics_body_box_face_evas_object_set() for more details.
*
* @ingroup EPhysics_Body
*/
EAPI Evas_Object *ephysics_body_box_face_evas_object_get(const EPhysics_Body *body, EPhysics_Body_Box_Face face);
/**
* @brief
* Unset the evas object associated to a physics box body face.
*
* @param body The body to unset an evas object from.
* @param face The specific face of @p body where the evas object was placed.
* @return The associated evas object, or @c NULL if no object is associated
* or on error.
*
* @see ephysics_body_box_face_evas_object_set() for more details.
*
* @ingroup EPhysics_Body
*/
EAPI Evas_Object *ephysics_body_box_face_evas_object_unset(EPhysics_Body *body, EPhysics_Body_Box_Face face);
/**
* @brief
* Set an evas object to a physics cylinder body face.
*
* It will create a direct association between a specific face of the physics
* body and an evas object.
* With that EPhysics will be able to update evas object
* position and rotation automatically.
*
* If it's required to associate only one evas object to this body, a more
* generic function @see ephysics_body_evas_object_set() can be used.
*
* @param body The body to associate to an evas object.
* @param face The specific face of @p body where the evas object will be
* placed.
* @param evas_obj The evas object that will be associated to this @p body.
* @param use_obj_pos If @c EINA_TRUE it will set the physics body position
* to match evas object position taking world rate on consideration.
*
* @see ephysics_body_cylinder_face_evas_object_unset().
* @see ephysics_body_cylinder_face_evas_object_get().
* @see ephysics_body_circle_add().
* @see ephysics_body_soft_circle_add().
* @see ephysics_body_evas_object_set().
* @see ephysics_world_rate_set().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_cylinder_face_evas_object_set(EPhysics_Body *body, EPhysics_Body_Cylinder_Face face, Evas_Object *evas_obj, Eina_Bool use_obj_pos);
/**
* @brief
* Get the evas object associated to a physics cylinder body face.
*
* @param body The body to get an evas object from.
* @param face The specific face of @p body where the evas object was placed.
* @return The associated evas object, or @c NULL if no object is associated
* or on error.
*
* @see ephysics_body_cylinder_face_evas_object_set() for more details.
*
* @ingroup EPhysics_Body
*/
EAPI Evas_Object *ephysics_body_cylinder_face_evas_object_get(const EPhysics_Body *body, EPhysics_Body_Cylinder_Face face);
/**
* @brief
* Unset the evas object associated to a physics cylinder body face.
*
* @param body The body to unset an evas object from.
* @param face The specific face of @p body where the evas object was placed.
* @return The associated evas object, or @c NULL if no object is associated
* or on error.
*
* @see ephysics_body_cylinder_face_evas_object_set() for more details.
*
* @ingroup EPhysics_Body
*/
EAPI Evas_Object *ephysics_body_cylinder_face_evas_object_unset(EPhysics_Body *body, EPhysics_Body_Cylinder_Face face);
/**
* @brief
* Set an evas object to a physics cloth body face.
*
* It will create a direct association between a specific face of the physics
* body and an evas object.
* With that EPhysics will be able to update evas object
* position and rotation automatically.
*
* If it's required to associate only one evas object to this body, a more
* generic function @see ephysics_body_evas_object_set() can be used.
*
* @param body The body to associate to an evas object.
* @param face The specific face of @p body where the evas object will be
* placed.
* @param evas_obj The evas object that will be associated to this @p body.
* @param use_obj_pos If @c EINA_TRUE it will set the physics body position
* to match evas object position taking world rate on consideration.
*
* @see ephysics_body_cloth_face_evas_object_unset().
* @see ephysics_body_cloth_face_evas_object_get().
* @see ephysics_body_cloth_add().
* @see ephysics_body_evas_object_set().
* @see ephysics_world_rate_set().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_cloth_face_evas_object_set(EPhysics_Body *body, EPhysics_Body_Cloth_Face face, Evas_Object *evas_obj, Eina_Bool use_obj_pos);
/**
* @brief
* Get the evas object associated to a physics cloth body face.
*
* @param body The body to get an evas object from.
* @param face The specific face of @p body where the evas object was placed.
* @return The associated evas object, or @c NULL if no object is associated
* or on error.
*
* @see ephysics_body_cloth_face_evas_object_set() for more details.
*
* @ingroup EPhysics_Body
*/
EAPI Evas_Object *ephysics_body_cloth_face_evas_object_get(const EPhysics_Body *body, EPhysics_Body_Cloth_Face face);
/**
* @brief
* Unset the evas object associated to a physics cloth body face.
*
* @param body The body to unset an evas object from.
* @param face The specific face of @p body where the evas object was placed.
* @return The associated evas object, or @c NULL if no object is associated
* or on error.
*
* @see ephysics_body_cloth_face_evas_object_set() for more details.
*
* @ingroup EPhysics_Body
*/
EAPI Evas_Object *ephysics_body_cloth_face_evas_object_unset(EPhysics_Body *body, EPhysics_Body_Cloth_Face face);
/**
* @brief
* Set physics body size.

View File

@ -17,9 +17,13 @@
extern "C" {
#endif
#define SHAPE_BOX "Box"
#define SHAPE_CYLINDER "CylinderZ"
typedef struct _EPhysics_Body_Callback EPhysics_Body_Callback;
typedef struct _EPhysics_Body_Evas_Stacking EPhysics_Body_Evas_Stacking;
typedef struct _EPhysics_Body_Soft_Body_Slice EPhysics_Body_Soft_Body_Slice;
typedef struct _EPhysics_Body_Face_Obj EPhysics_Body_Face_Obj;
struct _EPhysics_Body_Callback {
EINA_INLIST;
@ -52,6 +56,11 @@ struct _EPhysics_Body_Soft_Body_Slice
float stacking;
};
struct _EPhysics_Body_Face_Obj {
int face;
Evas_Object *obj;
};
static void
_ephysics_body_soft_body_slices_apply(EPhysics_Body *body)
{
@ -1056,6 +1065,23 @@ _ephysics_body_del(EPhysics_Body *body)
free(body);
}
static void
_ephysics_cloth_face_objs_update(EPhysics_Body *body __UNUSED__)
{
}
static void
_ephysics_cylinder_face_objs_update(EPhysics_Body *body __UNUSED__)
{
}
static void
_ephysics_box_face_objs_update(EPhysics_Body *body)
{
}
static void
_ephysics_body_evas_object_default_update(EPhysics_Body *body)
{
@ -1066,6 +1092,19 @@ _ephysics_body_evas_object_default_update(EPhysics_Body *body)
Evas_Map *map;
double rate;
if (body->face_objs)
{
if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
_ephysics_cloth_face_objs_update(body);
else if (body->type == EPHYSICS_BODY_TYPE_RIGID)
{
if (!(strcmp(body->collision_shape->getName(), SHAPE_CYLINDER)))
_ephysics_cylinder_face_objs_update(body);
else if (!(strcmp(body->collision_shape->getName(), SHAPE_BOX)))
_ephysics_box_face_objs_update(body);
}
}
if (!body->evas_obj)
return;
@ -3375,6 +3414,614 @@ ephysics_body_clockwise_get(const EPhysics_Body *body)
return body->clockwise;
}
static void
_ephysics_body_face_obj_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
EPhysics_Body *body = (EPhysics_Body *) data;
EPhysics_Body_Face_Obj *face_obj;
Eina_List *l;
void *ldata;
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->obj == obj)
{
body->face_objs = eina_list_remove(body->face_objs, face_obj);
free(face_obj);
return;
}
}
}
static void
_ephysics_body_face_obj_unset(Evas_Object *obj, Evas_Object_Event_Cb resize_func)
{
evas_object_map_enable_set(obj, EINA_FALSE);
evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL,
_ephysics_body_face_obj_del_cb);
evas_object_event_callback_del(obj, EVAS_CALLBACK_RESIZE, resize_func);
}
static void
_ephysics_body_face_evas_object_add(EPhysics_Body *body, int face, Evas_Object *evas_obj, Evas_Object_Event_Cb resize_func)
{
EPhysics_Body_Face_Obj *face_obj;
Eina_List *l;
void *ldata;
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->face == face)
{
_ephysics_body_face_obj_unset(face_obj->obj, resize_func);
face_obj->obj = evas_obj;
return;
}
}
face_obj = (EPhysics_Body_Face_Obj *)calloc(1,
sizeof(EPhysics_Body_Face_Obj));
if (!face_obj)
{
ERR("Failed to create face object");
return;
}
face_obj->face = face;
face_obj->obj = evas_obj;
body->face_objs = eina_list_append(body->face_objs, face_obj);
}
static void
_ephysics_body_box_face_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
EPhysics_Body_Box_Face face = EPHYSICS_BODY_BOX_FACE_LAST;
EPhysics_Body *body = (EPhysics_Body *) data;
EPhysics_Body_Face_Obj *face_obj;
int w, h, bw, bh, bd;
Eina_List *l;
void *ldata;
evas_object_geometry_get(obj, NULL, NULL, &w, &h);
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->obj == obj)
{
face = (EPhysics_Body_Box_Face) face_obj->face;
break;
}
}
switch(face)
{
case EPHYSICS_BODY_BOX_FACE_FRONT:
case EPHYSICS_BODY_BOX_FACE_BACK:
case EPHYSICS_BODY_BOX_FACE_MIDDLE_FRONT:
case EPHYSICS_BODY_BOX_FACE_MIDDLE_BACK:
if ((w == body->size.w) && (h == body->size.h))
return;
bw = w;
bh = h;
bd = body->size.d;
break;
case EPHYSICS_BODY_BOX_FACE_RIGHT:
case EPHYSICS_BODY_BOX_FACE_LEFT:
if ((w == body->size.d) && (h == body->size.h))
return;
bw = body->size.w;
bh = h;
bd = w;
case EPHYSICS_BODY_BOX_FACE_TOP:
case EPHYSICS_BODY_BOX_FACE_BOTTOM:
if ((w == body->size.w) && (h == body->size.d))
return;
bw = w;
bh = body->size.h;
bd = h;
default:
return;
}
DBG("Resizing body %p to w=%i, h=%i, d=%i", body, bw, bh, bd);
ephysics_world_lock_take(body->world);
_ephysics_body_resize(body, bw, bh, bd);
ephysics_world_lock_release(body->world);
}
EAPI void
ephysics_body_box_face_evas_object_set(EPhysics_Body *body, EPhysics_Body_Box_Face face, Evas_Object *evas_obj, Eina_Bool use_obj_pos)
{
int obj_x, obj_y, obj_w, obj_h, bx, by, bz, bw, bh, bd;
double rate;
if (!body)
{
ERR("Can't set evas object to body, the last wasn't provided.");
return;
}
if (!evas_obj)
{
ERR("Can't set evas object to body, the first wasn't provided.");
return;
}
if ((strcmp(body->collision_shape->getName(), SHAPE_BOX)))
{
ERR("Can't set evas object to body, it's not a box.");
return;
}
if ((face < 0) || (face >= EPHYSICS_BODY_BOX_FACE_LAST))
{
ERR("Can't set evas object to body, face is invalid.");
return;
}
if (body->soft_body)
{
ERR("Not implemented for soft bodies yet.");
return;
}
_ephysics_body_face_evas_object_add(body, face, evas_obj,
_ephysics_body_box_face_obj_resize_cb);
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_DEL,
_ephysics_body_face_obj_del_cb, body);
if (!use_obj_pos)
return;
rate = ephysics_world_rate_get(body->world);
evas_object_geometry_get(evas_obj, &obj_x, &obj_y, &obj_w, &obj_h);
ephysics_body_geometry_get(body, &bx, &by, &bz, &bw, &bh, &bd);
ephysics_world_lock_take(body->world);
switch(face)
{
case EPHYSICS_BODY_BOX_FACE_FRONT:
case EPHYSICS_BODY_BOX_FACE_BACK:
case EPHYSICS_BODY_BOX_FACE_MIDDLE_FRONT:
case EPHYSICS_BODY_BOX_FACE_MIDDLE_BACK:
_ephysics_body_geometry_set(body, obj_x, obj_y, bz,
obj_w, obj_h, bd, rate);
break;
case EPHYSICS_BODY_BOX_FACE_RIGHT:
case EPHYSICS_BODY_BOX_FACE_LEFT:
_ephysics_body_geometry_set(body, bx, by, bz,
bw, obj_h, obj_w, rate);
case EPHYSICS_BODY_BOX_FACE_TOP:
case EPHYSICS_BODY_BOX_FACE_BOTTOM:
_ephysics_body_geometry_set(body, bx, by, bz,
obj_w, bh, obj_h, rate);
default:
break;
}
ephysics_world_lock_release(body->world);
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_RESIZE,
_ephysics_body_box_face_obj_resize_cb,
body);
}
EAPI Evas_Object *
ephysics_body_box_face_evas_object_get(const EPhysics_Body *body, EPhysics_Body_Box_Face face)
{
EPhysics_Body_Face_Obj *face_obj;
Eina_List *l;
void *ldata;
if (!body)
{
ERR("Can't get evas object from body, it wasn't provided.");
return NULL;
}
if (strcmp(body->collision_shape->getName(), SHAPE_BOX))
{
ERR("Can't get evas object from body, it's not a box.");
return NULL;
}
if ((face < 0) || (face >= EPHYSICS_BODY_BOX_FACE_LAST))
{
ERR("Can't get evas object from body, face is invalid.");
return NULL;
}
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->face == face)
return face_obj->obj;
}
ERR("Couldn't find an object associated to face %i.", face);
return NULL;
}
EAPI Evas_Object *
ephysics_body_box_face_evas_object_unset(EPhysics_Body *body, EPhysics_Body_Box_Face face)
{
EPhysics_Body_Face_Obj *face_obj;
Eina_List *l;
void *ldata;
if (!body)
{
ERR("Can't unset evas object from body, it wasn't provided.");
return NULL;
}
if (strcmp(body->collision_shape->getName(), SHAPE_BOX))
{
ERR("Can't unset evas object from body, it's not a box.");
return NULL;
}
if ((face < 0) || (face >= EPHYSICS_BODY_BOX_FACE_LAST))
{
ERR("Can't unset evas object from body, face is invalid.");
return NULL;
}
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->face == face)
{
Evas_Object *obj = face_obj->obj;
_ephysics_body_face_obj_unset(
obj, _ephysics_body_box_face_obj_resize_cb);
body->face_objs = eina_list_remove(body->face_objs, face_obj);
free(face_obj);
return obj;
}
}
ERR("Couldn't find an object associated to face %i.", face);
return NULL;
}
static void
_ephysics_body_cylinder_face_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
EPhysics_Body_Cylinder_Face face = EPHYSICS_BODY_CYLINDER_FACE_LAST;
EPhysics_Body *body = (EPhysics_Body *) data;
EPhysics_Body_Face_Obj *face_obj;
int w, h, bw, bh, bd;
Eina_List *l;
void *ldata;
evas_object_geometry_get(obj, NULL, NULL, &w, &h);
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->obj == obj)
{
face = (EPhysics_Body_Cylinder_Face) face_obj->face;
break;
}
}
switch(face)
{
case EPHYSICS_BODY_CYLINDER_FACE_FRONT:
case EPHYSICS_BODY_CYLINDER_FACE_BACK:
case EPHYSICS_BODY_CYLINDER_FACE_MIDDLE_FRONT:
case EPHYSICS_BODY_CYLINDER_FACE_MIDDLE_BACK:
if ((w == body->size.w) && (h == body->size.h))
return;
bw = w;
bh = h;
bd = body->size.d;
break;
case EPHYSICS_BODY_CYLINDER_FACE_CURVED:
if ((h == body->size.d))
return;
bw = body->size.w;
bh = body->size.h;
bd = h;
default:
return;
}
DBG("Resizing body %p to w=%i, h=%i, d=%i", body, bw, bh, bd);
ephysics_world_lock_take(body->world);
_ephysics_body_resize(body, bw, bh, bd);
ephysics_world_lock_release(body->world);
}
EAPI void
ephysics_body_cylinder_face_evas_object_set(EPhysics_Body *body, EPhysics_Body_Cylinder_Face face, Evas_Object *evas_obj, Eina_Bool use_obj_pos)
{
int obj_x, obj_y, obj_w, obj_h, bx, by, bz, bw, bh, bd;
double rate;
if (!body)
{
ERR("Can't set evas object to body, the last wasn't provided.");
return;
}
if (!evas_obj)
{
ERR("Can't set evas object to body, the first wasn't provided.");
return;
}
if (strcmp(body->collision_shape->getName(), SHAPE_CYLINDER))
{
ERR("Can't set evas object to body, it's not a cylinder.");
return;
}
if ((face < 0) || (face >= EPHYSICS_BODY_CYLINDER_FACE_LAST))
{
ERR("Can't set evas object to body, face is invalid.");
return;
}
if (body->soft_body)
{
ERR("Not implemented for soft bodies yet.");
return;
}
_ephysics_body_face_evas_object_add(
body, face, evas_obj, _ephysics_body_cylinder_face_obj_resize_cb);
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_DEL,
_ephysics_body_face_obj_del_cb, body);
if (!use_obj_pos)
return;
rate = ephysics_world_rate_get(body->world);
evas_object_geometry_get(evas_obj, &obj_x, &obj_y, &obj_w, &obj_h);
ephysics_body_geometry_get(body, &bx, &by, &bz, &bw, &bh, &bd);
ephysics_world_lock_take(body->world);
switch(face)
{
case EPHYSICS_BODY_CYLINDER_FACE_FRONT:
case EPHYSICS_BODY_CYLINDER_FACE_BACK:
case EPHYSICS_BODY_CYLINDER_FACE_MIDDLE_FRONT:
case EPHYSICS_BODY_CYLINDER_FACE_MIDDLE_BACK:
_ephysics_body_geometry_set(body, obj_x, obj_y, bz,
obj_w, obj_h, bd, rate);
break;
case EPHYSICS_BODY_CYLINDER_FACE_CURVED:
_ephysics_body_geometry_set(body, bx, by, bz,
bw, bh, obj_h, rate);
default:
break;
}
ephysics_world_lock_release(body->world);
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_RESIZE,
_ephysics_body_cylinder_face_obj_resize_cb,
body);
}
EAPI Evas_Object *
ephysics_body_cylinder_face_evas_object_get(const EPhysics_Body *body, EPhysics_Body_Cylinder_Face face)
{
EPhysics_Body_Face_Obj *face_obj;
Eina_List *l;
void *ldata;
if (!body)
{
ERR("Can't get evas object from body, it wasn't provided.");
return NULL;
}
if (strcmp(body->collision_shape->getName(), SHAPE_CYLINDER))
{
ERR("Can't get evas object from body, it's not a cylinder.");
return NULL;
}
if ((face < 0) || (face >= EPHYSICS_BODY_CYLINDER_FACE_LAST))
{
ERR("Can't get evas object from body, face is invalid.");
return NULL;
}
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->face == face)
return face_obj->obj;
}
ERR("Couldn't find an object associated to face %i.", face);
return NULL;
}
EAPI Evas_Object *
ephysics_body_cylinder_face_evas_object_unset(EPhysics_Body *body, EPhysics_Body_Cylinder_Face face)
{
EPhysics_Body_Face_Obj *face_obj;
Eina_List *l;
void *ldata;
if (!body)
{
ERR("Can't unset evas object from body, it wasn't provided.");
return NULL;
}
if (strcmp(body->collision_shape->getName(), SHAPE_CYLINDER))
{
ERR("Can't unset evas object from body, it's not a cylinder.");
return NULL;
}
if ((face < 0) || (face >= EPHYSICS_BODY_CYLINDER_FACE_LAST))
{
ERR("Can't unset evas object from body, face is invalid.");
return NULL;
}
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->face == face)
{
Evas_Object *obj = face_obj->obj;
_ephysics_body_face_obj_unset(
obj, _ephysics_body_cylinder_face_obj_resize_cb);
body->face_objs = eina_list_remove(body->face_objs, face_obj);
free(face_obj);
return obj;
}
}
ERR("Couldn't find an object associated to face %i.", face);
return NULL;
}
EAPI void
ephysics_body_cloth_face_evas_object_set(EPhysics_Body *body, EPhysics_Body_Cloth_Face face, Evas_Object *evas_obj, Eina_Bool use_obj_pos)
{
int obj_x, obj_y, obj_w, obj_h, bz, bd;
double rate;
if (!body)
{
ERR("Can't set evas object to body, the last wasn't provided.");
return;
}
if (!evas_obj)
{
ERR("Can't set evas object to body, the first wasn't provided.");
return;
}
if (body->type != EPHYSICS_BODY_TYPE_CLOTH)
{
ERR("Can't set evas object to body, it's not a cloth.");
return;
}
if ((face < 0) || (face >= EPHYSICS_BODY_CLOTH_FACE_LAST))
{
ERR("Can't set evas object to body, face is invalid.");
return;
}
if (body->soft_body)
{
ERR("Not implemented for soft bodies yet.");
return;
}
_ephysics_body_face_evas_object_add(body, face, evas_obj,
_ephysics_body_evas_obj_resize_cb);
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_DEL,
_ephysics_body_face_obj_del_cb, body);
if (!use_obj_pos)
return;
rate = ephysics_world_rate_get(body->world);
evas_object_geometry_get(evas_obj, &obj_x, &obj_y, &obj_w, &obj_h);
ephysics_world_lock_take(body->world);
ephysics_body_geometry_get(body, NULL, NULL, &bz, NULL, NULL, &bd);
_ephysics_body_geometry_set(body, obj_x, obj_y, bz, obj_w, obj_h, bd, rate);
ephysics_world_lock_release(body->world);
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_RESIZE,
_ephysics_body_evas_obj_resize_cb,
body);
}
EAPI Evas_Object *
ephysics_body_cloth_face_evas_object_get(const EPhysics_Body *body, EPhysics_Body_Cloth_Face face)
{
EPhysics_Body_Face_Obj *face_obj;
Eina_List *l;
void *ldata;
if (!body)
{
ERR("Can't get evas object from body, it wasn't provided.");
return NULL;
}
if (body->type != EPHYSICS_BODY_TYPE_CLOTH)
{
ERR("Can't get evas object from body, it's not a cloth.");
return NULL;
}
if ((face < 0) || (face >= EPHYSICS_BODY_CLOTH_FACE_LAST))
{
ERR("Can't get evas object from body, face is invalid.");
return NULL;
}
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->face == face)
return face_obj->obj;
}
ERR("Couldn't find an object associated to face %i.", face);
return NULL;
}
EAPI Evas_Object *
ephysics_body_cloth_face_evas_object_unset(EPhysics_Body *body, EPhysics_Body_Cloth_Face face)
{
EPhysics_Body_Face_Obj *face_obj;
Eina_List *l;
void *ldata;
if (!body)
{
ERR("Can't unset evas object from body, it wasn't provided.");
return NULL;
}
if (body->type != EPHYSICS_BODY_TYPE_CLOTH)
{
ERR("Can't unset evas object from body, it's not a cloth.");
return NULL;
}
if ((face < 0) || (face >= EPHYSICS_BODY_CLOTH_FACE_LAST))
{
ERR("Can't unset evas object from body, face is invalid.");
return NULL;
}
EINA_LIST_FOREACH(body->face_objs, l, ldata)
{
face_obj = (EPhysics_Body_Face_Obj *)ldata;
if (face_obj->face == face)
{
Evas_Object *obj = face_obj->obj;
_ephysics_body_face_obj_unset(
obj, _ephysics_body_evas_obj_resize_cb);
body->face_objs = eina_list_remove(body->face_objs, face_obj);
free(face_obj);
return obj;
}
}
ERR("Couldn't find an object associated to face %i.", face);
return NULL;
}
#ifdef __cplusplus
}
#endif

View File

@ -122,6 +122,7 @@ struct _EPhysics_Body {
Eina_List *collision_groups;
Eina_List *to_delete;
Eina_List *slices_list;
Eina_List *face_objs;
EPhysics_Body_Material material;
double mass;
double density;