summaryrefslogtreecommitdiff
path: root/include/SSystem/SComponent/c_m3d.h
blob: 04b66ff41a4f2c11eef518989f789d42f67251d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef C_M3D_H_
#define C_M3D_H_

#include "math.h" // IWYU pragma: keep
#include "dolphin/types.h"
#include "dolphin/mtx/vec.h"
#include "dolphin/mtx/mtx.h"

class cM3dGAab;
class cM3dGCps;
class cM3dGCyl;
class cM3dGLin;
class cM3dGPla;
class cM3dGSph;
class cM3dGTri;
class csXyz;
class cXyz;

struct Vec;

extern const f32 G_CM3D_F_ABS_MIN;
#if VERSION == VERSION_DEMO
extern const f32 G_CM3D_F_INF;
#else
#define G_CM3D_F_INF (1000000000.0f)
#endif

extern const u32 BPCP_OUTCODE0;
extern const u32 BPCP_OUTCODE1;
extern const u32 BPCP_OUTCODE4;
extern const u32 BPCP_OUTCODE5;
extern const u32 BPCP_OUTCODE2;
extern const u32 BPCP_OUTCODE3;
extern const u32 BEVEL2D_OUTCODE0;
extern const u32 BEVEL2D_OUTCODE1;
extern const u32 BEVEL2D_OUTCODE2;
extern const u32 BEVEL2D_OUTCODE3;
extern const u32 BEVEL2D_OUTCODE4;
extern const u32 BEVEL2D_OUTCODE5;
extern const u32 BEVEL2D_OUTCODE6;
extern const u32 BEVEL2D_OUTCODE7;
extern const u32 BEVEL2D_OUTCODE8;
extern const u32 BEVEL2D_OUTCODE9;
extern const u32 BEVEL2D_OUTCODE10;
extern const u32 BEVEL2D_OUTCODE11;
extern const u32 BEVEL3D_OUTCODE0;
extern const u32 BEVEL3D_OUTCODE1;
extern const u32 BEVEL3D_OUTCODE2;
extern const u32 BEVEL3D_OUTCODE3;
extern const u32 BEVEL3D_OUTCODE4;
extern const u32 BEVEL3D_OUTCODE5;
extern const u32 BEVEL3D_OUTCODE6;
extern const u32 BEVEL3D_OUTCODE7;

struct cM3d_Range {
    f32 start;
    f32 end;
};

inline f32 cM3d_Len2dSq(f32 x0, f32 y0, f32 x1, f32 y1) {
    f32 x = x0 - x1;
    f32 y = y0 - y1;
    return x*x + y*y;
}

