EPhysics: fix ephysics central impulse unit and
authorBruno Dilly <bdilly@profusion.mobi>
Mon, 20 Aug 2012 22:12:14 +0000 (22:12 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Mon, 20 Aug 2012 22:12:14 +0000 (22:12 +0000)
 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

14 files changed:
legacy/ephysics/src/bin/ephysics_logo.c
legacy/ephysics/src/bin/test_bouncing_ball.c
legacy/ephysics/src/bin/test_camera.c
legacy/ephysics/src/bin/test_camera_track.c
legacy/ephysics/src/bin/test_collision_detection.c
legacy/ephysics/src/bin/test_collision_filter.c
legacy/ephysics/src/bin/test_collision_speed.c
legacy/ephysics/src/bin/test_delete.c
legacy/ephysics/src/bin/test_growing_balls.c
legacy/ephysics/src/bin/test_jumping_balls.c
legacy/ephysics/src/bin/test_slider.c
legacy/ephysics/src/bin/test_velocity.c
legacy/ephysics/src/lib/EPhysics.h
legacy/ephysics/src/lib/ephysics_body.cpp

index 8c4a178..aa8f996 100644 (file)
@@ -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();
 
index b1ecdca..2fb081d 100644 (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, 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;
 }
index 9378a1a..b7b4475 100644 (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, 10, 0);
+   ephysics_body_central_impulse_apply(fall_body, 300, 0);
 
    shadow = elm_layout_add(camera_data->base.win);
    elm_layout_file_set(
index 9dc43ac..c785f4b 100644 (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, 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);
 }
index 112888a..4b23a01 100644 (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, 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);
index 3be4b15..62e61ad 100644 (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, 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);
      }
 }
index 30aba1f..2efd3f0 100644 (file)
@@ -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;
 
-   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
index fb7700a..debfe5a 100644 (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, 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);
index e272f07..0a3531e 100644 (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, 10, 0);
+   ephysics_body_central_impulse_apply(sphere_body, 300, 0);
    test_data->bodies = eina_list_append(test_data->bodies, sphere_body);
 }
 
index 231f99d..9fa0016 100644 (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, 10);
+      ephysics_body_central_impulse_apply(body, 0, 300);
    eina_list_free(bodies);
 }
 
index 927401f..f2c49ce 100644 (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, -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);
 
index a9ba0fd..b541bf7 100644 (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, 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;
 }
index 5aef034..6717a1f 100644 (file)
@@ -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.
index e4aedbf..b2df88a 100644 (file)
@@ -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