forked from enlightenment/efl
EPhysics: fix ephysics central impulse unit and
improve docs It should use a unit based on pixels, not meters. This way is more compatible with the rest of API and easier to see the result. SVN revision: 75472
This commit is contained in:
parent
df457b4645
commit
5c32157f04
|
@ -266,7 +266,7 @@ elm_main(int argc __UNUSED__, char **argv __UNUSED__)
|
|||
ephysics_body_rotation_on_z_axis_enable_set(letter_body, EINA_TRUE);
|
||||
|
||||
/* make the "E" logo get into the viewport by applying an horizontal force */
|
||||
ephysics_body_central_impulse_apply(letter_body, 13, 0);
|
||||
ephysics_body_central_impulse_apply(letter_body, 390, 0);
|
||||
|
||||
elm_run();
|
||||
|
||||
|
|
|
@ -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, 10);
|
||||
ephysics_body_central_impulse_apply(body, 0, 300);
|
||||
else if (strcmp(ev->keyname, "Down") == 0)
|
||||
ephysics_body_central_impulse_apply(body, 0, -10);
|
||||
ephysics_body_central_impulse_apply(body, 0, -300);
|
||||
else if (strcmp(ev->keyname, "Right") == 0)
|
||||
ephysics_body_central_impulse_apply(body, 10, 0);
|
||||
ephysics_body_central_impulse_apply(body, 300, 0);
|
||||
else if (strcmp(ev->keyname, "Left") == 0)
|
||||
ephysics_body_central_impulse_apply(body, -10, 0);
|
||||
ephysics_body_central_impulse_apply(body, -300, 0);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
|
|
@ -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, 10, 0);
|
||||
ephysics_body_central_impulse_apply(fall_body, 300, 0);
|
||||
|
||||
shadow = elm_layout_add(camera_data->base.win);
|
||||
elm_layout_file_set(
|
||||
|
|
|
@ -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, 3, 0);
|
||||
ephysics_body_central_impulse_apply(body, 90, 0);
|
||||
track_data->body = body;
|
||||
track_data->base.bodies = eina_list_append(track_data->base.bodies, body);
|
||||
}
|
||||
|
|
|
@ -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, 12, 0);
|
||||
ephysics_body_central_impulse_apply(sphere_body2, 360, 0);
|
||||
collision_data->sphere2 = sphere_body2;
|
||||
collision_data->base.bodies = eina_list_append(
|
||||
collision_data->base.bodies, sphere_body2);
|
||||
|
|
|
@ -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, 20 * row - 10, 0);
|
||||
ephysics_body_central_impulse_apply(fall_body, 600 * row - 300, 0);
|
||||
test_data->bodies = eina_list_append(test_data->bodies, fall_body);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,13 @@ static void
|
|||
_shoot(void *data, Evas_Object *obj, void *event_info __UNUSED__)
|
||||
{
|
||||
Speed_Data *speed_data = data;
|
||||
double impulse;
|
||||
double impulse, rate;
|
||||
|
||||
rate = ephysics_world_rate_get(ephysics_body_world_get(speed_data->ball));
|
||||
impulse = elm_spinner_value_get(speed_data->sp);
|
||||
|
||||
elm_object_disabled_set(obj, EINA_TRUE);
|
||||
impulse = elm_spinner_value_get(speed_data->sp);
|
||||
ephysics_body_central_impulse_apply(speed_data->ball, impulse, 0);
|
||||
ephysics_body_central_impulse_apply(speed_data->ball, impulse * rate, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -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, 12, 0);
|
||||
ephysics_body_central_impulse_apply(sphere_body2, 360, 0);
|
||||
collision_data->sphere2 = sphere_body2;
|
||||
collision_data->base.bodies = eina_list_append(
|
||||
collision_data->base.bodies, sphere_body2);
|
||||
|
|
|
@ -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, 10, 0);
|
||||
ephysics_body_central_impulse_apply(sphere_body, 300, 0);
|
||||
test_data->bodies = eina_list_append(test_data->bodies, sphere_body);
|
||||
}
|
||||
|
||||
|
|
|
@ -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, 10);
|
||||
ephysics_body_central_impulse_apply(body, 0, 300);
|
||||
eina_list_free(bodies);
|
||||
}
|
||||
|
||||
|
|
|
@ -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, -8, 0);
|
||||
ephysics_body_central_impulse_apply(box_body3, -240, 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, -20, 0);
|
||||
ephysics_body_central_impulse_apply(box_body4, -600, 0);
|
||||
test_data->constraints = eina_list_append(test_data->constraints,
|
||||
constraint);
|
||||
|
||||
|
|
|
@ -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, 10);
|
||||
ephysics_body_central_impulse_apply(body, 0, 300);
|
||||
else if (strcmp(ev->keyname, "Down") == 0)
|
||||
ephysics_body_central_impulse_apply(body, 0, -10);
|
||||
ephysics_body_central_impulse_apply(body, 0, -300);
|
||||
else if (strcmp(ev->keyname, "Right") == 0)
|
||||
ephysics_body_central_impulse_apply(body, 10, 0);
|
||||
ephysics_body_central_impulse_apply(body, 300, 0);
|
||||
else if (strcmp(ev->keyname, "Left") == 0)
|
||||
ephysics_body_central_impulse_apply(body, -10, 0);
|
||||
ephysics_body_central_impulse_apply(body, -300, 0);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
|
|
@ -2120,14 +2120,24 @@ EAPI double ephysics_body_friction_get(const EPhysics_Body *body);
|
|||
* Apply an impulse on the center of a body.
|
||||
*
|
||||
* The impulse is equal to the change of momentum of the body.
|
||||
* It's the product of the force over the time this force is applied.
|
||||
*
|
||||
* When a impulse is applied over a body it will has its velocity changed.
|
||||
* Impulse is the product of the force over the time this force is applied.
|
||||
* In ephysics case, it would be the time of a tick, so it behaves just
|
||||
* summing current linear velocity to impulse per mass.
|
||||
*
|
||||
* Example:
|
||||
* A body of 2kg of mass has an initial velocity of 30 p/s.
|
||||
* 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)
|
||||
*
|
||||
* 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
|
||||
* rotating the body. For that is possible to apply a torque impulse with
|
||||
* @ref ephysics_body_torque_impulse_apply().
|
||||
*
|
||||
* @note Impulse is measured in Ns (Newton seconds).
|
||||
* @note Impulse is measured in kg * p / s.
|
||||
*
|
||||
* @param body The physics body that will receive the impulse.
|
||||
* @param x The axis x component of impulse.
|
||||
|
|
|
@ -1223,14 +1223,18 @@ ephysics_body_world_get(const EPhysics_Body *body)
|
|||
EAPI void
|
||||
ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y)
|
||||
{
|
||||
double rate;
|
||||
|
||||
if (!body)
|
||||
{
|
||||
ERR("Can't apply impulse to a null body.");
|
||||
return;
|
||||
}
|
||||
|
||||
rate = ephysics_world_rate_get(body->world);
|
||||
|
||||
body->rigid_body->activate(1);
|
||||
body->rigid_body->applyCentralImpulse(btVector3(x, y, 0));
|
||||
body->rigid_body->applyCentralImpulse(btVector3(x / rate, y / rate, 0));
|
||||
}
|
||||
|
||||
EAPI void
|
||||
|
|
Loading…
Reference in New Issue