ephysics: impulses support the 3 planes

SVN revision: 77780
This commit is contained in:
Bruno Dilly 2012-10-10 19:17:36 +00:00
parent 71583d30e3
commit a1897ddf57
16 changed files with 50 additions and 39 deletions

View File

@ -266,7 +266,7 @@ elm_main(int argc __UNUSED__, char **argv __UNUSED__)
EINA_FALSE, EINA_TRUE);
/* make the "E" logo get into the viewport by applying an horizontal force */
ephysics_body_central_impulse_apply(letter_body, 390, 0);
ephysics_body_central_impulse_apply(letter_body, 390, 0, 0);
elm_run();

View File

@ -261,8 +261,8 @@ _body_impulse_x_x_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
rel_x = elm_spinner_value_get(evas_object_data_get(obj, "relx"));
rel_y = elm_spinner_value_get(evas_object_data_get(obj, "rely"));
ephysics_body_impulse_apply(body, elm_spinner_value_get(obj), y, rel_x,
rel_y);
ephysics_body_impulse_apply(body, elm_spinner_value_get(obj), y, 0,
rel_x, rel_y, 0);
}
static void
@ -280,7 +280,8 @@ _body_impulse_x_rel_cb(void *data, Evas_Object *obj,
y = elm_spinner_value_get(evas_object_data_get(aux, "y"));
rel_y = elm_spinner_value_get(evas_object_data_get(aux, "rely"));
ephysics_body_impulse_apply(body, x, y, elm_spinner_value_get(obj), rel_y);
ephysics_body_impulse_apply(body, x, y, 0,
elm_spinner_value_get(obj), rel_y, 0);
}
static void
@ -297,8 +298,8 @@ _body_impulse_y_y_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
rel_x = elm_spinner_value_get(evas_object_data_get(aux, "relx"));
rel_y = elm_spinner_value_get(evas_object_data_get(aux, "rely"));
ephysics_body_impulse_apply(body, x, elm_spinner_value_get(obj), rel_x,
rel_y);
ephysics_body_impulse_apply(body, x, elm_spinner_value_get(obj), 0,
rel_x, rel_y, 0);
}
static void
@ -316,7 +317,8 @@ _body_impulse_y_rel_cb(void *data, Evas_Object *obj,
y = elm_spinner_value_get(evas_object_data_get(aux, "y"));
rel_x = elm_spinner_value_get(evas_object_data_get(aux, "relx"));
ephysics_body_impulse_apply(body, x, y, rel_x, elm_spinner_value_get(obj));
ephysics_body_impulse_apply(body, x, y, 0,
rel_x, 0, elm_spinner_value_get(obj));
}
static void
@ -715,7 +717,7 @@ _sandie_body_add(Evas_Object *win, EPhysics_World *world, int x, int y)
body = ephysics_body_circle_add(world);
ephysics_body_evas_object_set(body, body_image, EINA_TRUE);
ephysics_body_mass_set(body, 20);
ephysics_body_central_impulse_apply(body, 8201, 2110);
ephysics_body_central_impulse_apply(body, 8201, 2110, 0);
ephysics_body_event_callback_add(body, EPHYSICS_CALLBACK_BODY_DEL,
_body_del, NULL);

View File

@ -14,13 +14,13 @@ _on_keydown(void *data, Evas_Object *obj __UNUSED__, Evas_Object *src __UNUSED__
return EINA_FALSE;
if (strcmp(ev->keyname, "Up") == 0)
ephysics_body_central_impulse_apply(body, 0, -300);
ephysics_body_central_impulse_apply(body, 0, -300, 0);
else if (strcmp(ev->keyname, "Down") == 0)
ephysics_body_central_impulse_apply(body, 0, 300);
ephysics_body_central_impulse_apply(body, 0, 300, 0);
else if (strcmp(ev->keyname, "Right") == 0)
ephysics_body_central_impulse_apply(body, 300, 0);
ephysics_body_central_impulse_apply(body, 300, 0, 0);
else if (strcmp(ev->keyname, "Left") == 0)
ephysics_body_central_impulse_apply(body, -300, 0);
ephysics_body_central_impulse_apply(body, -300, 0, 0);
return EINA_TRUE;
}

