ephysics: support angular and linear velocity on 3

axes




SVN revision: 77779
This commit is contained in:
Bruno Dilly 2012-10-10 19:17:29 +00:00
parent f7c2009910
commit 71583d30e3
8 changed files with 52 additions and 38 deletions

View File

@ -392,7 +392,8 @@ _body_linear_velocity_x_cb(void *data, Evas_Object *obj,
double ylinear;
ylinear = elm_spinner_value_get(evas_object_data_get(obj, "y"));
ephysics_body_linear_velocity_set(body, elm_spinner_value_get(obj), ylinear);
ephysics_body_linear_velocity_set(body, elm_spinner_value_get(obj), ylinear,
0);
}
static void
@ -403,7 +404,8 @@ _body_linear_velocity_y_cb(void *data, Evas_Object *obj,
double xlinear;
xlinear = elm_spinner_value_get(evas_object_data_get(obj, "x"));
ephysics_body_linear_velocity_set(body, xlinear, elm_spinner_value_get(obj));
ephysics_body_linear_velocity_set(body, xlinear, elm_spinner_value_get(obj),
0);
}
static void
@ -411,7 +413,7 @@ _body_angular_velocity_cb(void *data, Evas_Object *obj,
void *event_info __UNUSED__)
{
EPhysics_Body *body = data;
ephysics_body_angular_velocity_set(body, elm_spinner_value_get(obj));
ephysics_body_angular_velocity_set(body, 0, 0, elm_spinner_value_get(obj));
}
/*
static void

View File

@ -13,8 +13,8 @@ _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info _
ephysics_body_forces_get(body, &x, &y, &torque);
DBG("Body %p, fx: %lf, fy: %lf, torque: %lf", body, x, y, torque);
ephysics_body_linear_velocity_get(body, &vx, &vy);
va = ephysics_body_angular_velocity_get(body);
ephysics_body_linear_velocity_get(body, &vx, &vy, NULL);
ephysics_body_angular_velocity_get(body, NULL, NULL, &va);
DBG("Body %p, vx: %lf, vy: %lf, va: %lf", body, vx, vy, va);
}

View File

@ -42,7 +42,7 @@ _world_populate(Test_Data *test_data)
update_object_cb, sh1);
ephysics_body_restitution_set(box_body1, 0.7);
ephysics_body_friction_set(box_body1, 0);
ephysics_body_linear_velocity_set(box_body1, -30, 40);
ephysics_body_linear_velocity_set(box_body1, -30, 40, 0);
ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1);
test_data->bodies = eina_list_append(test_data->bodies, box_body1);
@ -68,8 +68,8 @@ _world_populate(Test_Data *test_data)
update_object_cb, sh2);
ephysics_body_restitution_set(box_body2, 0.7);
ephysics_body_friction_set(box_body2, 0);
ephysics_body_linear_velocity_set(box_body2, 40, -30);
ephysics_body_angular_velocity_set(box_body2, 36);
ephysics_body_linear_velocity_set(box_body2, 40, -30, 0);
ephysics_body_angular_velocity_set(box_body2, 0, 0, 36);
ephysics_body_sleeping_threshold_set(box_body2, 0.1, 0.1);
test_data->bodies = eina_list_append(test_data->bodies, box_body2);
test_data->data = box_body2;

View File

@ -69,7 +69,7 @@ _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info _
double rot, vrot, torque;
ephysics_body_rotation_get(body, NULL, NULL, &rot);
vrot = ephysics_body_angular_velocity_get(body);
ephysics_body_angular_velocity_get(body, NULL, NULL, &vrot);
ephysics_body_forces_get(body, NULL, NULL, &torque);
ephysics_body_evas_object_update(body);

View File

@ -35,7 +35,7 @@ _world_populate(Test_Data *test_data)
ephysics_body_restitution_set(sphere_body1, 1);
ephysics_body_friction_set(sphere_body1, 0.4);
ephysics_body_sleeping_threshold_set(sphere_body1, 60, 360);
ephysics_body_linear_velocity_set(sphere_body1, 100, 0);
ephysics_body_linear_velocity_set(sphere_body1, 100, 0, 0);
ephysics_body_damping_set(sphere_body1, 0.5, 0.5);
test_data->bodies = eina_list_append(test_data->bodies, sphere_body1);
@ -63,7 +63,7 @@ _world_populate(Test_Data *test_data)
ephysics_body_restitution_set(sphere_body2, 1);
ephysics_body_friction_set(sphere_body2, 0.4);
ephysics_body_sleeping_threshold_set(sphere_body2, 10, 360);
ephysics_body_linear_velocity_set(sphere_body2, -100, 0);
ephysics_body_linear_velocity_set(sphere_body2, -100, 0, 0);
ephysics_body_damping_set(sphere_body2, 0.5, 0.5);
test_data->bodies = eina_list_append(test_data->bodies, sphere_body2);

View File

@ -52,8 +52,8 @@ _update_vel_cb(void *data, EPhysics_Body *body, void *event_info __UNUSED__)
delta_time = time_now - velocity_data->last_time;
velocity_data->last_time = time_now;
vaz = ephysics_body_angular_velocity_get(body);
ephysics_body_linear_velocity_get(body, &vx, &vy);
ephysics_body_angular_velocity_get(body, NULL, NULL, &vaz);
ephysics_body_linear_velocity_get(body, &vx, &vy, NULL);
vx = (vx > 0 || vx <= -0.01) ? vx : 0;
vy = (vy > 0 || vy <= -0.01) ? vy : 0;

View File

@ -2102,11 +2102,12 @@ EAPI double ephysics_body_mass_get(const EPhysics_Body *body);
/**
* @brief
* Set body's linear velocity on x and y axis.
* Set body's linear velocity on x, y and z axes.
*
* @param body The physics body.
* @param x The linear velocity on axis x.
* @param y The linear velocity on axis y.
* @param z The linear velocity on axis z.
*
* @note EPhysics unit for linear velocity is Evas coordinates per second.
*
@ -2115,15 +2116,16 @@ EAPI double ephysics_body_mass_get(const EPhysics_Body *body);
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y);
EAPI void ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double z);
/**
* @brief
* Get body's linear velocity on x and y axis.
* Get body's linear velocity on x, y and z axes.
*
* @param body The physics body.
* @param x The linear velocity on axis x.
* @param y The linear velocity on axis y.
* @param z The linear velocity on axis z.
*
* @note EPhysics unit for linear velocity is Evas coordinates per second.
*
@ -2132,13 +2134,15 @@ EAPI void ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, doubl
*
* @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, double *z);
/**
* @brief
* Set body's angular velocity on z axis.
* Set body's angular velocity on x, y and z axes.
*
* @param body The physics body.
* @param x The angular velocity on axis x.
* @param y The angular velocity on axis y.
* @param z The angular velocity on axis z.
*
* @note EPhysics unit for angular velocity is degrees per second.
@ -2148,14 +2152,16 @@ EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_angular_velocity_set(EPhysics_Body *body, double z);
EAPI void ephysics_body_angular_velocity_set(EPhysics_Body *body, double x, double y, double z);
/**
* @brief
* Get body's angular velocity on z axis.
* Get body's angular velocity on x, y and z axes.
*
* @param body The physics body.
* @return The angular velocity on axis z, or 0 on error.
* @param x The angular velocity on axis x.
* @param y The angular velocity on axis y.
* @param z The angular velocity on axis z.
*
* @note EPhysics unit for angular velocity is degrees per second.
*
@ -2164,7 +2170,7 @@ EAPI void ephysics_body_angular_velocity_set(EPhysics_Body *body, double z);
*
* @ingroup EPhysics_Body
*/
EAPI double ephysics_body_angular_velocity_get(const EPhysics_Body *body);
EAPI void ephysics_body_angular_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z);
/**
* @brief

View File

@ -479,10 +479,11 @@ _ephysics_body_sleeping_threshold_set(EPhysics_Body *body, double linear_thresho
}
static inline void
_ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double rate)
_ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double z, double rate)
{
ephysics_body_activate(body, EINA_TRUE);
body->rigid_body->setLinearVelocity(btVector3(x / rate, -y / rate, 0));
body->rigid_body->setLinearVelocity(btVector3(x / rate, -y / rate,
z / rate));
}
static void
@ -1087,14 +1088,14 @@ void
ephysics_body_recalc(EPhysics_Body *body, double rate)
{
Evas_Coord x, y, z, w, h, d;
double vx, vy, lt, at;
double vx, vy, vz, lt, at;
ephysics_body_geometry_get(body, &x, &y, &z, &w, &h, &d);
ephysics_body_linear_velocity_get(body, &vx, &vy);
ephysics_body_linear_velocity_get(body, &vx, &vy, &vz);
ephysics_body_sleeping_threshold_get(body, &lt, &at);
_ephysics_body_geometry_set(body, x, y, z, w, h, d, rate);
_ephysics_body_linear_velocity_set(body, vx, vy, rate);
_ephysics_body_linear_velocity_set(body, vx, vy, vz, rate);
_ephysics_body_sleeping_threshold_set(body, lt, at, rate);
}
@ -2076,7 +2077,7 @@ ephysics_body_mass_get(const EPhysics_Body *body)
}
EAPI void
ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y)
ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double z)
{
if (!body)
{
@ -2084,13 +2085,13 @@ ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y)
return;
}
_ephysics_body_linear_velocity_set(body, x, y,
_ephysics_body_linear_velocity_set(body, x, y, z,
ephysics_world_rate_get(body->world));
DBG("Linear velocity of body %p set to %lf, %lf", body, x, y);
DBG("Linear velocity of body %p set to (%lf, %lf, %lf).", body, x, y, z);
}
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 *z)
{
double rate;
@ -2103,10 +2104,11 @@ ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *
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;
if (z) *z = body->rigid_body->getLinearVelocity().getZ() * rate;
}
EAPI void
ephysics_body_angular_velocity_set(EPhysics_Body *body, double z)
ephysics_body_angular_velocity_set(EPhysics_Body *body, double x, double y, double z)
{
if (!body)
{
@ -2115,21 +2117,25 @@ ephysics_body_angular_velocity_set(EPhysics_Body *body, double z)
}
ephysics_world_lock_take(body->world);
body->rigid_body->setAngularVelocity(btVector3(0, 0, -z/RAD_TO_DEG));
DBG("Angular velocity of body %p set to %lf", body, z);
body->rigid_body->setAngularVelocity(btVector3(-x / RAD_TO_DEG,
-y / RAD_TO_DEG,
-z/RAD_TO_DEG));
DBG("Angular velocity of body %p set to (%lf, %lf, %lf).", body, x, y, z);
ephysics_world_lock_release(body->world);
}
EAPI double
ephysics_body_angular_velocity_get(const EPhysics_Body *body)
EAPI void
ephysics_body_angular_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z)
{
if (!body)
{
ERR("Can't get angular velocity, body is null.");
return 0;
return;
}
return -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG;
if (x) *x = -body->rigid_body->getAngularVelocity().getX() * RAD_TO_DEG;
if (y) *y = -body->rigid_body->getAngularVelocity().getY() * RAD_TO_DEG;
if (z) *z = -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG;
}
EAPI void