forked from enlightenment/efl
ephysics: body rotation getter / setter changed to
support 3 axes SVN revision: 77776
This commit is contained in:
parent
290a7d8821
commit
32f03f55a4
|
@ -180,7 +180,7 @@ static void
|
|||
_body_rotation_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
|
||||
{
|
||||
EPhysics_Body *body = data;
|
||||
ephysics_body_rotation_set(body, elm_spinner_value_get(obj));
|
||||
ephysics_body_rotation_set(body, 0, 0, elm_spinner_value_get(obj));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -10,8 +10,8 @@ _rotate_cb(void *data)
|
|||
EPhysics_Body *body = data;
|
||||
double rotation;
|
||||
|
||||
rotation = ephysics_body_rotation_get(body);
|
||||
ephysics_body_rotation_set(body, ((int) round(rotation) + 5) % 360);
|
||||
ephysics_body_rotation_get(body, NULL, NULL, &rotation);
|
||||
ephysics_body_rotation_set(body, 0, 0, ((int) round(rotation) + 5) % 360);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info _
|
|||
{
|
||||
double rot, vrot, torque;
|
||||
|
||||
rot = ephysics_body_rotation_get(body);
|
||||
ephysics_body_rotation_get(body, NULL, NULL, &rot);
|
||||
vrot = ephysics_body_angular_velocity_get(body);
|
||||
ephysics_body_forces_get(body, NULL, NULL, &torque);
|
||||
|
||||
|
|
|
@ -2769,38 +2769,42 @@ EAPI void ephysics_body_linear_movement_enable_get(const EPhysics_Body *body, Ei
|
|||
|
||||
/**
|
||||
* @brief
|
||||
* Return body's rotation on z axis.
|
||||
* Get body's rotation on x, y and z axes.
|
||||
*
|
||||
* By default rotation is 0 degrees.
|
||||
* By default rotation is 0 degree on all axes.
|
||||
*
|
||||
* @note The unit used for rotation is degrees.
|
||||
*
|
||||
* @param body The physics body.
|
||||
* @return The amount of degrees @p body is rotated, from 0.0 to 360.0.
|
||||
* @param rot_x The amount of degrees @p body is rotated on x axis.
|
||||
* @param rot_y The amount of degrees @p body is rotated on y axis.
|
||||
* @param rot_z The amount of degrees @p body is rotated on z axis.
|
||||
*
|
||||
* @see ephysics_body_rotation_set()
|
||||
*
|
||||
* @ingroup EPhysics_Body
|
||||
*/
|
||||
EAPI double ephysics_body_rotation_get(const EPhysics_Body *body);
|
||||
EAPI void ephysics_body_rotation_get(const EPhysics_Body *body, double *rot_x, double *rot_y, double *rot_z);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Set body's rotation on z axis.
|
||||
*
|
||||
* By default rotation is 0 degrees.
|
||||
* By default rotation is 0 degrees on all axes.
|
||||
* Negative values indicates rotation on counter clockwise direction.
|
||||
*
|
||||
* @note The unit used for rotation is degrees.
|
||||
*
|
||||
* @param body The physics body.
|
||||
* @param rotation The amount of degrees @p body should be rotated.
|
||||
* @param rot_x The amount of degrees @p body should be rotated on x axis.
|
||||
* @param rot_y The amount of degrees @p body should be rotated on y axis.
|
||||
* @param rot_z The amount of degrees @p body should be rotated on z axis.
|
||||
*
|
||||
* @see ephysics_body_rotation_get()
|
||||
*
|
||||
* @ingroup EPhysics_Body
|
||||
*/
|
||||
EAPI void ephysics_body_rotation_set(EPhysics_Body *body, double rotation);
|
||||
EAPI void ephysics_body_rotation_set(EPhysics_Body *body, double rot_x, double rot_y, double rot_z);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
|
|
@ -2511,27 +2511,29 @@ ephysics_body_angular_movement_enable_get(const EPhysics_Body *body, Eina_Bool *
|
|||
if (enable_z) *enable_z = !!body->rigid_body->getAngularFactor().z();
|
||||
}
|
||||
|
||||
EAPI double
|
||||
ephysics_body_rotation_get(const EPhysics_Body *body)
|
||||
EAPI void
|
||||
ephysics_body_rotation_get(const EPhysics_Body *body, double *rot_x, double *rot_y, double *rot_z)
|
||||
{
|
||||
btTransform trans;
|
||||
double rot;
|
||||
|
||||
if (!body)
|
||||
{
|
||||
ERR("Can't get rotation, body is null.");
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
trans = _ephysics_body_transform_get(body);
|
||||
rot = - trans.getRotation().getAngle() * RAD_TO_DEG *
|
||||
trans.getRotation().getAxis().getZ();
|
||||
|
||||
return rot;
|
||||
if (rot_x) *rot_x = - trans.getRotation().getAngle() * RAD_TO_DEG *
|
||||
trans.getRotation().getAxis().getX();
|
||||
if (rot_y) *rot_y = - trans.getRotation().getAngle() * RAD_TO_DEG *
|
||||
trans.getRotation().getAxis().getY();
|
||||
if (rot_z) *rot_z = - trans.getRotation().getAngle() * RAD_TO_DEG *
|
||||
trans.getRotation().getAxis().getZ();
|
||||
}
|
||||
|
||||
EAPI void
|
||||
ephysics_body_rotation_set(EPhysics_Body *body, double rotation)
|
||||
ephysics_body_rotation_set(EPhysics_Body *body, double rot_x, double rot_y, double rot_z)
|
||||
{
|
||||
btTransform trans;
|
||||
btQuaternion quat;
|
||||
|
@ -2546,7 +2548,7 @@ ephysics_body_rotation_set(EPhysics_Body *body, double rotation)
|
|||
ephysics_body_activate(body, EINA_TRUE);
|
||||
trans = _ephysics_body_transform_get(body);
|
||||
|
||||
quat.setEuler(0, 0, -rotation / RAD_TO_DEG);
|
||||
quat.setEuler(-rot_x / RAD_TO_DEG, -rot_y / RAD_TO_DEG, -rot_z / RAD_TO_DEG);
|
||||
trans.setRotation(quat);
|
||||
|
||||
if (body->soft_body)
|
||||
|
@ -2555,7 +2557,7 @@ ephysics_body_rotation_set(EPhysics_Body *body, double rotation)
|
|||
body->rigid_body->proceedToTransform(trans);
|
||||
body->rigid_body->getMotionState()->setWorldTransform(trans);
|
||||
|
||||
DBG("Body %p rotation set to %lf", body, rotation);
|
||||
DBG("Body %p rotation set to (%lf, %lf, %lf)", body, rot_x, rot_y, rot_z);
|
||||
ephysics_world_lock_release(body->world);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue