EPhysics: consider gravity on forces getter
authorBruno Dilly <bdilly@profusion.mobi>
Mon, 20 Aug 2012 22:17:34 +0000 (22:17 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Mon, 20 Aug 2012 22:17:34 +0000 (22:17 +0000)
SVN revision: 75479

legacy/ephysics/src/lib/EPhysics.h
legacy/ephysics/src/lib/ephysics_body.cpp

index 4809864..381e970 100644 (file)
@@ -2444,7 +2444,8 @@ EAPI void ephysics_body_force_apply(EPhysics_Body *body, double x, double y, Eva
  * @brief
  * Get physics body forces.
  *
- * Get all the forces applied over a body.
+ * Get all the forces applied over a body, including gravity.
+ * Damping is not considered.
  *
  * @param body The physics body.
  * @param x The axis x component of total force.
@@ -2455,6 +2456,7 @@ EAPI void ephysics_body_force_apply(EPhysics_Body *body, double x, double y, Eva
  * @see ephysics_body_central_force_apply().
  * @see ephysics_body_torque_apply().
  * @see ephysics_body_forces_clear().
+ * @see ephysics_world_gravity_set().
  *
  * @ingroup EPhysics_Body
  */
index c495bcb..57ba19c 100644 (file)
@@ -1461,7 +1461,7 @@ ephysics_body_torque_apply(EPhysics_Body *body, double torque)
 EAPI void
 ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double *torque)
 {
-   double rate;
+   double rate, gx, gy;
 
    if (!body)
      {
@@ -1470,9 +1470,10 @@ ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double
      }
 
    rate = ephysics_world_rate_get(body->world);
+   ephysics_world_gravity_get(body->world, &gx, &gy);
 
-   if (x) *x = body->force.x * rate;
-   if (y) *y = body->force.y * rate;
+   if (x) *x = body->force.x * rate + gx;
+   if (y) *y = body->force.y * rate + gy;
    if (torque) *torque = -body->force.torque;
 }