summaryrefslogtreecommitdiff
path: root/legacy/ephysics/src/lib/EPhysics.h
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-11-14 20:01:20 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-11-14 20:01:20 +0000
commit52e0d5417466418af18254cf40a2099dc5c6e2f0 (patch)
tree12de11baf8744763656d2e58366823d7bd1bfc92 /legacy/ephysics/src/lib/EPhysics.h
parent8a7f6631687d9ee9d01c2f6eec33580e9384c20d (diff)
ephysics: change quaternion API to avoid many free calls
It was really annoying and error prone (easy to leak). SVN revision: 79299
Diffstat (limited to '')
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h57
1 files changed, 34 insertions, 23 deletions
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index 5a9279693a..04179df1ad 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -158,19 +158,29 @@ EAPI int ephysics_shutdown(void);
158typedef struct _EPhysics_Quaternion EPhysics_Quaternion; 158typedef struct _EPhysics_Quaternion EPhysics_Quaternion;
159 159
160/** 160/**
161 * @struct _EPhysics_Quaternion
162 *
163 * Quaternion coordinates and rotation (w, x, y, z)
164 */
165struct _EPhysics_Quaternion
166{
167 double w; /**< rotation */
168 double x; /**< x coordinate */
169 double y; /**< y coordinate */
170 double z; /**< z coordinate */
171};
172
173/**
161 * @brief 174 * @brief
162 * Create a new quaternion. 175 * Create a new quaternion.
163 * 176 *
164 * @note It should be deleted with free() after usage is concluded. 177 * By default a quaternion is created as identity (w = 1, x = 0, y = 0, z = 0).
165 *
166 * This values can be modified later by quaternion operations or set directly. 178 * This values can be modified later by quaternion operations or set directly.
167 * 179 *
168 * @param x The x coordinate.
169 * @param y The y coordinate.
170 * @param z The z coordinate.
171 * @param w The rotation.
172 * @return The created quaternion or @c NULL on error. 180 * @return The created quaternion or @c NULL on error.
173 * 181 *
182 * @note It should be deleted with free() after usage is concluded.
183 *
174 * @see ephysics_quaternion_set(); 184 * @see ephysics_quaternion_set();
175 * @see ephysics_quaternion_axis_angle_set(); 185 * @see ephysics_quaternion_axis_angle_set();
176 * @see ephysics_quaternion_euler_set(); 186 * @see ephysics_quaternion_euler_set();
@@ -179,7 +189,7 @@ typedef struct _EPhysics_Quaternion EPhysics_Quaternion;
179 * 189 *
180 * @ingroup EPhysics_Quaternion 190 * @ingroup EPhysics_Quaternion
181 */ 191 */
182EAPI EPhysics_Quaternion *ephysics_quaternion_new(double x, double y, double z, double w); 192EAPI EPhysics_Quaternion *ephysics_quaternion_new(void);
183 193
184/** 194/**
185 * @brief 195 * @brief
@@ -325,13 +335,13 @@ EAPI void ephysics_quaternion_inverse_scale(EPhysics_Quaternion *quat, double sc
325 * 335 *
326 * @param quat1 First quaternion to sum. 336 * @param quat1 First quaternion to sum.
327 * @param quat2 Second quaternion to sum. 337 * @param quat2 Second quaternion to sum.
338 * @param result Quaternion used to store the result. If it's @c NULL, a new
339 * quaternion will be allocated (and should be freed after usage).
328 * @return The sum quaternion or @c NULL on error. 340 * @return The sum quaternion or @c NULL on error.
329 * 341 *
330 * @note It should be freed after usage.
331 *
332 * @ingroup EPhysics_Quaternion 342 * @ingroup EPhysics_Quaternion
333 */ 343 */
334EAPI EPhysics_Quaternion *ephysics_quaternion_sum(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2); 344EAPI EPhysics_Quaternion *ephysics_quaternion_sum(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result);
335 345
336/** 346/**
337 * @brief 347 * @brief
@@ -339,13 +349,13 @@ EAPI EPhysics_Quaternion *ephysics_quaternion_sum(const EPhysics_Quaternion *qua
339 * 349 *
340 * @param quat1 First quaternion. 350 * @param quat1 First quaternion.
341 * @param quat2 Second quaternion. 351 * @param quat2 Second quaternion.
352 * @param result Quaternion used to store the result. If it's @c NULL, a new
353 * quaternion will be allocated (and should be freed after usage).
342 * @return The difference between @p quat1 and @p quat2, or @c NULL on error. 354 * @return The difference between @p quat1 and @p quat2, or @c NULL on error.
343 * 355 *
344 * @note It should be freed after usage.
345 *
346 * @ingroup EPhysics_Quaternion 356 * @ingroup EPhysics_Quaternion
347 */ 357 */
348EAPI EPhysics_Quaternion *ephysics_quaternion_diff(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2); 358EAPI EPhysics_Quaternion *ephysics_quaternion_diff(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result);
349 359
350/** 360/**
351 * @brief 361 * @brief
@@ -353,14 +363,14 @@ EAPI EPhysics_Quaternion *ephysics_quaternion_diff(const EPhysics_Quaternion *qu
353 * 363 *
354 * @param quat1 First quaternion. 364 * @param quat1 First quaternion.
355 * @param quat2 Second quaternion. 365 * @param quat2 Second quaternion.
366 * @param result Quaternion used to store the result. If it's @c NULL, a new
367 * quaternion will be allocated (and should be freed after usage).
356 * @return The @p quat1 multiplied by @p quat2 on the right, or @c NULL 368 * @return The @p quat1 multiplied by @p quat2 on the right, or @c NULL
357 * on error. 369 * on error.
358 * 370 *
359 * @note It should be freed after usage.
360 *
361 * @ingroup EPhysics_Quaternion 371 * @ingroup EPhysics_Quaternion
362 */ 372 */
363EAPI EPhysics_Quaternion *ephysics_quaternion_multiply(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2); 373EAPI EPhysics_Quaternion *ephysics_quaternion_multiply(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result);
364 374
365/** 375/**
366 * @brief 376 * @brief
@@ -374,14 +384,14 @@ EAPI EPhysics_Quaternion *ephysics_quaternion_multiply(const EPhysics_Quaternion
374 * @param ratio The ratio between @p quat1 and @p quat2 to interpolate. If 384 * @param ratio The ratio between @p quat1 and @p quat2 to interpolate. If
375 * @p ratio = 0, the result is @p quat1, if @p ratio = 1, the result is 385 * @p ratio = 0, the result is @p quat1, if @p ratio = 1, the result is
376 * @p quat2. 386 * @p quat2.
387 * @param result Quaternion used to store the result. If it's @c NULL, a new
388 * quaternion will be allocated (and should be freed after usage).
377 * @return The result of slerp between @p quat1 and @p quat2, or @c NULL 389 * @return The result of slerp between @p quat1 and @p quat2, or @c NULL
378 * on error. 390 * on error.
379 * 391 *
380 * @note It should be freed after usage.
381 *
382 * @ingroup EPhysics_Quaternion 392 * @ingroup EPhysics_Quaternion
383 */ 393 */
384EAPI EPhysics_Quaternion *ephysics_quaternion_slerp(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, double ratio); 394EAPI EPhysics_Quaternion *ephysics_quaternion_slerp(const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, double ratio, EPhysics_Quaternion *result);
385 395
386/** 396/**
387 * @brief 397 * @brief
@@ -3738,18 +3748,19 @@ EAPI void ephysics_body_linear_movement_enable_get(const EPhysics_Body *body, Ei
3738 * @brief 3748 * @brief
3739 * Get body's rotation quaternion. 3749 * Get body's rotation quaternion.
3740 * 3750 *
3741 * By default rotation is 0 degree on all axes. 3751 * By default rotation is 0 degree on all axes (1, 0, 0, 0).
3742 * 3752 *
3743 * @param body The physics body. 3753 * @param body The physics body.
3744 * @return A quaternion or @c NULL on error. It should be freed with free() 3754 * @param rotation Quaternion used to store the result. If it's @c NULL, a new
3745 * after usage. 3755 * quaternion will be allocated (and should be freed after usage).
3756 * @return A quaternion or @c NULL on error.
3746 * 3757 *
3747 * @see ephysics_body_rotation_set() 3758 * @see ephysics_body_rotation_set()
3748 * @see ephysics_quaternion_get() 3759 * @see ephysics_quaternion_get()
3749 * 3760 *
3750 * @ingroup EPhysics_Body 3761 * @ingroup EPhysics_Body
3751 */ 3762 */
3752EAPI EPhysics_Quaternion *ephysics_body_rotation_get(const EPhysics_Body *body); 3763EAPI EPhysics_Quaternion *ephysics_body_rotation_get(const EPhysics_Body *body, EPhysics_Quaternion *rotation);
3753 3764
3754/** 3765/**
3755 * @brief 3766 * @brief