1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-20 20:29:58 +01:00

Continue matrices

This commit is contained in:
Miloslav Číž 2018-11-21 16:58:26 +01:00
parent a3fd54891c
commit 9eccbe986a
2 changed files with 31 additions and 4 deletions

27
s3l.h
View file

@ -194,9 +194,10 @@ static inline void S3L_initMat4(S3L_Mat4 *m)
/**
Multiplies a vector by a matrix with normalization by S3L_FRACTIONS_PER_UNIT.
Result is stored in the input vector.
*/
static inline void S3L_vec4Xmat4(S3L_Vec4 *v, S3L_Mat4 *m)
void S3L_vec4Xmat4(S3L_Vec4 *v, S3L_Mat4 *m)
{
S3L_Vec4 vBackup;
@ -221,6 +222,30 @@ static inline void S3L_vec4Xmat4(S3L_Vec4 *v, S3L_Mat4 *m)
#undef dot
}
/**
Multiplies two matrices with normalization by S3L_FRACTIONS_PER_UNIT. Result
is stored in the first matrix.
*/
void S3L_mat4Xmat4(S3L_Mat4 *m1, S3L_Mat4 *m2)
{
S3L_Mat4 mat1;
for (uint16_t row = 0; row < 4; ++row)
for (uint16_t col = 0; col < 4; ++col)
mat1[col][row] = (*m1)[col][row];
for (uint16_t row = 0; row < 4; ++row)
for (uint16_t col = 0; col < 4; ++col)
{
(*m1)[col][row] = 0;
for (uint16_t i = 0; i < 4; ++i)
(*m1)[col][row] +=
(mat1[i][row] * (*m2)[col][i]) / S3L_FRACTIONS_PER_UNIT;
}
}
static inline void S3L_makeTranslationMat(S3L_Unit offsetX, S3L_Unit offsetY,
S3L_Unit offsetZ, S3L_Mat4 *m)
{

8
test.c
View file

@ -8,7 +8,7 @@ void pixelFunc(S3L_PixelInfo *pixel)
int main()
{
S3L_Mat4 m;
S3L_Mat4 m, m2;
S3L_Vec4 v;
S3L_initMat4(&m);
@ -21,9 +21,11 @@ int main()
S3L_vec4Xmat4(&v,&m);
S3L_writeVec4(v);
S3L_makeTranslationMat(100,200,300,&m);
S3L_writeMat4(m);
S3L_makeTranslationMat(100,200,300,&m2);
S3L_writeMat4(m2);
S3L_mat4Xmat4(&m,&m2);
S3L_writeMat4(m);
return 0;