EPhysics: velocity setters and stop

SVN revision: 73312
This commit is contained in:
Bruno Dilly 2012-07-04 22:04:37 +00:00
parent fe013dc22e
commit c45cfc3be1
2 changed files with 102 additions and 3 deletions

View File

@ -663,7 +663,7 @@ EAPI double ephysics_world_linear_slop_get(EPhysics_World *world);
* by the top. * by the top.
* *
* It's useful when you don't care about bodies leaving the render * It's useful when you don't care about bodies leaving the render
* area set with @ref ephysics_world_render_area_set(), and don't think * area set with @ref ephysics_world_render_geometry_set(), and don't think
* they could / should return. So you can safely delete them and save resources. * they could / should return. So you can safely delete them and save resources.
* *
* Also, it's useful if you have only a bottom border set with * Also, it's useful if you have only a bottom border set with
@ -1160,6 +1160,23 @@ EAPI void ephysics_body_mass_set(EPhysics_Body *body, double mass);
*/ */
EAPI double ephysics_body_mass_get(const EPhysics_Body *body); EAPI double ephysics_body_mass_get(const EPhysics_Body *body);
/**
* @brief
* Set body's linear velocity on x and y axis.
*
* @param body The physics 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_linear_velocity_get().
* @see ephysics_body_angular_velocity_set().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y);
/** /**
* @brief * @brief
* Get body's linear velocity on x and y axis. * Get body's linear velocity on x and y axis.
@ -1170,12 +1187,29 @@ EAPI double ephysics_body_mass_get(const EPhysics_Body *body);
* *
* @note EPhysics unit for linear velocity is Evas coordinates per second. * @note EPhysics unit for linear velocity is Evas coordinates per second.
* *
* @see ephysics_body_linear_velocity_set().
* @see ephysics_body_angular_velocity_get(). * @see ephysics_body_angular_velocity_get().
* *
* @ingroup EPhysics_Body * @ingroup EPhysics_Body
*/ */
EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y); EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y);
/**
* @brief
* Set body's angular velocity on z axis.
*
* @param body The physics body.
* @param z The angular velocity on axis z.
*
* @note EPhysics unit for angular velocity is degrees per second.
*
* @see ephysics_body_angular_velocity_set().
* @see ephysics_body_linear_velocity_get().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_angular_velocity_set(EPhysics_Body *body, double z);
/** /**
* @brief * @brief
* Get body's angular velocity on z axis. * Get body's angular velocity on z axis.
@ -1191,6 +1225,26 @@ EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x
*/ */
EAPI double ephysics_body_angular_velocity_get(const EPhysics_Body *body); EAPI double ephysics_body_angular_velocity_get(const EPhysics_Body *body);
/**
* @brief
* Stop angular and linear body movement.
*
* It's equivalent to set linear velocity to 0 on both axis and
* angular velocity to 0 as well.
*
* It's a momentary situation. If it receives impulse, directly or
* by collision, if gravity acts over this body,
* it will stop but it will accelerate again.
*
* @param body The physics body.
*
* @see ephysics_body_angular_velocity_set().
* @see ephysics_body_linear_velocity_set().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_stop(EPhysics_Body *body);
/** /**
* @brief * @brief
* Update the evas object associated to the body. * Update the evas object associated to the body.

View File

@ -574,13 +574,30 @@ ephysics_body_mass_get(const EPhysics_Body *body)
return 1 / body->rigid_body->getInvMass(); return 1 / body->rigid_body->getInvMass();
} }
EAPI void
ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y)
{
double rate;
if (!body)
{
ERR("Can't set body linear velocity, body is null.");
return;
}
rate = ephysics_world_rate_get(body->world);
body->rigid_body->setLinearVelocity(btVector3(x / rate, y / rate, 0));
DBG("Linear velocity of body %p set to %lf, %lf", body, x, y);
}
EAPI void EAPI void
ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y) ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y)
{ {
double rate; double rate;
if (!body) if (!body)
{ {
ERR("Can't get body linear velocity, body is null."); ERR("Can't get linear velocity, body is null.");
return; return;
} }
@ -589,18 +606,46 @@ ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *
if (y) *y = -body->rigid_body->getLinearVelocity().getY() * rate; if (y) *y = -body->rigid_body->getLinearVelocity().getY() * rate;
} }
EAPI void
ephysics_body_angular_velocity_set(EPhysics_Body *body, double z)
{
if (!body)
{
ERR("Can't set angular velocity, body is null.");
return;
}
body->rigid_body->setAngularVelocity(btVector3(0, 0, -z/RAD_TO_DEG));
DBG("Angular velocity of body %p set to %lf", body, z);
}
EAPI double EAPI double
ephysics_body_angular_velocity_get(const EPhysics_Body *body) ephysics_body_angular_velocity_get(const EPhysics_Body *body)
{ {
if (!body) if (!body)
{ {
ERR("Can't get body linear velocity, body is null."); ERR("Can't get angular velocity, body is null.");
return 0; return 0;
} }
return -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG; return -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG;
} }
EAPI void
ephysics_body_stop(EPhysics_Body *body)
{
if (!body)
{
ERR("Can't stop a null body.");
return;
}
body->rigid_body->setLinearVelocity(btVector3(0, 0, 0));
body->rigid_body->setAngularVelocity(btVector3(0, 0, 0));
DBG("Body %p stopped", body);
}
EAPI void EAPI void
ephysics_body_evas_object_update(EPhysics_Body *body) ephysics_body_evas_object_update(EPhysics_Body *body)
{ {