mirror of
https://github.com/ioquake/ioq3.git
synced 2025-06-02 18:01:34 +00:00
Bug 5199 - IQM joint matrices wrong, patch by James Canete
This commit is contained in:
parent
9124d26afb
commit
bc3e989967
1 changed files with 34 additions and 49 deletions
|
@ -92,30 +92,26 @@ static void JointToMatrix( vec4_t rot, vec3_t scale, vec3_t trans,
|
||||||
mat[10] = scale[2] * (1.0f - (xx + yy));
|
mat[10] = scale[2] * (1.0f - (xx + yy));
|
||||||
mat[11] = trans[2];
|
mat[11] = trans[2];
|
||||||
}
|
}
|
||||||
static void JointToMatrixInverse( vec4_t rot, vec3_t scale, vec3_t trans,
|
static void Matrix34Invert( float *inMat, float *outMat )
|
||||||
float *mat ) {
|
{
|
||||||
float xx = 2.0f * rot[0] * rot[0];
|
vec3_t trans;
|
||||||
float yy = 2.0f * rot[1] * rot[1];
|
float invSqrLen, *v;
|
||||||
float zz = 2.0f * rot[2] * rot[2];
|
|
||||||
float xy = 2.0f * rot[0] * rot[1];
|
|
||||||
float xz = 2.0f * rot[0] * rot[2];
|
|
||||||
float yz = 2.0f * rot[1] * rot[2];
|
|
||||||
float wx = 2.0f * rot[3] * rot[0];
|
|
||||||
float wy = 2.0f * rot[3] * rot[1];
|
|
||||||
float wz = 2.0f * rot[3] * rot[2];
|
|
||||||
|
|
||||||
mat[ 0] = scale[0] * (1.0f - (yy + zz));
|
outMat[ 0] = inMat[ 0]; outMat[ 1] = inMat[ 4]; outMat[ 2] = inMat[ 8];
|
||||||
mat[ 1] = scale[0] * (xy + wz);
|
outMat[ 4] = inMat[ 1]; outMat[ 5] = inMat[ 5]; outMat[ 6] = inMat[ 9];
|
||||||
mat[ 2] = scale[2] * (xz - wy);
|
outMat[ 8] = inMat[ 2]; outMat[ 9] = inMat[ 6]; outMat[10] = inMat[10];
|
||||||
mat[ 3] = -DotProduct((mat + 0), trans);
|
|
||||||
mat[ 4] = scale[0] * (xy - wz);
|
v = outMat + 0; invSqrLen = 1.0f / DotProduct(v, v); VectorScale(v, invSqrLen, v);
|
||||||
mat[ 5] = scale[1] * (1.0f - (xx + zz));
|
v = outMat + 4; invSqrLen = 1.0f / DotProduct(v, v); VectorScale(v, invSqrLen, v);
|
||||||
mat[ 6] = scale[2] * (yz + wx);
|
v = outMat + 8; invSqrLen = 1.0f / DotProduct(v, v); VectorScale(v, invSqrLen, v);
|
||||||
mat[ 7] = -DotProduct((mat + 4), trans);
|
|
||||||
mat[ 8] = scale[0] * (xz + wy);
|
trans[0] = inMat[ 3];
|
||||||
mat[ 9] = scale[1] * (yz - wx);
|
trans[1] = inMat[ 7];
|
||||||
mat[10] = scale[2] * (1.0f - (xx + yy));
|
trans[2] = inMat[11];
|
||||||
mat[11] = -DotProduct((mat + 8), trans);
|
|
||||||
|
outMat[ 3] = -DotProduct(outMat + 0, trans);
|
||||||
|
outMat[ 7] = -DotProduct(outMat + 4, trans);
|
||||||
|
outMat[11] = -DotProduct(outMat + 8, trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -473,36 +469,25 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na
|
||||||
mat = jointMats;
|
mat = jointMats;
|
||||||
joint = (iqmJoint_t *)((byte *)header + header->ofs_joints);
|
joint = (iqmJoint_t *)((byte *)header + header->ofs_joints);
|
||||||
for( i = 0; i < header->num_joints; i++, joint++ ) {
|
for( i = 0; i < header->num_joints; i++, joint++ ) {
|
||||||
float tmpMat[12];
|
float baseFrame[12], invBaseFrame[12];
|
||||||
|
|
||||||
JointToMatrix( joint->rotate, joint->scale, joint->translate,
|
JointToMatrix( joint->rotate, joint->scale, joint->translate, baseFrame );
|
||||||
tmpMat );
|
Matrix34Invert( baseFrame, invBaseFrame );
|
||||||
|
|
||||||
if( joint->parent >= 0 ) {
|
if ( joint->parent >= 0 )
|
||||||
// premultiply with parent-matrix
|
{
|
||||||
Matrix34Multiply( jointMats + 2 * 12 * joint->parent,
|
Matrix34Multiply( jointMats + 2 * 12 * joint->parent, baseFrame, mat );
|
||||||
tmpMat, mat);
|
mat += 12;
|
||||||
} else {
|
Matrix34Multiply( invBaseFrame, jointMats + 2 * 12 * joint->parent + 12, mat );
|
||||||
Com_Memcpy( mat, tmpMat, sizeof(tmpMat) );
|
mat += 12;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
mat += 12;
|
{
|
||||||
|
Com_Memcpy( mat, baseFrame, sizeof(baseFrame) );
|
||||||
// compute the inverse matrix by combining the
|
mat += 12;
|
||||||
// inverse scale, rotation and translation
|
Com_Memcpy( mat, invBaseFrame, sizeof(invBaseFrame) );
|
||||||
JointToMatrixInverse( joint->rotate, joint->scale,
|
mat += 12;
|
||||||
joint->translate, tmpMat );
|
|
||||||
|
|
||||||
if( joint->parent >= 0 ) {
|
|
||||||
// premultiply with inverse parent-matrix
|
|
||||||
Matrix34Multiply( tmpMat,
|
|
||||||
jointMats + 2 * 12 * joint->parent + 12,
|
|
||||||
mat);
|
|
||||||
} else {
|
|
||||||
Com_Memcpy( mat, tmpMat, sizeof(tmpMat) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mat += 12;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate pose matrices
|
// calculate pose matrices
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue