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();
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;
}
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(
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);
}
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);
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);
}
}
_shoot(void *data, Evas_Object *obj, void *event_info __UNUSED__)
{
Speed_Data *speed_data = data;
- double impulse;
+ double impulse, rate;
- elm_object_disabled_set(obj, EINA_TRUE);
+ rate = ephysics_world_rate_get(ephysics_body_world_get(speed_data->ball));
impulse = elm_spinner_value_get(speed_data->sp);
- ephysics_body_central_impulse_apply(speed_data->ball, impulse, 0);
+
+ elm_object_disabled_set(obj, EINA_TRUE);
+ ephysics_body_central_impulse_apply(speed_data->ball, impulse * rate, 0);
}
static void
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);
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);
}
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);
}
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);
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);
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;
}
* 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.
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