From 66b8ca8afcd5e061955d3bad60f2dcef42fce8d6 Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Mon, 15 Oct 2012 21:53:56 +0000 Subject: [PATCH] ephysics: implement rotation quartenion getter So it's possible to create a custom body update callback using it with evas_map_util_quat_rotate(). SVN revision: 78010 --- legacy/ephysics/src/lib/EPhysics.h | 21 ++++++++++++++++++++- legacy/ephysics/src/lib/ephysics_body.cpp | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index dc10eb38af..04cb54e1cd 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -2924,6 +2924,7 @@ EAPI void ephysics_body_linear_movement_enable_get(const EPhysics_Body *body, Ei * @param rot_z The amount of degrees @p body is rotated on z axis. * * @see ephysics_body_rotation_set() + * @see ephysics_body_rotation_quaternion_get() * * @ingroup EPhysics_Body */ @@ -2949,6 +2950,24 @@ EAPI void ephysics_body_rotation_get(const EPhysics_Body *body, double *rot_x, d */ EAPI void ephysics_body_rotation_set(EPhysics_Body *body, double rot_x, double rot_y, double rot_z); +/** + * @brief + * Get body's normalized rotation quaternion (x, y, z and w). + * + * @param body The physics body. + * @param x the x component of the imaginary part of the quaternion. + * @param y the y component of the imaginary part of the quaternion. + * @param z the z component of the imaginary part of the quaternion. + * @param w the w component of the real part of the quaternion. + * + * @see ephysics_body_rotation_set() + * @see ephysics_body_rotation_get() + * + * @ingroup EPhysics_Body + */ +EAPI void +ephysics_body_rotation_quaternion_get(const EPhysics_Body *body, double *x, double *y, double *z, double *w); + /** * @brief * Set data to @p body. @@ -3169,7 +3188,7 @@ EAPI void ephysics_body_forces_clear(EPhysics_Body *body); * * If a body of width = 30, height = 20 and depth = 20, and has the center of * mass at x component = 20, y component = 10 and z = 10, it will return - * @p x = 0.666, @p y = 0.5 and @z = 0.5. + * @p x = 0.666, @p y = 0.5 and @p z = 0.5. * * For primitive shapes, like box and circle, the center of mass * is (0.5, 0.5, 0.5). diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 67617be0ff..28e7d76993 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -2611,6 +2611,28 @@ ephysics_body_rotation_set(EPhysics_Body *body, double rot_x, double rot_y, doub ephysics_world_lock_release(body->world); } +EAPI void +ephysics_body_rotation_quaternion_get(const EPhysics_Body *body, double *x, double *y, double *z, double *w) +{ + btTransform trans; + btQuaternion quat; + + if (!body) + { + ERR("Can't get rotation, body is null."); + return; + } + + trans = _ephysics_body_transform_get(body); + quat = trans.getRotation(); + quat.normalize(); + + if (x) *x = quat.x(); + if (y) *y = quat.y(); + if (z) *z = quat.z(); + if (w) *w = -quat.w(); +} + EAPI void ephysics_body_data_set(EPhysics_Body *body, void *data) {