Implement QuatExp and fix up QuatBlend's param names.

This commit is contained in:
Bill Currie 2012-01-12 21:22:06 +09:00
parent ba1b819173
commit cbd13ac54e
2 changed files with 23 additions and 6 deletions

View file

@ -267,12 +267,12 @@ extern const vec_t *const quat_origin;
(e)[3] = d; \
} while (0)
#define QuatBlend(v1,v2,b,v) \
#define QuatBlend(q1,q2,b,q) \
do { \
(v)[0] = (v1)[0] * (1 - (b)) + (v2)[0] * (b); \
(v)[1] = (v1)[1] * (1 - (b)) + (v2)[1] * (b); \
(v)[2] = (v1)[2] * (1 - (b)) + (v2)[2] * (b); \
(v)[3] = (v1)[3] * (1 - (b)) + (v2)[3] * (b); \
(q)[0] = (q1)[0] * (1 - (b)) + (q2)[0] * (b); \
(q)[1] = (q1)[1] * (1 - (b)) + (q2)[1] * (b); \
(q)[2] = (q1)[2] * (1 - (b)) + (q2)[2] * (b); \
(q)[3] = (q1)[3] * (1 - (b)) + (q2)[3] * (b); \
} while (0)
//For printf etc
@ -415,7 +415,7 @@ void RotatePointAroundVector (vec3_t dst, const vec3_t axis,
void QuatMult (const quat_t q1, const quat_t q2, quat_t out);
void QuatInverse (const quat_t in, quat_t out);
void QuatExp (const quat_t a, quat_t b);
void QuatToMatrix (const quat_t q, vec_t *m, int homogenous, int vertical);
void Mat4Transpose (const mat4_t a, mat4_t b);

View file

@ -195,6 +195,23 @@ QuatInverse (const quat_t in, quat_t out)
QuatScale (q, 1 / m, out);
}
VISIBLE void
QuatExp (const quat_t a, quat_t b)
{
vec3_t n;
vec_t th;
vec_t r;
vec_t c, s;
VectorCopy (a + 1, n);
th = VectorNormalize (n);
r = expf (a[0]);
c = cosf (th);
s = sinf (th);
VectorScale (n, r * s, b + 1);
b[0] = r * c;
}
VISIBLE void
QuatToMatrix (const quat_t q, vec_t *m, int homogenous, int vertical)
{