From ec5414e7bd3bc5ff93ce83d5065e2106dc5a62c6 Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Tue, 3 Jul 2012 02:18:14 +0000 Subject: [PATCH] EPhysics: fix velocity getters SVN revision: 73185 --- legacy/ephysics/src/bin/test_velocity.c | 4 +++- legacy/ephysics/src/lib/EPhysics.h | 8 ++++++-- legacy/ephysics/src/lib/ephysics_body.cpp | 18 ++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/legacy/ephysics/src/bin/test_velocity.c b/legacy/ephysics/src/bin/test_velocity.c index 2e77bf91c9..e7018bc841 100644 --- a/legacy/ephysics/src/bin/test_velocity.c +++ b/legacy/ephysics/src/bin/test_velocity.c @@ -32,8 +32,10 @@ _update_vel_cb(void *data, EPhysics_Body *body, void *event_info __UNUSED__) Test_Data *test_data = data; double vx, vy, vaz; + vaz = ephysics_body_angular_velocity_get(body); ephysics_body_linear_velocity_get(body, &vx, &vy); - ephysics_body_angular_velocity_get(body, &vaz); + vx = (vx > 0 || vx <= -0.01) ? vx : 0; + vy = (vy > 0 || vy <= -0.01) ? vy : 0; snprintf(linear_vel, sizeof(linear_vel), "Linear velocity: x = %.2f, y = %.2f", vx, vy); diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index c9e47b10cb..994d9891d4 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -988,6 +988,8 @@ EAPI double ephysics_body_mass_get(const EPhysics_Body *body); * @param x The linear velocity on axis x. * @param y The linear velocity on axis y. * + * @note EPhysics unit for linear velocity is Evas coordinates per second. + * * @see ephysics_body_angular_velocity_get(). * * @ingroup EPhysics_Body @@ -999,13 +1001,15 @@ EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x * Get body's angular velocity on z axis. * * @param body The physics body. - * @param z The angular velocity on axis z. + * @return The angular velocity on axis z, or 0 on error. + * + * @note EPhysics unit for angular velocity is degrees per second. * * @see ephysics_body_linear_velocity_get(). * * @ingroup EPhysics_Body */ -EAPI void ephysics_body_angular_velocity_get(const EPhysics_Body *body, double *z); +EAPI double ephysics_body_angular_velocity_get(const EPhysics_Body *body); /** * @brief diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index cdb32a8909..813f00684b 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -550,26 +550,28 @@ ephysics_body_mass_get(const EPhysics_Body *body) EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y) { - if (!body) + double rate; + if (!body) { ERR("Can't get body linear velocity, body is null."); return; } - if (x) *x = body->rigid_body->getLinearVelocity().getX(); - if (y) *y = body->rigid_body->getLinearVelocity().getY(); + rate = ephysics_world_rate_get(body->world); + if (x) *x = body->rigid_body->getLinearVelocity().getX() * rate; + if (y) *y = -body->rigid_body->getLinearVelocity().getY() * rate; } -EAPI void -ephysics_body_angular_velocity_get(const EPhysics_Body *body, double *z) +EAPI double +ephysics_body_angular_velocity_get(const EPhysics_Body *body) { - if (!body) + if (!body) { ERR("Can't get body linear velocity, body is null."); - return; + return 0; } - if (z) *z = body->rigid_body->getAngularVelocity().getZ(); + return -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG; } EAPI void