ephysics: change quaternion API to avoid many free calls
It was really annoying and error prone (easy to leak). SVN revision: 79299
This commit is contained in:
parent
8a7f663168
commit
52e0d54174
|
@ -118,14 +118,14 @@ _type_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
|
||||||
double mass, friction, restitution, lin_damping, ang_damping;
|
double mass, friction, restitution, lin_damping, ang_damping;
|
||||||
double lin_sleeping, ang_sleeping;
|
double lin_sleeping, ang_sleeping;
|
||||||
EPhysics_Body_Material material;
|
EPhysics_Body_Material material;
|
||||||
EPhysics_Quaternion *rotation;
|
EPhysics_Quaternion rotation;
|
||||||
Evas_Object *body_image;
|
Evas_Object *body_image;
|
||||||
EPhysics_World *world;
|
EPhysics_World *world;
|
||||||
Body_Data *bd = data;
|
Body_Data *bd = data;
|
||||||
EPhysics_Body *body = bd->body;
|
EPhysics_Body *body = bd->body;
|
||||||
|
|
||||||
mass = ephysics_body_mass_get(body);
|
mass = ephysics_body_mass_get(body);
|
||||||
rotation = ephysics_body_rotation_get(body);
|
ephysics_body_rotation_get(body, &rotation);
|
||||||
friction = ephysics_body_friction_get(body);
|
friction = ephysics_body_friction_get(body);
|
||||||
restitution = ephysics_body_restitution_get(body);
|
restitution = ephysics_body_restitution_get(body);
|
||||||
ephysics_body_damping_get(body, &lin_damping, &ang_damping);
|
ephysics_body_damping_get(body, &lin_damping, &ang_damping);
|
||||||
|
@ -152,7 +152,7 @@ _type_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
|
||||||
|
|
||||||
ephysics_body_evas_object_set(body, body_image, EINA_TRUE);
|
ephysics_body_evas_object_set(body, body_image, EINA_TRUE);
|
||||||
ephysics_body_mass_set(body, mass);
|
ephysics_body_mass_set(body, mass);
|
||||||
ephysics_body_rotation_set(body, rotation);
|
ephysics_body_rotation_set(body, &rotation);
|
||||||
ephysics_body_friction_set(body, friction);
|
ephysics_body_friction_set(body, friction);
|
||||||
ephysics_body_restitution_set(body, restitution);
|
ephysics_body_restitution_set(body, restitution);
|
||||||
ephysics_body_damping_set(body, lin_damping, ang_damping);
|
ephysics_body_damping_set(body, lin_damping, ang_damping);
|
||||||
|
@ -168,7 +168,6 @@ _type_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
|
||||||
elm_slider_value_get(bd->controls.force.torque));
|
elm_slider_value_get(bd->controls.force.torque));
|
||||||
|
|
||||||
bd->body = body;
|
bd->body = body;
|
||||||
free(rotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -229,13 +228,10 @@ _density_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
|
||||||
static void
|
static void
|
||||||
_rotation_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
|
_rotation_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
|
||||||
{
|
{
|
||||||
EPhysics_Quaternion *quat;
|
EPhysics_Quaternion quat;
|
||||||
Body_Data *bd = data;
|
Body_Data *bd = data;
|
||||||
|
ephysics_quaternion_euler_set(&quat, 0, 0, elm_slider_value_get(obj));
|
||||||
quat = ephysics_quaternion_new(0, 0, 0, 0);
|
ephysics_body_rotation_set(bd->body, &quat);
|
||||||
ephysics_quaternion_euler_set(quat, 0, 0, elm_slider_value_get(obj));
|
|
||||||
ephysics_body_rotation_set(bd->body, quat);
|
|
||||||
free(quat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -7,18 +7,14 @@
|
||||||
static void
|
static void
|
||||||
_pos_print_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
|
_pos_print_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
|
||||||
{
|
{
|
||||||
EPhysics_Quaternion *quat;
|
EPhysics_Quaternion quat;
|
||||||
double rx, ry, rz, rw;
|
|
||||||
Evas_Coord x, y, z;
|
Evas_Coord x, y, z;
|
||||||
|
|
||||||
ephysics_body_geometry_get(body, &x, &y, &z, NULL, NULL, NULL);
|
ephysics_body_geometry_get(body, &x, &y, &z, NULL, NULL, NULL);
|
||||||
|
ephysics_body_rotation_get(body, &quat);
|
||||||
quat = ephysics_body_rotation_get(body);
|
|
||||||
ephysics_quaternion_get(quat, &rx, &ry, &rz, &rw);
|
|
||||||
free(quat);
|
|
||||||
|
|
||||||
printf("Position X:%i Y:%i Z:%i\n", x, y, z);
|
printf("Position X:%i Y:%i Z:%i\n", x, y, z);
|
||||||
printf("Rotation X:%lf Y:%lf Z:%lf W:%lf\n", rx, ry, rz, rw);
|
printf("Rotation X:%lf Y:%lf Z:%lf W:%lf\n", quat.x, quat.y, quat.z, quat.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
static void
|
static void
|
||||||
_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
|
_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
|
||||||
{
|
{
|
||||||
EPhysics_Quaternion *quat_prev, *quat_delta, *quat;
|
EPhysics_Quaternion quat_prev, quat_delta, quat;
|
||||||
Evas_Event_Mouse_Move *mmove = event_info;
|
Evas_Event_Mouse_Move *mmove = event_info;
|
||||||
EPhysics_Body *body = data;
|
EPhysics_Body *body = data;
|
||||||
double rx, ry;
|
double rx, ry;
|
||||||
|
@ -19,15 +19,10 @@ _mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void
|
||||||
rx = mmove->cur.output.y - mmove->prev.output.y;
|
rx = mmove->cur.output.y - mmove->prev.output.y;
|
||||||
ry = mmove->cur.output.x - mmove->prev.output.x;
|
ry = mmove->cur.output.x - mmove->prev.output.x;
|
||||||
|
|
||||||
quat_prev = ephysics_body_rotation_get(body);
|
ephysics_body_rotation_get(body, &quat_prev);
|
||||||
quat_delta = ephysics_quaternion_new(0, 0, 0, 0);
|
ephysics_quaternion_euler_set(&quat_delta, -ry * 0.06, - rx * 0.04, 0);
|
||||||
ephysics_quaternion_euler_set(quat_delta, -ry * 0.06, - rx * 0.04, 0);
|
ephysics_quaternion_multiply(&quat_prev, &quat_delta, &quat);
|
||||||
quat = ephysics_quaternion_multiply(quat_prev, quat_delta);
|
ephysics_body_rotation_set(body, &quat);
|
||||||
ephysics_body_rotation_set(body, quat);
|
|
||||||
|
|
||||||
free(quat_prev);
|
|
||||||
free(quat_delta);
|
|
||||||
free(quat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -7,19 +7,15 @@
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_rotate_cb(void *data)
|
_rotate_cb(void *data)
|
||||||
{
|
{
|
||||||
EPhysics_Quaternion *quat_prev, *quat_delta, *quat;
|
EPhysics_Quaternion *quat_prev, quat_delta, quat;
|
||||||
EPhysics_Body *body = data;
|
EPhysics_Body *body = data;
|
||||||
|
|
||||||
quat_prev = ephysics_body_rotation_get(body);
|
quat_prev = ephysics_body_rotation_get(body, NULL);
|
||||||
quat_delta = ephysics_quaternion_new(0, 0, -0.15, 0.98);
|
ephysics_quaternion_set(&quat_delta, 0, 0, -0.15, 0.98);
|
||||||
ephysics_quaternion_normalize(quat_delta);
|
ephysics_quaternion_normalize(&quat_delta);
|
||||||
quat = ephysics_quaternion_multiply(quat_delta, quat_prev);
|
ephysics_body_rotation_set(
|
||||||
|
body, ephysics_quaternion_multiply(&quat_delta, quat_prev, &quat));
|
||||||
ephysics_body_rotation_set(body, quat);
|
|
||||||
|
|
||||||
free(quat_prev);
|
free(quat_prev);
|
||||||
free(quat_delta);
|
|
||||||
free(quat);
|
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -74,14 +70,13 @@ static void
|
||||||
_update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
|
_update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
|
||||||
{
|
{
|
||||||
double rx, ry, rz, rw, vrot, torque;
|
double rx, ry, rz, rw, vrot, torque;
|
||||||
EPhysics_Quaternion *quat;
|
EPhysics_Quaternion quat;
|
||||||
|
|
||||||
ephysics_body_angular_velocity_get(body, NULL, NULL, &vrot);
|
ephysics_body_angular_velocity_get(body, NULL, NULL, &vrot);
|
||||||
ephysics_body_torques_get(body, NULL, NULL, &torque);
|
ephysics_body_torques_get(body, NULL, NULL, &torque);
|
||||||
|
|
||||||
quat = ephysics_body_rotation_get(body);
|
ephysics_body_rotation_get(body, &quat);
|
||||||
ephysics_quaternion_get(quat, &rx, &ry, &rz, &rw);
|
ephysics_quaternion_get(&quat, &rx, &ry, &rz, &rw);
|
||||||
free(quat);
|
|
||||||
|
|
||||||
ephysics_body_evas_object_update(body);
|
ephysics_body_evas_object_update(body);
|
||||||
|
|
||||||
|
|
|
@ -157,20 +157,30 @@ EAPI int ephysics_shutdown(void);
|
||||||
*/
|
*/
|
||||||
typedef struct _EPhysics_Quaternion EPhysics_Quaternion;
|
typedef struct _EPhysics_Quaternion EPhysics_Quaternion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @struct _EPhysics_Quaternion
|
||||||
|
*
|
||||||
|
* Quaternion coordinates and rotation (w, x, y, z)
|
||||||
|
*/
|
||||||
|
struct _EPhysics_Quaternion
|
||||||
|
{
|
||||||
|
double w; /**< rotation */
|
||||||
|
double x; /**< x coordinate */
|
||||||
|
double y; /**< y coordinate */
|
||||||
|
double z; /**< z coordinate */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* Create a new quaternion.
|
* Create a new quaternion.
|
||||||
*
|
*
|
||||||
* @note It should be deleted with free() after usage is concluded.
|
* By default a quaternion is created as identity (w = 1, x = 0, y = 0, z = 0).
|
||||||
*
|
|
||||||
* This values can be modified later by quaternion operations or set directly.
|
* This values can be modified later by quaternion operations or set directly.
|
||||||
*
|
*
|
||||||
* @param x The x coordinate.
|
|
||||||
* @param y The y coordinate.
|
|
||||||
* @param z The z coordinate.
|
|
||||||
* @param w The rotation.
|
|
||||||
* @return The created quaternion or @c NULL on error.
|
* @return The created quaternion or @c NULL on error.
|
||||||
*
|
*
|
||||||
|
* @note It should be deleted with free() after usage is concluded.
|
||||||
|
*
|
||||||
* @see ephysics_quaternion_set();
|
* @see ephysics_quaternion_set();
|
||||||
* @see ephysics_quaternion_axis_angle_set();
|
* @see ephysics_quaternion_axis_angle_set();
|
||||||
* @see ephysics_quaternion_euler_set();
|
* @see ephysics_quaternion_euler_set();
|
||||||
|
@ -179,7 +189,7 @@ typedef struct _EPhysics_Quaternion EPhysics_Quaternion;
|
||||||
*
|
*
|
||||||
* @ingroup EPhysics_Quaternion
|
* @ingroup EPhysics_Quaternion
|
||||||
*/
|
*/
|
||||||
EAPI EPhysics_Quaternion *ephysics_quaternion_new(double x, double y, double z, double w);
|
EAPI EPhysics_Quaternion *ephysics_quaternion_new(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
@ -325,13 +335,13 @@ EAPI void ephysics_quaternion_inverse_scale(EPhysics_Quaternion *quat, double sc
|
||||||
*
|
*
|
||||||
* @param quat1 First quaternion to sum.
|
* @param quat1 First quaternion to sum.
|
||||||
* @param quat2 Second quaternion to sum.
|
* @param quat2 Second quaternion to sum.
|
||||||
|
* @param result Quaternion used to store the result. If it's @c NULL, a new
|
||||||
|
* quaternion will be allocated (and should be freed after usage).
|
||||||
* @return The sum quaternion or @c NULL on error.
|
* @return The sum quaternion or @c NULL on error.
|
||||||
*
|
*
|
||||||
* @note It should be freed after usage.
|
|
||||||
*
|
|
||||||
* @ingroup EPhysics_Quaternion
|
* @ingroup EPhysics_Quaternion
|
||||||
*/
|
*/
|
||||||
EAPI EPhysics_Quaternion *ephysics_quaternion_sum(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2);
|
EAPI EPhysics_Quaternion *ephysics_quaternion_sum(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
@ -339,13 +349,13 @@ EAPI EPhysics_Quaternion *ephysics_quaternion_sum(const EPhysics_Quaternion *qua
|
||||||
*
|
*
|
||||||
* @param quat1 First quaternion.
|
* @param quat1 First quaternion.
|
||||||
* @param quat2 Second quaternion.
|
* @param quat2 Second quaternion.
|
||||||
|
* @param result Quaternion used to store the result. If it's @c NULL, a new
|
||||||
|
* quaternion will be allocated (and should be freed after usage).
|
||||||
* @return The difference between @p quat1 and @p quat2, or @c NULL on error.
|
* @return The difference between @p quat1 and @p quat2, or @c NULL on error.
|
||||||
*
|
*
|
||||||
* @note It should be freed after usage.
|
|
||||||
*
|
|
||||||
* @ingroup EPhysics_Quaternion
|
* @ingroup EPhysics_Quaternion
|
||||||
*/
|
*/
|
||||||
EAPI EPhysics_Quaternion *ephysics_quaternion_diff(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2);
|
EAPI EPhysics_Quaternion *ephysics_quaternion_diff(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
@ -353,14 +363,14 @@ EAPI EPhysics_Quaternion *ephysics_quaternion_diff(const EPhysics_Quaternion *qu
|
||||||
*
|
*
|
||||||
* @param quat1 First quaternion.
|
* @param quat1 First quaternion.
|
||||||
* @param quat2 Second quaternion.
|
* @param quat2 Second quaternion.
|
||||||
|
* @param result Quaternion used to store the result. If it's @c NULL, a new
|
||||||
|
* quaternion will be allocated (and should be freed after usage).
|
||||||
* @return The @p quat1 multiplied by @p quat2 on the right, or @c NULL
|
* @return The @p quat1 multiplied by @p quat2 on the right, or @c NULL
|
||||||
* on error.
|
* on error.
|
||||||
*
|
*
|
||||||
* @note It should be freed after usage.
|
|
||||||
*
|
|
||||||
* @ingroup EPhysics_Quaternion
|
* @ingroup EPhysics_Quaternion
|
||||||
*/
|
*/
|
||||||
EAPI EPhysics_Quaternion *ephysics_quaternion_multiply(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2);
|
EAPI EPhysics_Quaternion *ephysics_quaternion_multiply(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
@ -374,14 +384,14 @@ EAPI EPhysics_Quaternion *ephysics_quaternion_multiply(const EPhysics_Quaternion
|
||||||
* @param ratio The ratio between @p quat1 and @p quat2 to interpolate. If
|
* @param ratio The ratio between @p quat1 and @p quat2 to interpolate. If
|
||||||
* @p ratio = 0, the result is @p quat1, if @p ratio = 1, the result is
|
* @p ratio = 0, the result is @p quat1, if @p ratio = 1, the result is
|
||||||
* @p quat2.
|
* @p quat2.
|
||||||
|
* @param result Quaternion used to store the result. If it's @c NULL, a new
|
||||||
|
* quaternion will be allocated (and should be freed after usage).
|
||||||
* @return The result of slerp between @p quat1 and @p quat2, or @c NULL
|
* @return The result of slerp between @p quat1 and @p quat2, or @c NULL
|
||||||
* on error.
|
* on error.
|
||||||
*
|
*
|
||||||
* @note It should be freed after usage.
|
|
||||||
*
|
|
||||||
* @ingroup EPhysics_Quaternion
|
* @ingroup EPhysics_Quaternion
|
||||||
*/
|
*/
|
||||||
EAPI EPhysics_Quaternion *ephysics_quaternion_slerp(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, double ratio);
|
EAPI EPhysics_Quaternion *ephysics_quaternion_slerp(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, double ratio, EPhysics_Quaternion *result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
@ -3738,18 +3748,19 @@ EAPI void ephysics_body_linear_movement_enable_get(const EPhysics_Body *body, Ei
|
||||||
* @brief
|
* @brief
|
||||||
* Get body's rotation quaternion.
|
* Get body's rotation quaternion.
|
||||||
*
|
*
|
||||||
* By default rotation is 0 degree on all axes.
|
* By default rotation is 0 degree on all axes (1, 0, 0, 0).
|
||||||
*
|
*
|
||||||
* @param body The physics body.
|
* @param body The physics body.
|
||||||
* @return A quaternion or @c NULL on error. It should be freed with free()
|
* @param rotation Quaternion used to store the result. If it's @c NULL, a new
|
||||||
* after usage.
|
* quaternion will be allocated (and should be freed after usage).
|
||||||
|
* @return A quaternion or @c NULL on error.
|
||||||
*
|
*
|
||||||
* @see ephysics_body_rotation_set()
|
* @see ephysics_body_rotation_set()
|
||||||
* @see ephysics_quaternion_get()
|
* @see ephysics_quaternion_get()
|
||||||
*
|
*
|
||||||
* @ingroup EPhysics_Body
|
* @ingroup EPhysics_Body
|
||||||
*/
|
*/
|
||||||
EAPI EPhysics_Quaternion *ephysics_body_rotation_get(const EPhysics_Body *body);
|
EAPI EPhysics_Quaternion *ephysics_body_rotation_get(const EPhysics_Body *body, EPhysics_Quaternion *rotation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
|
@ -3268,7 +3268,7 @@ ephysics_body_angular_movement_enable_get(const EPhysics_Body *body, Eina_Bool *
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI EPhysics_Quaternion *
|
EAPI EPhysics_Quaternion *
|
||||||
ephysics_body_rotation_get(const EPhysics_Body *body)
|
ephysics_body_rotation_get(const EPhysics_Body *body, EPhysics_Quaternion *rotation)
|
||||||
{
|
{
|
||||||
EPhysics_Quaternion *quat;
|
EPhysics_Quaternion *quat;
|
||||||
btTransform trans;
|
btTransform trans;
|
||||||
|
@ -3279,11 +3279,20 @@ ephysics_body_rotation_get(const EPhysics_Body *body)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!rotation)
|
||||||
|
{
|
||||||
|
quat = ephysics_quaternion_new();
|
||||||
|
if (!quat) return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
quat = rotation;
|
||||||
|
|
||||||
trans = _ephysics_body_transform_get(body);
|
trans = _ephysics_body_transform_get(body);
|
||||||
quat = ephysics_quaternion_new(trans.getRotation().x(),
|
quat->x = trans.getRotation().x();
|
||||||
trans.getRotation().y(),
|
quat->y = trans.getRotation().y();
|
||||||
trans.getRotation().z(),
|
quat->z = trans.getRotation().z();
|
||||||
trans.getRotation().getW());
|
quat->w = trans.getRotation().getW();
|
||||||
|
|
||||||
return quat;
|
return quat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct _EPhysics_Quaternion {
|
|
||||||
double x;
|
|
||||||
double y;
|
|
||||||
double z;
|
|
||||||
double w;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ephysics_quaternion_update(EPhysics_Quaternion *quat, btQuaternion *bt_quat)
|
_ephysics_quaternion_update(EPhysics_Quaternion *quat, btQuaternion *bt_quat)
|
||||||
{
|
{
|
||||||
|
@ -24,8 +17,23 @@ _ephysics_quaternion_update(EPhysics_Quaternion *quat, btQuaternion *bt_quat)
|
||||||
quat->w = bt_quat->getW();
|
quat->w = bt_quat->getW();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EPhysics_Quaternion *
|
||||||
|
_ephysics_quaternion_params_check(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result)
|
||||||
|
{
|
||||||
|
if ((!quat1) || (!quat2))
|
||||||
|
{
|
||||||
|
ERR("Can't operate over null quaternions.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return ephysics_quaternion_new();
|
||||||
|
}
|
||||||
|
|
||||||
EAPI EPhysics_Quaternion *
|
EAPI EPhysics_Quaternion *
|
||||||
ephysics_quaternion_new(double x, double y, double z, double w)
|
ephysics_quaternion_new(void)
|
||||||
{
|
{
|
||||||
EPhysics_Quaternion *quat;
|
EPhysics_Quaternion *quat;
|
||||||
|
|
||||||
|
@ -37,11 +45,7 @@ ephysics_quaternion_new(double x, double y, double z, double w)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
quat->x = x;
|
quat->w = 1;
|
||||||
quat->y = y;
|
|
||||||
quat->z = z;
|
|
||||||
quat->w = w;
|
|
||||||
|
|
||||||
return quat;
|
return quat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,79 +196,71 @@ ephysics_quaternion_inverse_scale(EPhysics_Quaternion *quat, double scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI EPhysics_Quaternion *
|
EAPI EPhysics_Quaternion *
|
||||||
ephysics_quaternion_sum(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2)
|
ephysics_quaternion_sum(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result)
|
||||||
{
|
{
|
||||||
btQuaternion bt_quat1, bt_quat2, bt_quat;
|
btQuaternion bt_quat1, bt_quat2, bt_quat;
|
||||||
|
EPhysics_Quaternion *quat;
|
||||||
|
|
||||||
if ((!quat1) || (!quat2))
|
quat = _ephysics_quaternion_params_check(quat1, quat2, result);
|
||||||
{
|
if (!quat) return NULL;
|
||||||
ERR("Can't operate over null quaternions.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_quat1 = btQuaternion(quat1->x, quat1->y, quat1->z, quat1->w);
|
bt_quat1 = btQuaternion(quat1->x, quat1->y, quat1->z, quat1->w);
|
||||||
bt_quat2 = btQuaternion(quat2->x, quat2->y, quat2->z, quat2->w);
|
bt_quat2 = btQuaternion(quat2->x, quat2->y, quat2->z, quat2->w);
|
||||||
bt_quat = bt_quat1 + bt_quat2;
|
bt_quat = bt_quat1 + bt_quat2;
|
||||||
|
|
||||||
return ephysics_quaternion_new(bt_quat.x(), bt_quat.y(), bt_quat.z(),
|
_ephysics_quaternion_update(quat, &bt_quat);
|
||||||
bt_quat.getW());
|
return quat;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI EPhysics_Quaternion *
|
EAPI EPhysics_Quaternion *
|
||||||
ephysics_quaternion_diff(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2)
|
ephysics_quaternion_diff(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result)
|
||||||
{
|
{
|
||||||
btQuaternion bt_quat1, bt_quat2, bt_quat;
|
btQuaternion bt_quat1, bt_quat2, bt_quat;
|
||||||
|
EPhysics_Quaternion *quat;
|
||||||
|
|
||||||
if ((!quat1) || (!quat2))
|
quat = _ephysics_quaternion_params_check(quat1, quat2, result);
|
||||||
{
|
if (!quat) return NULL;
|
||||||
ERR("Can't operate over null quaternions.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_quat1 = btQuaternion(quat1->x, quat1->y, quat1->z, quat1->w);
|
bt_quat1 = btQuaternion(quat1->x, quat1->y, quat1->z, quat1->w);
|
||||||
bt_quat2 = btQuaternion(quat2->x, quat2->y, quat2->z, quat2->w);
|
bt_quat2 = btQuaternion(quat2->x, quat2->y, quat2->z, quat2->w);
|
||||||
bt_quat = bt_quat1 - bt_quat2;
|
bt_quat = bt_quat1 - bt_quat2;
|
||||||
|
|
||||||
return ephysics_quaternion_new(bt_quat.x(), bt_quat.y(), bt_quat.z(),
|
_ephysics_quaternion_update(quat, &bt_quat);
|
||||||
bt_quat.getW());
|
return quat;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI EPhysics_Quaternion *
|
EAPI EPhysics_Quaternion *
|
||||||
ephysics_quaternion_multiply(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2)
|
ephysics_quaternion_multiply(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result)
|
||||||
{
|
{
|
||||||
btQuaternion bt_quat1, bt_quat2, bt_quat;
|
btQuaternion bt_quat1, bt_quat2, bt_quat;
|
||||||
|
EPhysics_Quaternion *quat;
|
||||||
|
|
||||||
if ((!quat1) || (!quat2))
|
quat = _ephysics_quaternion_params_check(quat1, quat2, result);
|
||||||
{
|
if (!quat) return NULL;
|
||||||
ERR("Can't operate over null quaternions.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_quat1 = btQuaternion(quat1->x, quat1->y, quat1->z, quat1->w);
|
bt_quat1 = btQuaternion(quat1->x, quat1->y, quat1->z, quat1->w);
|
||||||
bt_quat2 = btQuaternion(quat2->x, quat2->y, quat2->z, quat2->w);
|
bt_quat2 = btQuaternion(quat2->x, quat2->y, quat2->z, quat2->w);
|
||||||
bt_quat = bt_quat1 * bt_quat2;
|
bt_quat = bt_quat1 * bt_quat2;
|
||||||
|
|
||||||
return ephysics_quaternion_new(bt_quat.x(), bt_quat.y(), bt_quat.z(),
|
_ephysics_quaternion_update(quat, &bt_quat);
|
||||||
bt_quat.getW());
|
return quat;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI EPhysics_Quaternion *
|
EAPI EPhysics_Quaternion *
|
||||||
ephysics_quaternion_slerp(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, double ratio)
|
ephysics_quaternion_slerp(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, double ratio, EPhysics_Quaternion *result)
|
||||||
{
|
{
|
||||||
btQuaternion bt_quat1, bt_quat2;
|
btQuaternion bt_quat1, bt_quat2;
|
||||||
|
EPhysics_Quaternion *quat;
|
||||||
|
|
||||||
if ((!quat1) || (!quat2))
|
quat = _ephysics_quaternion_params_check(quat1, quat2, result);
|
||||||
{
|
if (!quat) return NULL;
|
||||||
ERR("Can't operate over null quaternions.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_quat1 = btQuaternion(quat1->x, quat1->y, quat1->z, quat1->w);
|
bt_quat1 = btQuaternion(quat1->x, quat1->y, quat1->z, quat1->w);
|
||||||
bt_quat2 = btQuaternion(quat2->x, quat2->y, quat2->z, quat2->w);
|
bt_quat2 = btQuaternion(quat2->x, quat2->y, quat2->z, quat2->w);
|
||||||
bt_quat1.slerp(bt_quat2, ratio);
|
bt_quat1.slerp(bt_quat2, ratio);
|
||||||
|
|
||||||
return ephysics_quaternion_new(bt_quat1.x(), bt_quat1.y(), bt_quat1.z(),
|
_ephysics_quaternion_update(quat, &bt_quat1);
|
||||||
bt_quat1.getW());
|
return quat;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI double
|
EAPI double
|
||||||
|
|
Loading…
Reference in New Issue