diff --git a/src/hardware/hw_model.h b/src/hardware/hw_model.h index 653263dfa..ac030e8d6 100644 --- a/src/hardware/hw_model.h +++ b/src/hardware/hw_model.h @@ -79,7 +79,7 @@ typedef struct mesh_s typedef struct tag_s { char name[64]; -// matrix_t transform; +// oldmatrix_t transform; } tag_t; #define MODEL_INTERPOLATION_FLAG "+i" diff --git a/src/m_fixed.c b/src/m_fixed.c index 18af7f9d6..632226074 100644 --- a/src/m_fixed.c +++ b/src/m_fixed.c @@ -725,10 +725,10 @@ boolean FV3_PointInsideBox(const vector3_t *point, const vector3_t *box) // // Loads the identity matrix into a matrix // -void FM_LoadIdentity(matrix_t* matrix) +void FM_LoadIdentity(oldmatrix_t* matrix) { #define M(row,col) matrix->m[col * 4 + row] - memset(matrix, 0x00, sizeof(matrix_t)); + memset(matrix, 0x00, sizeof(oldmatrix_t)); M(0, 0) = FRACUNIT; M(1, 1) = FRACUNIT; @@ -743,7 +743,7 @@ void FM_LoadIdentity(matrix_t* matrix) // Creates a matrix that can be used for // adjusting the position of an object // -void FM_CreateObjectMatrix(matrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fixed_t anglex, fixed_t angley, fixed_t anglez, fixed_t upx, fixed_t upy, fixed_t upz, fixed_t radius) +void FM_CreateObjectMatrix(oldmatrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fixed_t anglex, fixed_t angley, fixed_t anglez, fixed_t upx, fixed_t upy, fixed_t upz, fixed_t radius) { vector3_t upcross; vector3_t upvec; @@ -782,7 +782,7 @@ void FM_CreateObjectMatrix(matrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fi // // Multiplies a vector by the specified matrix // -void FM_MultMatrixVec3(const matrix_t *matrix, const vector3_t *vec, vector3_t *out) +const vector3_t *FM_MultMatrixVec3(const oldmatrix_t *matrix, const vector3_t *vec, vector3_t *out) { #define M(row,col) matrix->m[col * 4 + row] out->x = FixedMul(vec->x, M(0, 0)) @@ -800,6 +800,34 @@ void FM_MultMatrixVec3(const matrix_t *matrix, const vector3_t *vec, vector3_t * + FixedMul(vec->z, M(2, 2)) + M(2, 3); #undef M + return out; +} + +const vector4_t *FM_MultMatrixVec4(const oldmatrix_t *matrix, const vector4_t *vec, vector4_t *out) +{ +#define M(row,col) matrix->m[col * 4 + row] + out->x = FixedMul(vec->x, M(0, 0)) + + FixedMul(vec->y, M(0, 1)) + + FixedMul(vec->z, M(0, 2)) + + FixedMul(vec->a, M(0, 3)); + + out->y = FixedMul(vec->x, M(1, 0)) + + FixedMul(vec->y, M(1, 1)) + + FixedMul(vec->z, M(1, 2)) + + FixedMul(vec->a, M(1, 3)); + + out->z = FixedMul(vec->x, M(2, 0)) + + FixedMul(vec->y, M(2, 1)) + + FixedMul(vec->z, M(2, 2)) + + FixedMul(vec->a, M(2, 3)); + + + out->a = FixedMul(vec->x, M(3, 0)) + + FixedMul(vec->y, M(3, 1)) + + FixedMul(vec->z, M(3, 2)) + + FixedMul(vec->a, M(3, 3)); +#undef M + return out; } // @@ -807,9 +835,9 @@ void FM_MultMatrixVec3(const matrix_t *matrix, const vector3_t *vec, vector3_t * // // Multiples one matrix into another // -void FM_MultMatrix(matrix_t *dest, const matrix_t *multme) +void FM_MultMatrix(oldmatrix_t *dest, const oldmatrix_t *multme) { - matrix_t result; + oldmatrix_t result; UINT8 i, j; #define M(row,col) multme->m[col * 4 + row] #define D(row,col) dest->m[col * 4 + row] @@ -821,7 +849,7 @@ void FM_MultMatrix(matrix_t *dest, const matrix_t *multme) R(i, j) = FixedMul(D(i, 0), M(0, j)) + FixedMul(D(i, 1), M(1, j)) + FixedMul(D(i, 2), M(2, j)) + FixedMul(D(i, 3), M(3, j)); } - M_Memcpy(dest, &result, sizeof(matrix_t)); + M_Memcpy(dest, &result, sizeof(oldmatrix_t)); #undef R #undef D @@ -833,12 +861,12 @@ void FM_MultMatrix(matrix_t *dest, const matrix_t *multme) // // Translates a matrix // -void FM_Translate(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z) +void FM_Translate(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z) { - matrix_t trans; + oldmatrix_t trans; #define M(row,col) trans.m[col * 4 + row] - memset(&trans, 0x00, sizeof(matrix_t)); + memset(&trans, 0x00, sizeof(oldmatrix_t)); M(0, 0) = M(1, 1) = M(2, 2) = M(3, 3) = FRACUNIT; M(0, 3) = x; @@ -854,12 +882,12 @@ void FM_Translate(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z) // // Scales a matrix // -void FM_Scale(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z) +void FM_Scale(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z) { - matrix_t scale; + oldmatrix_t scale; #define M(row,col) scale.m[col * 4 + row] - memset(&scale, 0x00, sizeof(matrix_t)); + memset(&scale, 0x00, sizeof(oldmatrix_t)); M(3, 3) = FRACUNIT; M(0, 0) = x; diff --git a/src/m_fixed.h b/src/m_fixed.h index 2eceafe6b..2cbbbe4ce 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -327,17 +327,18 @@ vector3_t *FV3_IntersectionPoint(const vector3_t *vNormal, const vector3_t *vLin UINT8 FV3_PointOnLineSide(const vector3_t *point, const vector3_t *line); boolean FV3_PointInsideBox(const vector3_t *point, const vector3_t *box); -struct matrix_t +struct oldmatrix_t { fixed_t m[16]; }; -void FM_LoadIdentity(matrix_t* matrix); -void FM_CreateObjectMatrix(matrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fixed_t anglex, fixed_t angley, fixed_t anglez, fixed_t upx, fixed_t upy, fixed_t upz, fixed_t radius); -void FM_MultMatrixVec3(const matrix_t *matrix, const vector3_t *vec, vector3_t *out); -void FM_MultMatrix(matrix_t *dest, const matrix_t *multme); -void FM_Translate(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z); -void FM_Scale(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z); +void FM_LoadIdentity(oldmatrix_t* matrix); +void FM_CreateObjectMatrix(oldmatrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fixed_t anglex, fixed_t angley, fixed_t anglez, fixed_t upx, fixed_t upy, fixed_t upz, fixed_t radius); +const vector3_t *FM_MultMatrixVec3(const oldmatrix_t *matrix, const vector3_t *vec, vector3_t *out); +const vector4_t *FM_MultMatrixVec4(const oldmatrix_t *matrix, const vector4_t *vec, vector4_t *out); +void FM_MultMatrix(oldmatrix_t *dest, const oldmatrix_t *multme); +void FM_Translate(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z); +void FM_Scale(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z); #ifdef __cplusplus } // extern "C" diff --git a/src/tables.c b/src/tables.c index c4c5abbda..7a3b1b8d3 100644 --- a/src/tables.c +++ b/src/tables.c @@ -434,9 +434,9 @@ void FV3_Rotate(vector3_t *rotVec, const vector3_t *axisVec, const angle_t angle rotVec->z = az+dz+ez; } -void FM_Rotate(matrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z) -{ #define M(row,col) dest->m[row * 4 + col] +oldmatrix_t *FM_Rotate(oldmatrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z) +{ const fixed_t sinA = FINESINE(angle>>ANGLETOFINESHIFT); const fixed_t cosA = FINECOSINE(angle>>ANGLETOFINESHIFT); const fixed_t invCosA = FRACUNIT - cosA; @@ -486,5 +486,84 @@ void FM_Rotate(matrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z) M(1, 3) = 0; M(2, 3) = 0; M(3, 3) = FRACUNIT; -#undef M + + return dest; } + + +oldmatrix_t *FM_RotateX(oldmatrix_t *dest, angle_t rad) +{ + const angle_t fa = rad>>ANGLETOFINESHIFT; + const fixed_t cosrad = FINECOSINE(fa), sinrad = FINESINE(fa); + + M(0, 0) = FRACUNIT; + M(0, 1) = 0; + M(0, 2) = 0; + M(0, 3) = 0; + M(1, 0) = 0; + M(1, 1) = cosrad; + M(1, 2) = sinrad; + M(1, 3) = 0; + M(2, 0) = 0; + M(2, 1) = -sinrad; + M(2, 2) = cosrad; + M(2, 3) = 0; + M(3, 0) = 0; + M(3, 1) = 0; + M(3, 2) = 0; + M(3, 3) = FRACUNIT; + + return dest; +} + +oldmatrix_t *FM_RotateY(oldmatrix_t *dest, angle_t rad) +{ + const angle_t fa = rad>>ANGLETOFINESHIFT; + const fixed_t cosrad = FINECOSINE(fa), sinrad = FINESINE(fa); + + M(0, 0) = cosrad; + M(0, 1) = 0; + M(0, 2) = -sinrad; + M(0, 3) = 0; + M(1, 0) = 0; + M(1, 1) = FRACUNIT; + M(1, 2) = 0; + M(1, 3) = 0; + M(2, 0) = sinrad; + M(2, 1) = 0; + M(2, 2) = cosrad; + M(2, 3) = 0; + M(3, 0) = 0; + M(3, 1) = 0; + M(3, 2) = 0; + M(3, 3) = FRACUNIT; + + return dest; +} + +oldmatrix_t *FM_RotateZ(oldmatrix_t *dest, angle_t rad) +{ + const angle_t fa = rad>>ANGLETOFINESHIFT; + const fixed_t cosrad = FINECOSINE(fa), sinrad = FINESINE(fa); + + M(0, 0) = cosrad; + M(0, 1) = sinrad; + M(0, 2) = 0; + M(0, 3) = 0; + M(1, 0) = -sinrad; + M(1, 1) = cosrad; + M(1, 2) = 0; + M(1, 3) = 0; + M(2, 0) = 0; + M(2, 1) = 0; + M(2, 2) = FRACUNIT; + M(2, 3) = 0; + M(3, 0) = 0; + M(3, 1) = 0; + M(3, 2) = 0; + M(3, 3) = FRACUNIT; + + return dest; +} + +#undef M \ No newline at end of file diff --git a/src/tables.h b/src/tables.h index 0a282ff3d..01d94c555 100644 --- a/src/tables.h +++ b/src/tables.h @@ -126,7 +126,10 @@ boolean FV3_InsidePolygon(const vector3_t *vIntersection, const vector3_t *Poly, boolean FV3_IntersectedPolygon(const vector3_t *vPoly, const vector3_t *vLine, const INT32 vertexCount, vector3_t *collisionPoint); void FV3_Rotate(vector3_t *rotVec, const vector3_t *axisVec, const angle_t angle); /// Fixed Point Matrix functions -void FM_Rotate(matrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z); +oldmatrix_t *FM_Rotate(oldmatrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z); +oldmatrix_t *FM_RotateX(oldmatrix_t *dest, angle_t rad); +oldmatrix_t *FM_RotateY(oldmatrix_t *dest, angle_t rad); +oldmatrix_t *FM_RotateZ(oldmatrix_t *dest, angle_t rad); // The table values in tables.c are calculated with this many fractional bits. #define FINE_FRACBITS 16 diff --git a/src/typedef.h b/src/typedef.h index b34af2b44..0a4fa9565 100644 --- a/src/typedef.h +++ b/src/typedef.h @@ -228,7 +228,7 @@ TYPEDEF (mdllistitem_t); // m_fixed.h TYPEDEF (vector2_t); TYPEDEF (vector3_t); -TYPEDEF (matrix_t); +TYPEDEF (oldmatrix_t); // m_perfstats.h TYPEDEF (ps_hookinfo_t);