ephysics: improve body struct readability a bit

Actually ephysics body deserves a redesign, since it differs
a lot between types. It wasn't previewed.



SVN revision: 79038
This commit is contained in:
Bruno Dilly 2012-11-09 18:52:22 +00:00
parent 5d465e1c04
commit 560c3e6fa8
2 changed files with 56 additions and 42 deletions

View File

@ -895,9 +895,9 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
_ephysics_body_mass_set(body, ephysics_body_mass_get(body)); _ephysics_body_mass_set(body, ephysics_body_mass_get(body));
} }
body->w = w; body->size.w = w;
body->h = h; body->size.h = h;
body->d = d; body->size.d = d;
ephysics_body_activate(body, EINA_TRUE); ephysics_body_activate(body, EINA_TRUE);
@ -917,9 +917,9 @@ _ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord
NULL, &height, NULL); NULL, &height, NULL);
height += wy; height += wy;
mx = (x + body->w * body->cm.x) / rate; mx = (x + body->size.w * body->cm.x) / rate;
my = (height - (y + body->h * body->cm.y)) / rate; my = (height - (y + body->size.h * body->cm.y)) / rate;
mz = (z + body->d * body->cm.z) / rate; mz = (z + body->size.d * body->cm.z) / rate;
trans = _ephysics_body_transform_get(body); trans = _ephysics_body_transform_get(body);
trans.setOrigin(btVector3(mx, my, mz)); trans.setOrigin(btVector3(mx, my, mz));
@ -986,9 +986,9 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
_ephysics_body_transform_set(body, trans); _ephysics_body_transform_set(body, trans);
ephysics_body_activate(body, EINA_TRUE); ephysics_body_activate(body, EINA_TRUE);
body->w = w; body->size.w = w;
body->h = h; body->size.h = h;
body->d = d; body->size.d = d;
body->scale = body_scale; body->scale = body_scale;
DBG("Body %p position changed to (%lf, %lf, %lf).", body, mx, my, mz); DBG("Body %p position changed to (%lf, %lf, %lf).", body, mx, my, mz);
@ -1002,12 +1002,12 @@ _ephysics_body_evas_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *o
int w, h; int w, h;
evas_object_geometry_get(obj, NULL, NULL, &w, &h); evas_object_geometry_get(obj, NULL, NULL, &w, &h);
if ((w == body->w) && (h == body->h)) if ((w == body->size.w) && (h == body->size.h))
return; return;
DBG("Resizing body %p to w=%i, h=%i, d=%i", body, w, h, body->d); DBG("Resizing body %p to w=%i, h=%i, d=%i", body, w, h, body->size.d);
ephysics_world_lock_take(body->world); ephysics_world_lock_take(body->world);
_ephysics_body_resize(body, w, h, body->d); _ephysics_body_resize(body, w, h, body->size.d);
ephysics_world_lock_release(body->world); ephysics_world_lock_release(body->world);
} }
@ -2485,9 +2485,9 @@ ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, Evas_Coord
if (y) *y = height - round((trans.getOrigin().getY() + scale.y() / 2) if (y) *y = height - round((trans.getOrigin().getY() + scale.y() / 2)
* rate); * rate);
if (z) *z = round((trans.getOrigin().getZ() - scale.z() / 2) * rate); if (z) *z = round((trans.getOrigin().getZ() - scale.z() / 2) * rate);
if (w) *w = body->w; if (w) *w = body->size.w;
if (h) *h = body->h; if (h) *h = body->size.h;
if (d) *d = body->d; if (d) *d = body->size.d;
} }
EAPI void EAPI void

View File

@ -48,7 +48,11 @@ extern "C" {
#define RAD_TO_DEG 57.29582 /* 2 * pi radians == 360 degree */ #define RAD_TO_DEG 57.29582 /* 2 * pi radians == 360 degree */
typedef struct _EPhysics_Force EPhysics_Force;
typedef struct _EPhysics_Body_Center_Mass EPhysics_Body_Center_Mass;
typedef struct _EPhysics_Body_Size EPhysics_Body_Size;
typedef struct _EPhysics_Point EPhysics_Point; typedef struct _EPhysics_Point EPhysics_Point;
typedef struct _EPhysics_Dragging_Data EPhysics_Dragging_Data;
typedef struct _EPhysics_Body_Soft_Body_Data EPhysics_Body_Soft_Body_Data; typedef struct _EPhysics_Body_Soft_Body_Data EPhysics_Body_Soft_Body_Data;
typedef enum _EPhysics_World_Boundary typedef enum _EPhysics_World_Boundary
@ -62,6 +66,13 @@ typedef enum _EPhysics_World_Boundary
EPHYSICS_WORLD_BOUNDARY_LAST EPHYSICS_WORLD_BOUNDARY_LAST
} EPhysics_World_Boundary; } EPhysics_World_Boundary;
typedef enum _EPhysics_Body_Type
{
EPHYSICS_BODY_TYPE_RIGID,
EPHYSICS_BODY_TYPE_SOFT,
EPHYSICS_BODY_TYPE_CLOTH,
} EPhysics_Body_Type;
struct _EPhysics_Point { struct _EPhysics_Point {
EINA_INLIST; EINA_INLIST;
double x; double x;
@ -69,12 +80,32 @@ struct _EPhysics_Point {
double z; double z;
}; };
typedef enum _EPhysics_Body_Type struct _EPhysics_Force {
{ double x;
EPHYSICS_BODY_TYPE_RIGID, double y;
EPHYSICS_BODY_TYPE_SOFT, double z;
EPHYSICS_BODY_TYPE_CLOTH, double torque_x;
} EPhysics_Body_Type; double torque_y;
double torque_z;
};
struct _EPhysics_Dragging_Data {
int triangle;
double mass[3];
Eina_Bool dragging:1;
};
struct _EPhysics_Body_Center_Mass {
double x;
double y;
double z;
};
struct _EPhysics_Body_Size {
Evas_Coord w;
Evas_Coord h;
Evas_Coord d;
};
struct _EPhysics_Body { struct _EPhysics_Body {
EINA_INLIST; EINA_INLIST;
@ -84,9 +115,7 @@ struct _EPhysics_Body {
Evas_Object *evas_obj; Evas_Object *evas_obj;
EPhysics_World *world; EPhysics_World *world;
int walking; int walking;
Evas_Coord w; EPhysics_Body_Size size;
Evas_Coord h;
Evas_Coord d;
btVector3 scale; btVector3 scale;
void *data; void *data;
Eina_Inlist *callbacks; Eina_Inlist *callbacks;
@ -96,19 +125,8 @@ struct _EPhysics_Body {
EPhysics_Body_Material material; EPhysics_Body_Material material;
double mass; double mass;
double density; double density;
struct { EPhysics_Force force;
double x; EPhysics_Body_Center_Mass cm;
double y;
double z;
double torque_x;
double torque_y;
double torque_z;
} force;
struct {
double x;
double y;
double z;
} cm;
int slices; int slices;
int *points_deform; int *points_deform;
EPhysics_Body_Type type; EPhysics_Body_Type type;
@ -117,11 +135,7 @@ struct _EPhysics_Body {
int material_index; int material_index;
int collision_cb; int collision_cb;
EPhysics_Body_Soft_Body_Data *soft_data; EPhysics_Body_Soft_Body_Data *soft_data;
struct { EPhysics_Dragging_Data dragging_data;
int triangle;
double mass[3];
Eina_Bool dragging;
} dragging_data;
Eina_Bool active:1; Eina_Bool active:1;
Eina_Bool deleted:1; Eina_Bool deleted:1;