ephysics: support 3 axes on body geometry related

functions

geometry set / get, move, resize



SVN revision: 77777
This commit is contained in:
Bruno Dilly 2012-10-10 19:17:01 +00:00
parent 32f03f55a4
commit 8b9c28f003
12 changed files with 75 additions and 57 deletions

View File

@ -99,7 +99,7 @@ _update_circle_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info)
evas_object_color_set(shadow, alpha, alpha, alpha, alpha);
if (x > E_THRESHOLD)
ephysics_body_move(body, -w - 1, y);
ephysics_body_move(body, -w - 1, y, -15);
}
static void
@ -218,7 +218,8 @@ elm_main(int argc __UNUSED__, char **argv __UNUSED__)
ground_body = ephysics_body_box_add(world);
ephysics_body_mass_set(ground_body, EPHYSICS_BODY_MASS_STATIC);
ephysics_body_geometry_set(ground_body, -100, FLOOR_Y, WIDTH + 800, 10);
ephysics_body_geometry_set(ground_body, -100, FLOOR_Y, -15, WIDTH + 800, 10,
30);
ephysics_body_restitution_set(ground_body, 0.65);
ephysics_body_friction_set(ground_body, 0.8);

View File

@ -22,7 +22,7 @@ _world_populate(Test_Data *test_data)
text_body = ephysics_body_box_add(test_data->world);
ephysics_body_evas_object_set(text_body, text, EINA_FALSE);
ephysics_body_geometry_set(text_body, x, y, w * 5 / 6, 46);
ephysics_body_geometry_set(text_body, x, y, -15, w * 5 / 6, 46, 30);
ephysics_body_restitution_set(text_body, 0.95);
ephysics_body_friction_set(text_body, 0.1);
test_data->bodies = eina_list_append(test_data->bodies, text_body);

View File

