From: havoc Date: Thu, 29 Aug 2002 14:14:34 +0000 (+0000) Subject: fixed viewmodel (it wasn't drawing because it's matrix was empty), fixed a bug with... X-Git-Tag: RELEASE_0_2_0_RC1~294 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c205aefdd43177a9f184f90b9af53c3adf7a90d1;p=xonotic%2Fdarkplaces.git fixed viewmodel (it wasn't drawing because it's matrix was empty), fixed a bug with scaling in Matrix4x4_CreateFromQuakeEntity (and Matrix3x4 to match), added some extra code to Matrix4x4_Invert_Simple (and Matrix3x4) to further clarify the scaling inversion git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2310 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_rmain.c b/gl_rmain.c index d0a46fa2..9c2cfdbb 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -505,6 +505,9 @@ void R_DrawViewModel (void) R_LerpAnimation(ent); + Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], -ent->angles[0], ent->angles[1], ent->angles[2], ent->scale); + Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix); + ent->model->Draw(ent); } diff --git a/matrixlib.c b/matrixlib.c index ff447d7a..603b617c 100644 --- a/matrixlib.c +++ b/matrixlib.c @@ -135,7 +135,15 @@ void Matrix4x4_Invert_Simple (matrix4x4_t *out, const matrix4x4_t *in1) // (note the lack of sqrt here, because we're trying to undo the scaling, // this means multiplying by the inverse scale twice - squaring it, which // makes the sqrt a waste of time) +#if 1 double scale = 1.0 / (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]); +#else + double scale = 3.0 / sqrt + (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2] + + in1->m[1][0] * in1->m[1][0] + in1->m[1][1] * in1->m[1][1] + in1->m[1][2] * in1->m[1][2] + + in1->m[2][0] * in1->m[2][0] + in1->m[2][1] * in1->m[2][1] + in1->m[2][2] * in1->m[2][2]); +#endif + scale *= scale; // invert the rotation by transposing and multiplying by the squared // recipricol of the input matrix scale as described above @@ -287,17 +295,17 @@ void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, float x, float y, float z angle = roll * (M_PI*2 / 360); sr = sin(angle); cr = cos(angle); - out->m[0][0] = cp*cy * scale; - out->m[0][1] = sr*sp*cy+cr*-sy * scale; - out->m[0][2] = cr*sp*cy+-sr*-sy * scale; + out->m[0][0] = (cp*cy) * scale; + out->m[0][1] = (sr*sp*cy+cr*-sy) * scale; + out->m[0][2] = (cr*sp*cy+-sr*-sy) * scale; out->m[0][3] = x; - out->m[1][0] = cp*sy * scale; - out->m[1][1] = sr*sp*sy+cr*cy * scale; - out->m[1][2] = cr*sp*sy+-sr*cy * scale; + out->m[1][0] = (cp*sy) * scale; + out->m[1][1] = (sr*sp*sy+cr*cy) * scale; + out->m[1][2] = (cr*sp*sy+-sr*cy) * scale; out->m[1][3] = y; - out->m[2][0] = -sp * scale; - out->m[2][1] = sr*cp * scale; - out->m[2][2] = cr*cp * scale; + out->m[2][0] = (-sp) * scale; + out->m[2][1] = (sr*cp) * scale; + out->m[2][2] = (cr*cp) * scale; out->m[2][3] = z; out->m[3][0] = 0; out->m[3][1] = 0; @@ -503,7 +511,14 @@ void Matrix3x4_Invert_Simple (matrix3x4_t *out, const matrix3x4_t *in1) // (note the lack of sqrt here, because we're trying to undo the scaling, // this means multiplying by the inverse scale twice - squaring it, which // makes the sqrt a waste of time) +#if 1 double scale = 1.0 / (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]); +#else + double scale = 3.0 / sqrt + (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2] + + in1->m[1][0] * in1->m[1][0] + in1->m[1][1] * in1->m[1][1] + in1->m[1][2] * in1->m[1][2] + + in1->m[2][0] * in1->m[2][0] + in1->m[2][1] * in1->m[2][1] + in1->m[2][2] * in1->m[2][2]); +#endif // invert the rotation by transposing and multiplying by the squared // recipricol of the input matrix scale as described above @@ -630,17 +645,17 @@ void Matrix3x4_CreateFromQuakeEntity(matrix3x4_t *out, float x, float y, float z angle = roll * (M_PI*2 / 360); sr = sin(angle); cr = cos(angle); - out->m[0][0] = cp*cy * scale; - out->m[0][1] = sr*sp*cy+cr*-sy * scale; - out->m[0][2] = cr*sp*cy+-sr*-sy * scale; + out->m[0][0] = (cp*cy) * scale; + out->m[0][1] = (sr*sp*cy+cr*-sy) * scale; + out->m[0][2] = (cr*sp*cy+-sr*-sy) * scale; out->m[0][3] = x; - out->m[1][0] = cp*sy * scale; - out->m[1][1] = sr*sp*sy+cr*cy * scale; - out->m[1][2] = cr*sp*sy+-sr*cy * scale; + out->m[1][0] = (cp*sy) * scale; + out->m[1][1] = (sr*sp*sy+cr*cy) * scale; + out->m[1][2] = (cr*sp*sy+-sr*cy) * scale; out->m[1][3] = y; - out->m[2][0] = -sp * scale; - out->m[2][1] = sr*cp * scale; - out->m[2][2] = cr*cp * scale; + out->m[2][0] = (-sp) * scale; + out->m[2][1] = (sr*cp) * scale; + out->m[2][2] = (cr*cp) * scale; out->m[2][3] = z; }