void cM3d_InDivPos1(const Vec*, const Vec*, f32, Vec*);
void cM3d_InDivPos2(const Vec*, const Vec*, f32, Vec*);
bool cM3d_Len2dSqPntAndSegLine(f32, f32, f32, f32, f32, f32, f32*, f32*, f32*);
bool cM3d_Len3dSqPntAndSegLine(const cM3dGLin*, const Vec*, Vec*, f32*);
f32 cM3d_SignedLenPlaAndPos(const cM3dGPla*, const Vec*);
f32 cM3d_VectorProduct2d(f32, f32, f32, f32, f32, f32);
void cM3d_CalcPla(const Vec*, const Vec*, const Vec*, Vec*, f32*);
bool cM3d_Cross_AabAab(const cM3dGAab*, const cM3dGAab*);
bool cM3d_Cross_AabCyl(const cM3dGAab*, const cM3dGCyl*);
bool cM3d_Cross_AabSph(const cM3dGAab*, const cM3dGSph*);
int cM3d_Check_LinLin(const cM3dGLin*, const cM3dGLin*, f32*, f32*);
bool cM3d_Cross_LinPla(const cM3dGLin*, const cM3dGPla*, Vec*, bool, bool);
bool cM3d_Cross_MinMaxBoxLine(const Vec*, const Vec*, const Vec*, const Vec*);
bool cM3d_InclusionCheckPosIn3PosBox3d(const Vec*, const Vec*, const Vec*, const Vec*, f32);
inline static bool cM3d_InclusionCheckPosIn3PosBox2d(f32, f32, f32, f32, f32, f32, f32, f32);
bool cM3d_CrossX_Tri(const cM3dGTri*, const Vec*, f32*);
bool cM3d_CrossX_Tri(const cM3dGTri*, const Vec*, f32);
bool cM3d_CrossX_Tri(const cM3dGTri*, const Vec*);
bool cM3d_CrossX_LinTri_proc(const cM3dGTri*, const Vec*);
bool cM3d_CrossY_Tri(const cM3dGTri*, const Vec*);
bool cM3d_CrossY_LinTri_proc(const cM3dGTri*, const Vec*);
bool cM3d_CrossY_Tri(const Vec&, const Vec&, const Vec&, const cM3dGPla&, const Vec*);
bool cM3d_CrossY_Tri_Front(const Vec&, const Vec&, const Vec&, const Vec*);
bool cM3d_CrossY_Tri(const cM3dGTri*, const Vec*, f32*);
bool cM3d_CrossY_Tri(const cM3dGTri*, const Vec*, f32);
bool cM3d_CrossY_Tri(const cM3dGTri*, const Vec*, const cM3d_Range*, f32*);
bool cM3d_CrossZ_Tri(const cM3dGTri*, const Vec*, f32*);
bool cM3d_CrossZ_Tri(const cM3dGTri*, const Vec*, f32);
bool cM3d_CrossZ_Tri(const cM3dGTri*, const Vec*);
bool cM3d_CrossZ_LinTri_proc(const cM3dGTri*, const Vec*);
bool cM3d_Cross_LinTri(const cM3dGLin*, const cM3dGTri*, Vec*, bool, bool);
bool cM3d_Cross_LinTri_Easy(const cM3dGTri*, const Vec*);
bool cM3d_Cross_SphPnt(const cM3dGSph*, const Vec*);
bool cM3d_Cross_LinSph(const cM3dGLin*, const cM3dGSph*, Vec*);
int cM3d_Cross_LinSph_CrossPos(const cM3dGSph&, const cM3dGLin&, Vec*, Vec*);
bool cM3d_Cross_CylSph(const cM3dGCyl*, const cM3dGSph*, f32*);
bool cM3d_Cross_CylSph(const cM3dGCyl*, const cM3dGSph*, Vec*, f32*);
bool cM3d_Cross_SphSph(const cM3dGSph*, const cM3dGSph*, f32*);
bool cM3d_Cross_SphSph(const cM3dGSph*, const cM3dGSph*, f32*, f32*);
bool cM3d_Cross_SphSph(const cM3dGSph*, const cM3dGSph*, Vec*);
void cM3d_CalcSphVsTriCrossPoint(const cM3dGSph*, const cM3dGTri*, Vec*);
bool cM3d_Cross_SphTri(const cM3dGSph*, const cM3dGTri*, Vec*);
inline bool cM3d_Cross_SphTri(const cM3dGSph* param_0, const cM3dGTri* param_1) {
    return cM3d_Cross_SphTri(param_0, param_1, NULL);
}
bool cM3d_Cross_CylCyl(const cM3dGCyl*, const cM3dGCyl*, f32*);
bool cM3d_Cross_CylCyl(const cM3dGCyl*, const cM3dGCyl*, Vec*);
bool cM3d_Cross_CylTri(const cM3dGCyl*, const cM3dGTri*, Vec*);
int cM3d_Cross_CylLin(const cM3dGCyl*, const cM3dGLin*, Vec*, Vec*);
int cM3d_Cross_CylPntPnt(const cM3dGCyl*, const Vec*, const Vec*, Vec*, Vec*);
bool cM3d_Cross_CylPnt(const cM3dGCyl*, const Vec*);
bool cM3d_Cross_CpsCps(const cM3dGCps&, const cM3dGCps&, Vec*);
bool cM3d_Cross_CpsCyl(const cM3dGCps&, const cM3dGCyl&, Vec*);
void cM3d_Cross_CpsSph_CrossPos(const cM3dGCps&, const cM3dGSph&, const Vec&, Vec*);
bool cM3d_Cross_CpsSph(const cM3dGCps&, const cM3dGSph&, Vec*);
bool cM3d_Cross_TriTri(const cM3dGTri&, const cM3dGTri&, Vec*);
bool cM3d_Cross_CpsTri(const cM3dGCps&, cM3dGTri, Vec*);
void cM3d_CalcVecAngle(const Vec&, short*, short*);
void cM3d_CalcVecZAngle(const Vec&, csXyz*);
bool cM3d_NearPos_Cps(const cM3dGCps&, const Vec&, Vec*);
void cM3d_PlaneCrossLineProcWork(f32, f32, f32, f32, f32, f32, f32, f32*, f32*);
int cM3d_2PlaneCrossLine(const cM3dGPla&, const cM3dGPla&, cM3dGLin*);
BOOL cM3d_3PlaneCrossPos(const cM3dGPla&, const cM3dGPla&, const cM3dGPla&, Vec*);
f32 cM3d_lineVsPosSuisenCross(const cM3dGLin*, const Vec*, Vec*);
f32 cM3d_lineVsPosSuisenCross(const Vec&, const Vec&, const Vec&, Vec*);
int cM3d_2PlaneLinePosNearPos(const cM3dGPla&, const cM3dGPla&, const Vec*, Vec*);
void cM3d_CrawVec(const Vec&, const Vec&, Vec*);
int cM3d_UpMtx_Base(const Vec&, const Vec&, MtxP);

inline bool cM3d_IsZero(f32 f) {
    return std::fabsf(f) < G_CM3D_F_ABS_MIN;
}

inline void cM3d_VectorProduct(const Vec* p01, const Vec* p02, Vec* pDst) {
    VECCrossProduct(p01, p02, pDst);
}

inline void cM3d_VectorProduct(const Vec* p0, const Vec* p1, const Vec* p2, Vec* pDst) {
    Vec v01, v02;
    VECSubtract(p1, p0, &v01);
    VECSubtract(p2, p0, &v02);
    VECCrossProduct(&v01, &v02, pDst);
}

inline f32 cM3d_VectorProduct2d(f32 pX1, f32 pY1, f32 pX2, f32 pY2, f32 pX3, f32 pY3) {
    return (pX2 - pX1) * (pY3 - pY1) - (pY2 - pY1) * (pX3 - pX1);
}

inline bool cM3d_CrossInfLineVsInfPlane_proc(f32 a, f32 b, const Vec* pA, const Vec* pB, Vec* pDst) {
    if (cM3d_IsZero(a - b)) {
        *pDst = *pB;
        return false;
    } else {
        cM3d_InDivPos2(pA, pB, a / (a - b), pDst);
        return true;
    }
}

inline f32 cM3d_LenSq(const Vec* a, const Vec* b) {
    return VECSquareDistance(a, b);
}

#endif