View File

@ -103,7 +103,7 @@ _world_populate(Camera_Data *camera_data)
update_object_cb, shadow);
camera_data->base.bodies = eina_list_append(camera_data->base.bodies,
fall_body);
ephysics_body_central_impulse_apply(fall_body, 300, 0);
ephysics_body_central_impulse_apply(fall_body, 300, 0, 0);
shadow = elm_layout_add(camera_data->base.win);
elm_layout_file_set(

View File

@ -131,7 +131,7 @@ _world_populate(Track_Data *track_data)
ephysics_body_restitution_set(body, 0.95);
ephysics_body_friction_set(body, 1);
ephysics_body_damping_set(body, 0.1, 0);
ephysics_body_central_impulse_apply(body, 90, 0);
ephysics_body_central_impulse_apply(body, 90, 0, 0);
track_data->body = body;
track_data->base.bodies = eina_list_append(track_data->base.bodies, body);
}

View File

@ -95,7 +95,7 @@ _world_populate(Collision_Data *collision_data)
update_object_cb, sh2);
ephysics_body_restitution_set(sphere_body2, 1);
ephysics_body_friction_set(sphere_body2, 0.4);
ephysics_body_central_impulse_apply(sphere_body2, 360, 0);
ephysics_body_central_impulse_apply(sphere_body2, 360, 0, 0);
collision_data->sphere2 = sphere_body2;
collision_data->base.bodies = eina_list_append(
collision_data->base.bodies, sphere_body2);

View File

@ -35,7 +35,7 @@ _world_populate(Test_Data *test_data)
ephysics_body_friction_set(fall_body, 0.1);
ephysics_body_collision_group_add(fall_body, colors[row]);
if (column + row == 1)
ephysics_body_central_impulse_apply(fall_body, 600 * row - 300, 0);
ephysics_body_central_impulse_apply(fall_body, 600 * row - 300, 0, 0);
test_data->bodies = eina_list_append(test_data->bodies, fall_body);
}
}

View File

@ -23,7 +23,7 @@ _shoot(void *data, Evas_Object *obj, void *event_info __UNUSED__)
impulse = elm_spinner_value_get(speed_data->sp);
elm_object_disabled_set(obj, EINA_TRUE);
ephysics_body_central_impulse_apply(speed_data->ball, impulse * rate, 0);
ephysics_body_central_impulse_apply(speed_data->ball, impulse * rate, 0, 0);
}
static void

View File

@ -114,7 +114,7 @@ _world_populate(Collision_Data *collision_data)
update_object_cb, sh2);
ephysics_body_restitution_set(sphere_body2, 1);
ephysics_body_friction_set(sphere_body2, 0.4);
ephysics_body_central_impulse_apply(sphere_body2, 360, 0);
ephysics_body_central_impulse_apply(sphere_body2, 360, 0, 0);
collision_data->sphere2 = sphere_body2;
collision_data->base.bodies = eina_list_append(
collision_data->base.bodies, sphere_body2);

View File

@ -44,7 +44,7 @@ _add_sphere(Test_Data *test_data, const char *group, int size, int x, int y)
sphere_body = ephysics_body_circle_add(test_data->world);
ephysics_body_evas_object_set(sphere_body, sphere, EINA_TRUE);
ephysics_body_restitution_set(sphere_body, 0.5);
ephysics_body_central_impulse_apply(sphere_body, 300, 0);
ephysics_body_central_impulse_apply(sphere_body, 300, 0, 0);
test_data->bodies = eina_list_append(test_data->bodies, sphere_body);
}

View File

