Make Mat4Decompose a little more intuitive.

Params are now in application order (good thing not much code uses it yet).
This commit is contained in:
Bill Currie 2012-05-10 13:04:50 +09:00
parent 1473dbd526
commit fa6270322f
3 changed files with 17 additions and 7 deletions

View file

@ -611,8 +611,18 @@ void Mat4Init (const quat_t rot, const vec3_t scale, const vec3_t trans,
void Mat4Transpose (const mat4_t a, mat4_t b);
void Mat4Mult (const mat4_t a, const mat4_t b, mat4_t c);
void Mat4MultVec (const mat4_t a, const vec3_t b, vec3_t c);
// Column major matrix
int Mat4Decompose (const mat4_t m, quat_t rot, vec3_t scale, vec3_t shear,
/** Decompose a column major matrix into its component transformations.
This gives the matrix's rotation as a quaternion, shear, scale
(XY, XZ, YZ), and translation. Using the following sequence will give the
same result as multiplying \a v by \a mat.
QuatMultVec (rot, v, v);
VectorShear (shear, v, v);
VectorCompMult (scale, v, v);
VectorAdd (trans, v, v);
*/
int Mat4Decompose (const mat4_t mat, quat_t rot, vec3_t shear, vec3_t scale,
vec3_t trans);
#define BOX_ON_PLANE_SIDE(emins, emaxs, p) \

View file

@ -854,7 +854,7 @@ Mat4MultVec (const mat4_t a, const vec3_t b, vec3_t c)
}
int
Mat4Decompose (const mat4_t m, quat_t rot, vec3_t scale, vec3_t shear,
Mat4Decompose (const mat4_t mat, quat_t rot, vec3_t shear, vec3_t scale,
vec3_t trans)
{
vec3_t row[3], shr, scl;
@ -863,7 +863,7 @@ Mat4Decompose (const mat4_t m, quat_t rot, vec3_t scale, vec3_t shear,
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
row[j][i] = m[i * 4 + j];
row[j][i] = mat[i * 4 + j];
l = DotProduct (row[0], row[0]);
if (l < 1e-5)
@ -896,7 +896,7 @@ Mat4Decompose (const mat4_t m, quat_t rot, vec3_t scale, vec3_t shear,
if (shear)
VectorCopy (shr, shear);
if (trans)
VectorCopy (m + 12, trans);
VectorCopy (mat + 12, trans);
if (!rot)
return 1;

View file

@ -72,7 +72,7 @@ test_angle (const vec3_t angles)
AngleQuat (angles, rotation);
QuatToMatrix (rotation, mat, 1, 1);
Mat4Decompose (mat, r, scale, shear, trans);
Mat4Decompose (mat, r, shear, scale, trans);
for (i = 0; i < 4; i++)
if (!compare (rotation[i], r[i]))
goto negate;
@ -145,7 +145,7 @@ test_transform2 (const vec3_t angles, const vec3_t scale,
VectorAdd (translation, x, x);
Mat4Init (rotation, scale, translation, mat);
Mat4Decompose (mat, rot, sc, sh, tr);
Mat4Decompose (mat, rot, sh, sc, tr);
VectorCopy (v, y);
QuatMultVec (rot, y, y);