-
Notifications
You must be signed in to change notification settings - Fork 0
/
matmul.c
24 lines (21 loc) · 2.42 KB
/
matmul.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "mat_common.h"
/* multiplies two 4x4 matrices, saving the result in `res`. `res` MUST neither be A nor B */
void pg_mat4x4mul_c(float A[16], float B[16], float res[16]) {
//assert(res != A && res != B);
MAT4(res, 0, 0) = MAT4(A, 0, 0)*MAT4(B, 0, 0) + MAT4(A, 0, 1)*MAT4(B, 1, 0) + MAT4(A, 0, 2)*MAT4(B, 2, 0) + MAT4(A, 0, 3)*MAT4(B, 3, 0);
MAT4(res, 0, 1) = MAT4(A, 0, 0)*MAT4(B, 0, 1) + MAT4(A, 0, 1)*MAT4(B, 1, 1) + MAT4(A, 0, 2)*MAT4(B, 2, 1) + MAT4(A, 0, 3)*MAT4(B, 3, 1);
MAT4(res, 0, 2) = MAT4(A, 0, 0)*MAT4(B, 0, 2) + MAT4(A, 0, 1)*MAT4(B, 1, 2) + MAT4(A, 0, 2)*MAT4(B, 2, 2) + MAT4(A, 0, 3)*MAT4(B, 3, 2);
MAT4(res, 0, 3) = MAT4(A, 0, 0)*MAT4(B, 0, 3) + MAT4(A, 0, 1)*MAT4(B, 1, 3) + MAT4(A, 0, 2)*MAT4(B, 2, 3) + MAT4(A, 0, 3)*MAT4(B, 3, 3);
MAT4(res, 1, 0) = MAT4(A, 1, 0)*MAT4(B, 0, 0) + MAT4(A, 1, 1)*MAT4(B, 1, 0) + MAT4(A, 1, 2)*MAT4(B, 2, 0) + MAT4(A, 1, 3)*MAT4(B, 3, 0);
MAT4(res, 1, 1) = MAT4(A, 1, 0)*MAT4(B, 0, 1) + MAT4(A, 1, 1)*MAT4(B, 1, 1) + MAT4(A, 1, 2)*MAT4(B, 2, 1) + MAT4(A, 1, 3)*MAT4(B, 3, 1);
MAT4(res, 1, 2) = MAT4(A, 1, 0)*MAT4(B, 0, 2) + MAT4(A, 1, 1)*MAT4(B,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