Skip to content

Commit af25fe6

Browse files
committed
xMath3 matches
1 parent da1160e commit af25fe6

File tree

1 file changed

+62
-12
lines changed

1 file changed

+62
-12
lines changed

src/SB/Core/x/xMath3.cpp

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "xMath3.h"
2+
#include "iMath3.h"
23

34
#include <types.h>
5+
#include <intrin.h>
46

57
#include "iMath.h" // icos and isin
68
#include "xClimate.h" // xMat3x3Identity
@@ -9,18 +11,46 @@
911

1012
xVec3 g_O3 = { 0, 0, 0 };
1113

14+
S32 xPointInBox(const xBox* b, const xVec3* p)
15+
{
16+
S32 ret = 0;
17+
if ((p->x >=b->lower.x) && (p->x <= b->upper.x))
18+
{
19+
if ((p->y>= b->lower.y) && (p->y <= b->upper.y))
20+
{
21+
if ((p->z >= b->lower.z) && (p->z <= b->upper.z))
22+
{
23+
ret = 1;
24+
}
25+
}
26+
}
27+
return (char)ret;
28+
}
29+
1230
void xMat4x3Copy(xMat4x3* o, const xMat4x3* m)
1331
{
1432
}
1533

34+
void xMat4x3Rot(xMat4x3* m, const xVec3* a, F32 t, const xVec3* p)
35+
{
36+
xMat4x3 temp;
37+
38+
xMat3x3RotC(m, a->x, a->y, a->z, t);
39+
xVec3Copy(&m->pos, p);
40+
xMat3x3Identity(&temp);
41+
xVec3Inv(&temp.pos, p);
42+
xMat4x3Mul(m, &temp, m);
43+
44+
}
45+
1646
/* xMat4x3Mul (xMat4x3 *, xMat4x3 const *, xMat4x3 const *) */
1747
void xMat4x3Mul(xMat4x3* o, const xMat4x3* a, const xMat4x3* b)
1848
{
1949
xVec3 sp8;
2050

21-
xMat4x3Toworld(&sp8, b, (xVec3*)&a->pad3);
51+
xMat4x3Toworld(&sp8, b, &a->pos);
2252
xMat3x3Mul((xMat3x3*)o, (xMat3x3*)a, (xMat3x3*)b);
23-
xVec3Copy((xVec3*)&o->pad3, &sp8);
53+
xVec3Copy(&o->pos, &sp8);
2454
}
2555

2656
/* xMat3x3Euler (xMat3x3 *, float, float, float) */
@@ -102,17 +132,38 @@ void xMat3x3RotC(xMat3x3* m, F32 _x, F32 _y, F32 _z, F32 t)
102132
m->flags = 0;
103133
}
104134

105-
/* xMat3x3RotY (xMat3x3 *, float) */
135+
void xMat3x3RotX(xMat3x3* m, F32 t)
136+
{
137+
F32 cos = icos(t);
138+
F32 sin = isin(t);
139+
140+
xVec3Copy(&m->right, &g_X3);
141+
xVec3Init(&m->up, 0.0f, cos, sin);
142+
xVec3Init(&m->at, 0.0f, -sin, cos);
143+
m->flags = 0;
144+
}
145+
106146
void xMat3x3RotY(xMat3x3* m, F32 t)
107147
{
108-
F32 temp_f1;
109148
F32 temp_f31;
149+
F32 temp_f1;
110150

111151
temp_f31 = icos(t);
112152
temp_f1 = isin(t);
113153
xVec3Init((xVec3*)m, temp_f31, 0.0f, -temp_f1);
114-
xVec3Copy(&m->right, &g_Y3);
115-
xVec3Init(&m->up, temp_f1, 0.0f, temp_f31);
154+
xVec3Copy(&m->up, &g_Y3);
155+
xVec3Init(&m->at, temp_f1, 0.0f, temp_f31);
156+
m->flags = 0;
157+
}
158+
159+
void xMat3x3RotZ(xMat3x3* m, F32 t)
160+
{
161+
F32 cos = icos(t);
162+
F32 sin = isin(t);
163+
164+
xVec3Init(&m->right, cos, sin, 0.0f);
165+
xVec3Init(&m->up, -sin, cos, 0.0f);
166+
xVec3Copy(&m->at, &g_Z3);
116167
m->flags = 0;
117168
}
118169

@@ -128,8 +179,8 @@ void xMat4x3Identity(xMat4x3* m)
128179
void xMat3x3Normalize(xMat3x3* o, const xMat3x3* m)
129180
{
130181
xVec3Normalize((xVec3*)o, (xVec3*)m);
131-
xVec3Normalize(&o->right, &m->right);
132182
xVec3Normalize(&o->up, &m->up);
183+
xVec3Normalize(&o->at, &m->at);
133184
}
134185

135186
void xMat4x3Tolocal(xVec3* o, const xMat4x3* m, const xVec3* v)
@@ -470,8 +521,7 @@ F32 xMat3x3LookVec(xMat3x3* m, const xVec3* at)
470521
temp_f31 = xVec3Normalize(&m->at, at);
471522
temp_r3 = &m->at;
472523
xVec3Inv(temp_r3, temp_r3);
473-
temp_f2 = m->at.y;
474-
if ((F32)fabs(1.0f - temp_f2) < 0.00001f)
524+
if ((F32)__fabs(1.0f - m->at.y) < 0.00001f)
475525
{
476526
m->right.x = 1.0f;
477527
m->right.y = 0.0f;
@@ -484,7 +534,7 @@ F32 xMat3x3LookVec(xMat3x3* m, const xVec3* at)
484534
m->at.z = 0.0f;
485535
return temp_f31;
486536
}
487-
if ((F32)fabs(1.0f + temp_f2) < 0.00001f)
537+
if ((F32)__fabs(1.0f + m->at.y) < 0.00001f)
488538
{
489539
m->right.x = -1.0f;
490540
m->right.y = 0.0f;
@@ -497,7 +547,7 @@ F32 xMat3x3LookVec(xMat3x3* m, const xVec3* at)
497547
m->at.z = 0.0f;
498548
return temp_f31;
499549
}
500-
if (((F32)fabs(at->z) < 0.00001f) && ((F32)fabs(at->x) < 0.00001f))
550+
if (((F32)__fabs(at->z) < 0.00001f) && ((F32)__fabs(at->x) < 0.00001f))
501551
{
502552
m->right.x = 1.0f;
503553
m->right.y = 0.0f;
@@ -507,7 +557,7 @@ F32 xMat3x3LookVec(xMat3x3* m, const xVec3* at)
507557
m->up.z = 0.0f;
508558
m->at.x = 0.0f;
509559
m->at.y = 0.0f;
510-
m->at.y = 1.0f;
560+
m->at.z = 1.0f;
511561
return 0.0f;
512562
}
513563
m->right.x = m->at.z;

0 commit comments

Comments
 (0)