@ -227,7 +227,7 @@ test_camera(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info
boundary = ephysics_body_box_add(camera_data->base.world);
ephysics_body_mass_set(boundary, 0);
ephysics_body_geometry_set(boundary, 0, FLOOR_Y, WIDTH * 2, 10);
ephysics_body_geometry_set(boundary, 0, FLOOR_Y, -15, WIDTH * 2, 10, 30);
ephysics_body_restitution_set(boundary, 0.65);
ephysics_body_friction_set(boundary, 4);

View File

@ -238,7 +238,7 @@ test_camera_track(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *even
boundary = ephysics_body_box_add(track_data->base.world);
ephysics_body_mass_set(boundary, 0);
ephysics_body_geometry_set(boundary, 0, FLOOR_Y, WIDTH * 4, 10);
ephysics_body_geometry_set(boundary, 0, FLOOR_Y, -15, WIDTH * 4, 10, 30);
ephysics_body_restitution_set(boundary, 0.65);
ephysics_body_friction_set(boundary, 4);

View File

@ -75,7 +75,8 @@ test_collision_filter(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *
ephysics_body_friction_set(boundary, 2);
boundary = ephysics_body_box_add(test_data->world);
ephysics_body_geometry_set(boundary, 60, FLOOR_Y - 16, WIDTH - 120, 10);
ephysics_body_geometry_set(boundary, 60, FLOOR_Y - 16, -15, WIDTH - 120, 10,
30);
ephysics_body_restitution_set(boundary, 0.65);
ephysics_body_friction_set(boundary, 2);
ephysics_body_mass_set(boundary, 0);

View File

@ -30,7 +30,7 @@ _world_populate(Test_Data *test_data)
text_body = ephysics_body_box_add(test_data->world);
ephysics_body_evas_object_set(text_body, text, EINA_FALSE);
ephysics_body_geometry_set(text_body, x, y, w * 5 / 6, 40);
ephysics_body_geometry_set(text_body, x, y, -15, w * 5 / 6, 40, 30);
ephysics_body_friction_set(text_body, 0.1);
ephysics_body_restitution_set(text_body, 0.95);
test_data->bodies = eina_list_append(test_data->bodies, text_body);

View File

@ -62,7 +62,7 @@ _mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_inf
if (nx < 0 || ny < 0) return;
evas_object_geometry_get(obj, &x, &y, &w, &h);
ephysics_body_move(dragging->body, nx, ny);
ephysics_body_move(dragging->body, nx, ny, -15);
}
static void

View File

@ -62,7 +62,7 @@ _win_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_inf
evas_object_geometry_get(sphere, &x, &y, NULL, NULL);
ephysics_body_move(sphere_body, x * (ratew / old_rate->w),
y * (rateh / old_rate->h));
y * (rateh / old_rate->h), -15);
evas_object_resize(sphere, 70 * ratew, 70 * rateh);
old_rate->w = ratew;

View File

@ -1945,9 +1945,8 @@ EAPI Evas_Object *ephysics_body_evas_object_get(const EPhysics_Body *body);
* @brief
* Set physics body size.
*
* All the physics bodies are and with canonical dimensions.
* Circles have diameter 1, boxes have dimensions 1
* on all the axes.
* By default circles have diameter equal to 1 meter * rate, boxes have
* dimensions 1 meter * rate on all the axes.
*
* There are three direct ways of modifying it's size:
* @li With @ref ephysics_body_resize();
@ -1960,6 +1959,7 @@ EAPI Evas_Object *ephysics_body_evas_object_get(const EPhysics_Body *body);
* @param body The body to be resized.
* @param w The body width, in pixels.
* @param h The body height, in pixels.
* @param d The body depth, in pixels.
*
* @see ephysics_body_geometry_get().
* @see ephysics_body_geometry_set().
@ -1967,13 +1967,13 @@ EAPI Evas_Object *ephysics_body_evas_object_get(const EPhysics_Body *body);
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h);
EAPI void ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coord d);
/**
* @brief
* Set physics body position.
*
* All the physics bodies are created centered on origin (0, 0).
* All the physics bodies are created centered on origin (0, 0, 0).
*
* There are three direct ways of modifying this position:
* @li With @ref ephysics_body_move();
@ -1989,6 +1989,7 @@ EAPI void ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h);
* @param body The body to be positioned.
* @param x The position on axis x, in pixels.
* @param y The position on axis y, in pixels.
* @param z The position on axis z, in pixels.
*
* @see ephysics_body_geometry_get().
* @see ephysics_body_geometry_set().
@ -1996,7 +1997,7 @@ EAPI void ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h);
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y);
EAPI void ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord z);
/**
* @brief
@ -2025,8 +2026,10 @@ EAPI void ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y);
* @param body The body to be modified.
* @param x The position on axis x, in pixels.
* @param y The position on axis y, in pixels.
* @param z The position on axis z, in pixels.
* @param w The body width, in pixels.
* @param h The body height, in pixels.
* @param d The body depth, in pixels.
*
* @see ephysics_body_geometry_get().
* @see ephysics_body_move().
@ -2034,7 +2037,7 @@ EAPI void ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y);
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
EAPI void ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord z, Evas_Coord w, Evas_Coord h, Evas_Coord d);
/**
* @brief
@ -2043,8 +2046,10 @@ EAPI void ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coo
* @param body The physics body.
* @param x The position on axis x, in pixels.
* @param y The position on axis y, in pixels.
* @param z The position on axis z, in pixels.
* @param w The body width, in pixels.
* @param h The body height, in pixels.
* @param d The body depth, in pixels.
*
* @see ephysics_body_geometry_set() for more details.
* @see ephysics_body_move().
@ -2052,7 +2057,7 @@ EAPI void ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coo
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
EAPI void ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, Evas_Coord *y, Evas_Coord *z, Evas_Coord *w, Evas_Coord *h, Evas_Coord *d);
/**
* @brief

View File

@ -828,22 +828,23 @@ _ephysics_body_mass_set(EPhysics_Body *body, double mass)
}
static void
_ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h)
_ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coord d)
{
double rate, sx, sy;
double rate, sx, sy, sz;
rate = ephysics_world_rate_get(body->world);
sx = w / rate;
sy = h / rate;
sz = d / rate;
if (body->soft_body)
{
body->soft_body->scale(btVector3(sx, sy, 1));
body->soft_body->scale(btVector3(sx, sy, sz));
_ephysics_body_soft_body_constraints_rebuild(body);
}
else
{
body->collision_shape->setLocalScaling(btVector3(sx, sy, 1));
body->collision_shape->setLocalScaling(btVector3(sx, sy, sz));
if(!body->rigid_body->isStaticObject())
_ephysics_body_mass_set(body, ephysics_body_mass_get(body));
@ -851,16 +852,17 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h)
body->w = w;
body->h = h;
body->d = d;
ephysics_body_activate(body, EINA_TRUE);
DBG("Body %p scale changed to %lf, %lf.", body, sx, sy);
DBG("Body %p scale changed to (%lf, %lf, %lf).", body, sx, sy, sz);
}
static void
_ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y)
_ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord z)
{
double rate, mx, my;
double rate, mx, my, mz;
btTransform trans;
int wy, height;
btVector3 body_scale;
@ -871,21 +873,22 @@ _ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y)
mx = (x + body->w * body->cm.x) / rate;
my = (height - (y + body->h * body->cm.y)) / rate;
mz = z / rate;
trans = _ephysics_body_transform_get(body);
trans.setOrigin(btVector3(mx, my, 0));
trans.setOrigin(btVector3(mx, my, mz));
body->rigid_body->proceedToTransform(trans);
body->rigid_body->getMotionState()->setWorldTransform(trans);
ephysics_body_activate(body, EINA_TRUE);
DBG("Body %p position changed to %lf, %lf.", body, mx, my);
DBG("Body %p position changed to (%lf, %lf, %lf).", body, mx, my, mz);
}
static void
_ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, double rate)
_ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord z, Evas_Coord w, Evas_Coord h, Evas_Coord d, double rate)
{
double mx, my, sx, sy;
double mx, my, mz, sx, sy, sz;
btTransform trans;
int wy, height;
btVector3 body_scale;
@ -895,12 +898,14 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
mx = (x + w * body->cm.x) / rate;
my = (height - (y + h * body->cm.y)) / rate;
mz = z / rate;
sx = w / rate;
sy = h / rate;
sz = d / rate;
trans = _ephysics_body_transform_get(body);
trans.setOrigin(btVector3(mx, my, trans.getOrigin().z()));
body_scale = btVector3(sx, sy, 1);
trans.setOrigin(btVector3(mx, my, mz));
body_scale = btVector3(sx, sy, sz);
if (body->type == EPHYSICS_BODY_TYPE_SOFT)
{
@ -929,9 +934,10 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
body->w = w;
body->h = h;
body->d = d;
DBG("Body %p position changed to %lf, %lf.", body, mx, my);
DBG("Body %p scale changed to %lf, %lf.", body, sx, sy);
DBG("Body %p position changed to (%lf, %lf, %lf).", body, mx, my, mz);
DBG("Body %p scale changed to (%lf, %lf, %lf).", body, sx, sy, sz);
}
static void
@ -944,9 +950,9 @@ _ephysics_body_evas_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *o
if ((w == body->w) && (h == body->h))
return;
DBG("Resizing body %p to w=%i, h=%i", body, w, h);
DBG("Resizing body %p to w=%i, h=%i, d=%i", body, w, h, body->d);
ephysics_world_lock_take(body->world);
_ephysics_body_resize(body, w, h);
_ephysics_body_resize(body, w, h, body->d);
ephysics_world_lock_release(body->world);
}
@ -1044,7 +1050,7 @@ _ephysics_body_outside_render_area_check(EPhysics_Body *body)
int wx, wy, ww, wh, bx, by, bw, bh;
ephysics_world_render_geometry_get(body->world, &wx, &wy, &ww, &wh);
ephysics_body_geometry_get(body, &bx, &by, &bw, &bh);
ephysics_body_geometry_get(body, &bx, &by, NULL, &bw, &bh, NULL);
// FIXME: check what should be done regarding rotated bodies
if (((ephysics_world_bodies_outside_top_autodel_get(body->world)) &&
@ -1079,14 +1085,14 @@ ephysics_body_forces_apply(EPhysics_Body *body)
void
ephysics_body_recalc(EPhysics_Body *body, double rate)
{
Evas_Coord x, y, w, h;
Evas_Coord x, y, z, w, h, d;
double vx, vy, lt, at;
ephysics_body_geometry_get(body, &x, &y, &w, &h);
ephysics_body_geometry_get(body, &x, &y, &z, &w, &h, &d);
ephysics_body_linear_velocity_get(body, &vx, &vy);
ephysics_body_sleeping_threshold_get(body, &lt, &at);
_ephysics_body_geometry_set(body, x, y, w, h, rate);
_ephysics_body_geometry_set(body, x, y, z, w, h, d, rate);
_ephysics_body_linear_velocity_set(body, vx, vy, rate);
_ephysics_body_sleeping_threshold_set(body, lt, at, rate);
}
@ -1729,19 +1735,19 @@ ephysics_body_world_boundaries_resize(EPhysics_World *world)
bottom = ephysics_world_boundary_get(world, EPHYSICS_WORLD_BOUNDARY_BOTTOM);
if (bottom)
ephysics_body_geometry_set(bottom, x, y + height, width, 10);
ephysics_body_geometry_set(bottom, x, y + height, -5, width, 10, 10);
right = ephysics_world_boundary_get(world, EPHYSICS_WORLD_BOUNDARY_RIGHT);
if (right)
ephysics_body_geometry_set(right, x + width, 0, 10, y + height);
ephysics_body_geometry_set(right, x + width, 0, -5, 10, y + height, 10);
left = ephysics_world_boundary_get(world, EPHYSICS_WORLD_BOUNDARY_LEFT);
if (left)
ephysics_body_geometry_set(left, x - 10, 0, 10, y + height);
ephysics_body_geometry_set(left, x - 10, 0, -5, 10, y + height, 10);
top = ephysics_world_boundary_get(world, EPHYSICS_WORLD_BOUNDARY_TOP);
if (top)
ephysics_body_geometry_set(top, 0, y - 10, x + width, 10);
ephysics_body_geometry_set(top, 0, y - 10, -5, x + width, 10, 10);
}
static EPhysics_Body *
@ -1765,7 +1771,7 @@ _ephysics_body_boundary_add(EPhysics_World *world, EPhysics_World_Boundary bound
ephysics_body_mass_set(body, 0);
ephysics_world_boundary_set(world, boundary, body);
ephysics_body_geometry_set(body, x, y, w, h);
ephysics_body_geometry_set(body, x, y, -5, w, h, 10);
return body;
}
@ -1847,6 +1853,7 @@ EAPI Evas_Object *
ephysics_body_evas_object_set(EPhysics_Body *body, Evas_Object *evas_obj, Eina_Bool use_obj_pos)
{
int obj_x, obj_y, obj_w, obj_h;
double rate;
if (!body)
{
@ -1878,9 +1885,10 @@ ephysics_body_evas_object_set(EPhysics_Body *body, Evas_Object *evas_obj, Eina_B
return evas_obj;
evas_object_geometry_get(body->evas_obj, &obj_x, &obj_y, &obj_w, &obj_h);
rate = ephysics_world_rate_get(body->world);
ephysics_world_lock_take(body->world);
_ephysics_body_geometry_set(body, obj_x, obj_y, obj_w, obj_h,
ephysics_world_rate_get(body->world));
_ephysics_body_geometry_set(body, obj_x, obj_y, - rate / 2,
obj_w, obj_h, rate, rate);
if (body->soft_body)
{
@ -1946,7 +1954,7 @@ ephysics_body_evas_object_get(const EPhysics_Body *body)
}
EAPI void
ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord z, Evas_Coord w, Evas_Coord h, Evas_Coord d)
{
if (!body)
{
@ -1954,20 +1962,20 @@ ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas
return;
}
if ((w <= 0) || (h <= 0))
if ((w <= 0) || (h <= 0) || (d <= 0))
{
ERR("Width and height must to be a non-null, positive value.");
ERR("Width, height and depth must to be a non-null, positive value.");
return;
}
ephysics_world_lock_take(body->world);
_ephysics_body_geometry_set(body, x, y, w, h,
_ephysics_body_geometry_set(body, x, y, z, w, h, d,
ephysics_world_rate_get(body->world));
ephysics_world_lock_release(body->world);
}
EAPI void
ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h)
ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coord d)
{
if (!body)
{
@ -1975,19 +1983,19 @@ ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h)
return;
}
if ((w <= 0) || (h <= 0))
if ((w <= 0) || (h <= 0) || (d <= 0))
{
ERR("Width and height must to be a non-null, positive value.");
ERR("Width, height and depth must to be a non-null, positive value.");
return;
}
ephysics_world_lock_take(body->world);
_ephysics_body_resize(body, w, h);
_ephysics_body_resize(body, w, h, d);
ephysics_world_lock_release(body->world);
}
EAPI void
ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y)
ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord z)
{
if (!body)
{
@ -1996,12 +2004,12 @@ ephysics_body_move(EPhysics_Body *body, Evas_Coord x, Evas_Coord y)
}
ephysics_world_lock_take(body->world);
_ephysics_body_move(body, x, y);
_ephysics_body_move(body, x, y, z);
ephysics_world_lock_release(body->world);
}
EAPI void
ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, Evas_Coord *y, Evas_Coord *z, Evas_Coord *w, Evas_Coord *h, Evas_Coord *d)
{
btTransform trans;
btVector3 scale;
@ -2024,8 +2032,10 @@ ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, Evas_Coord
if (x) *x = round((trans.getOrigin().getX() - scale.x() / 2) * rate);
if (y) *y = height - round((trans.getOrigin().getY() + scale.y() / 2)
* rate);
if (z) *z = round((trans.getOrigin().getZ() - scale.z() / 2) * rate);
if (w) *w = body->w;
if (h) *h = body->h;
if (d) *d = body->d;
}
EAPI void

View File

@ -36,7 +36,7 @@ ephysics_camera_target_moved(EPhysics_Camera *camera, EPhysics_Body *body)
{
int x, y, w, h, ww, wh, new_x, new_y;
ephysics_body_geometry_get(body, &x, &y, &w, &h);
ephysics_body_geometry_get(body, &x, &y, NULL, &w, &h, NULL);
ephysics_world_render_geometry_get(camera->world, NULL, NULL, &ww, &wh);
if (camera->track_horizontal)

View File

@ -82,6 +82,7 @@ struct _EPhysics_Body {
int walking;
Evas_Coord w;
Evas_Coord h;
Evas_Coord d;
void *data;
Eina_Inlist *callbacks;
Eina_List *collision_groups;