Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/lib/src/guMtxF2L.c
7857 views
1
#include "libultra_internal.h"
2
#ifdef GBI_FLOATS
3
#include <string.h>
4
#endif
5
6
#ifndef GBI_FLOATS
7
void guMtxF2L(float mf[4][4], Mtx *m) {
8
int r, c;
9
s32 tmp1;
10
s32 tmp2;
11
s32 *m1 = &m->m[0][0];
12
s32 *m2 = &m->m[2][0];
13
for (r = 0; r < 4; r++) {
14
for (c = 0; c < 2; c++) {
15
tmp1 = mf[r][2 * c] * 65536.0f;
16
tmp2 = mf[r][2 * c + 1] * 65536.0f;
17
*m1++ = (tmp1 & 0xffff0000) | ((tmp2 >> 0x10) & 0xffff);
18
*m2++ = ((tmp1 << 0x10) & 0xffff0000) | (tmp2 & 0xffff);
19
}
20
}
21
}
22
23
void guMtxL2F(float mf[4][4], Mtx *m) {
24
int r, c;
25
u32 tmp1;
26
u32 tmp2;
27
u32 *m1;
28
u32 *m2;
29
s32 stmp1, stmp2;
30
m1 = (u32 *) &m->m[0][0];
31
m2 = (u32 *) &m->m[2][0];
32
for (r = 0; r < 4; r++) {
33
for (c = 0; c < 2; c++) {
34
tmp1 = (*m1 & 0xffff0000) | ((*m2 >> 0x10) & 0xffff);
35
tmp2 = ((*m1++ << 0x10) & 0xffff0000) | (*m2++ & 0xffff);
36
stmp1 = *(s32 *) &tmp1;
37
stmp2 = *(s32 *) &tmp2;
38
mf[r][c * 2 + 0] = stmp1 / 65536.0f;
39
mf[r][c * 2 + 1] = stmp2 / 65536.0f;
40
}
41
}
42
}
43
#else
44
void guMtxF2L(float mf[4][4], Mtx *m) {
45
memcpy(m, mf, sizeof(Mtx));
46
}
47
#endif
48
49
void guMtxIdentF(float mf[4][4]) {
50
int r, c;
51
for (r = 0; r < 4; r++) {
52
for (c = 0; c < 4; c++) {
53
if (r == c) {
54
mf[r][c] = 1.0f;
55
} else {
56
mf[r][c] = 0.0f;
57
}
58
}
59
}
60
}
61
62
void guMtxIdent(Mtx *m) {
63
#ifndef GBI_FLOATS
64
float mf[4][4];
65
guMtxIdentF(mf);
66
guMtxF2L(mf, m);
67
#else
68
guMtxIdentF(m->m);
69
#endif
70
}
71
72