@ -23,7 +23,7 @@ _jump(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
elm_object_disabled_set(bt, EINA_TRUE);
bodies = ephysics_world_bodies_get(world);
EINA_LIST_FOREACH(bodies, l, body)
ephysics_body_central_impulse_apply(body, 0, -300);
ephysics_body_central_impulse_apply(body, 0, -300, 0);
eina_list_free(bodies);
}

View File

@ -99,7 +99,7 @@ _world_populate(Test_Data *test_data)
EPHYSICS_CALLBACK_BODY_UPDATE,
_update_object_cb, NULL);
ephysics_body_torque_impulse_apply(body, 1);
ephysics_body_torque_impulse_apply(body, 0, 0, 1);
cube = elm_image_add(test_data->win);
elm_image_file_set(
@ -116,7 +116,7 @@ _world_populate(Test_Data *test_data)
EPHYSICS_CALLBACK_BODY_UPDATE,
_update_object_cb, NULL);
ephysics_body_impulse_apply(body, 30, 0, 0, -10);
ephysics_body_impulse_apply(body, 30, 0, 0, 0, -10, 0);
cube = elm_image_add(test_data->win);
elm_image_file_set(

View File

@ -94,7 +94,7 @@ _world_populate(Test_Data *test_data)
constraint = ephysics_constraint_slider_add(box_body3);
ephysics_constraint_slider_linear_limit_set(constraint, WIDTH - 120, 0, 0,
0);
ephysics_body_central_impulse_apply(box_body3, -240, 0);
ephysics_body_central_impulse_apply(box_body3, -240, 0, 0);
test_data->constraints = eina_list_append(test_data->constraints,
constraint);
@ -124,7 +124,7 @@ _world_populate(Test_Data *test_data)
constraint = ephysics_constraint_slider_add(box_body4);
ephysics_constraint_slider_linear_limit_set(constraint, WIDTH / 3, 0, 0, 0);
ephysics_body_central_impulse_apply(box_body4, -600, 0);
ephysics_body_central_impulse_apply(box_body4, -600, 0, 0);
test_data->constraints = eina_list_append(test_data->constraints,
constraint);

View File

@ -25,13 +25,13 @@ _on_keydown(void *data, Evas_Object *obj __UNUSED__, Evas_Object *src __UNUSED__
return EINA_FALSE;
if (strcmp(ev->keyname, "Up") == 0)
ephysics_body_central_impulse_apply(body, 0, -300);
ephysics_body_central_impulse_apply(body, 0, -300, 0);
else if (strcmp(ev->keyname, "Down") == 0)
ephysics_body_central_impulse_apply(body, 0, 300);
ephysics_body_central_impulse_apply(body, 0, 300, 0);
else if (strcmp(ev->keyname, "Right") == 0)
ephysics_body_central_impulse_apply(body, 300, 0);
ephysics_body_central_impulse_apply(body, 300, 0, 0);
else if (strcmp(ev->keyname, "Left") == 0)
ephysics_body_central_impulse_apply(body, -300, 0);
ephysics_body_central_impulse_apply(body, -300, 0, 0);
return EINA_TRUE;
}

View File

@ -2626,7 +2626,7 @@ EAPI double ephysics_body_friction_get(const EPhysics_Body *body);
* After a impulse of 30 kg * p / s in the same direction is applied,
* the velocity will be * 45 p/s.
*
* (0, 30) + (0, 300) / 2 = (0, 30) + (0, 15) = (0, 45)
* (0, 30, 0) + (0, 300, 0) / 2 = (0, 30, 0) + (0, 15, 0) = (0, 45, 0)
*
* When a impulse is applied over a body, it will has its velocity changed.
* This impulse will be applied on body's center, so it won't implies in
@ -2638,13 +2638,14 @@ EAPI double ephysics_body_friction_get(const EPhysics_Body *body);
* @param body The physics body that will receive the impulse.
* @param x The axis x component of impulse.
* @param y The axis y component of impulse.
* @param z The axis z component of impulse.
*
* @see ephysics_body_torque_impulse_apply().
* @see ephysics_body_impulse_apply().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y);
EAPI void ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y, double z);
/**
* @brief
@ -2657,6 +2658,10 @@ EAPI void ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, dou
* torque impulse and body's inertia.
*
* @param body The physics body that will receive the impulse.
* @param pitch Impulse to rotate body around Z axis (rotate on y - z plane).
* Negative values will impulse body on counter clockwise rotation.
* @param yaw Impulse to rotate body around Y axis (rotate on x - z plane).
* Negative values will impulse body on counter clockwise rotation.
* @param roll Impulse to rotate body around Z axis (rotate on x - y plane).
* Negative values will impulse body on counter clockwise rotation.
*
@ -2665,7 +2670,7 @@ EAPI void ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, dou
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll);
EAPI void ephysics_body_torque_impulse_apply(EPhysics_Body *body, double pitch, double yaw, double roll);
/**
* @brief
@ -2688,8 +2693,10 @@ EAPI void ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll);
* @param body The physics body that will receive the impulse.
* @param x The axis x component of impulse.
* @param y The axis y component of impulse.
* @param z The axis z component of impulse.
* @param pos_x The axis x component of the relative position to apply impulse.
* @param pos_y The axis y component of the relative position to apply impulse.
* @param pos_z The axis z component of the relative position to apply impulse.
*
* @note Impulse is measured in kg * p / s and position in pixels
* (Evas coordinates).
@ -2699,7 +2706,7 @@ EAPI void ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll);
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_impulse_apply(EPhysics_Body *body, double x, double y, Evas_Coord pos_x, Evas_Coord pos_y);
EAPI void ephysics_body_impulse_apply(EPhysics_Body *body, double x, double y, double z, Evas_Coord pos_x, Evas_Coord pos_y, Evas_Coord pos_z);
/**
* @brief

View File

@ -2418,7 +2418,7 @@ ephysics_body_world_get(const EPhysics_Body *body)
}
EAPI void
ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y)
ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y, double z)
{
double rate;
@ -2432,12 +2432,13 @@ ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y)
ephysics_world_lock_take(body->world);
ephysics_body_activate(body, EINA_TRUE);
body->rigid_body->applyCentralImpulse(btVector3(x / rate, - y / rate, 0));
body->rigid_body->applyCentralImpulse(btVector3(x / rate, - y / rate,
z / rate));
ephysics_world_lock_release(body->world);
}
EAPI void
ephysics_body_impulse_apply(EPhysics_Body *body, double x, double y, Evas_Coord pos_x, Evas_Coord pos_y)
ephysics_body_impulse_apply(EPhysics_Body *body, double x, double y, double z, Evas_Coord pos_x, Evas_Coord pos_y, Evas_Coord pos_z)
{
double rate;
@ -2451,9 +2452,10 @@ ephysics_body_impulse_apply(EPhysics_Body *body, double x, double y, Evas_Coord
ephysics_world_lock_take(body->world);
ephysics_body_activate(body, EINA_TRUE);
body->rigid_body->applyImpulse(btVector3(x / rate, - y / rate, 0),
body->rigid_body->applyImpulse(btVector3(x / rate, - y / rate, z / rate),
btVector3((double) pos_x / rate,
(double) pos_y / rate, 0));
(double) pos_y / rate,
(double) pos_z / rate));
ephysics_world_lock_release(body->world);
}
@ -2487,7 +2489,7 @@ ephysics_body_linear_movement_enable_get(const EPhysics_Body *body, Eina_Bool *e
}
EAPI void
ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll)
ephysics_body_torque_impulse_apply(EPhysics_Body *body, double pitch, double yaw, double roll)
{
if (!body)
{
@ -2497,7 +2499,7 @@ ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll)
ephysics_world_lock_take(body->world);
ephysics_body_activate(body, EINA_TRUE);
body->rigid_body->applyTorqueImpulse(btVector3(0, 0, -roll));
body->rigid_body->applyTorqueImpulse(btVector3(-pitch, -yaw, -roll));
ephysics_world_lock_release(body->world);
}