Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
geometry.h
Go to the documentation of this file.
1#ifndef NW4HBM_MATH_GEOMETRY_H
2#define NW4HBM_MATH_GEOMETRY_H
3
4#include <revolution/types.h>
5
6#include "types.h"
7
8namespace nw4hbm {
9 namespace math {
23
24 struct SEGMENT3 {
25 VEC3 P0; // size 0x0c, offset 0x00
26 VEC3 P1; // size 0x0c, offset 0x0c
27 }; // size 0x18
28
29 struct RAY3 {
30 VEC3 P; // size 0x0c, offset 0x00
31 VEC3 d; // size 0x0c, offset 0x0c
32 }; // size 0x18
33
34 struct LINE3 {
35 // methods
36 public:
37 // cdtors
38 LINE3() {}
39 LINE3(VEC3 const& Pt, VEC3 const& dir, bool isNormalized) : P(Pt), d(dir) {
40 if (!isNormalized)
41 Normalize();
42 }
43
44 // methods
45 void Normalize() { VEC3Normalize(&d, &d); }
46
47 void Set(SEGMENT3 const* S) {
48 P = S->P0;
49 VEC3Sub(&d, &S->P1, &S->P0);
50
51 Normalize();
52 }
53
54 // members
55 public:
56 VEC3 P; // size 0x0c, offset 0x00
57 VEC3 d; // size 0x0c, offset 0x0c
58 }; // size 0x18
59
60 struct CAPSULE {
61 SEGMENT3 S; // size 0x18, offset 0x00
62 f32 r; // size 0x04, offset 0x18
63 }; // size 0x1c
64
65 struct PLANE {
66 // methods
67 public:
68 // methods
69 void Set(VEC3 const* P0, VEC3 const* P1, VEC3 const* P2);
70
71 f32 Test(VEC3 const& P) const { return VEC3Dot(&N, &P) + d; }
72
73 // members
74 public:
75 VEC3 N; // size 0x0c, offset 0x00
76 f32 d; // size 0x04, offset 0x0c
77 }; // size 0x10
78
79 struct AABB {
80 // methods
81 public:
82 // cdtors
83 AABB() {}
84
85 // methods
86 void Normalize();
87 void Set(VEC3 const* arrayPoint, unsigned numPoints);
88 void Set(AABB const* box, MTX34 const* M);
89
90 // members
91 public:
92 VEC3 Pmin; // size 0x0c, offset 0x00
93 VEC3 Pmax; // size 0x0c, offset 0x0c
94 }; // size 0x18
95
96 struct SPHERE {
97 // methods
98 public:
99 // methods
100 void Set(VEC3 const* arrayPoint, unsigned numPoints);
101
102 // members
103 public:
104 VEC3 C; // size 0x0c, offset 0x00
105 f32 r; // size 0x04, offset 0x0c
106 }; // size 0x10
107
108 class FRUSTUM {
109 // methods
110 public:
111 // methods
112 void Set(f32 fovy, f32 aspect, f32 n, f32 f, MTX34 const& camera);
113 void Set(f32 top, f32 bottom, f32 left, f32 right, f32 n, f32 f, MTX34 const& camera);
114
115 bool IntersectSphere(SPHERE const* S) const;
116 bool IntersectAABB(AABB const* B) const;
118
119 // members
120 public:
121 MTX34 cam; // size 0x30, offset 0x00
122 PLANE leftPlane; // size 0x10, offset 0x30
123 PLANE rightPlane; // size 0x10, offset 0x40
124 PLANE topPlane; // size 0x10, offset 0x50
125 PLANE bottomPlane; // size 0x10, offset 0x60
126 f32 near; // size 0x04, offset 0x70
127 f32 far; // size 0x04, offset 0x74
128 AABB box; // size 0x18, offset 0x78
129 PLANE planes[6]; // size 0x60, offset 0x90
130 }; // size 0xf0
131
132 f32 DistSqPoint3ToLine3(VEC3 const* P, LINE3 const* L, f32* t);
133 f32 DistSqPoint3ToRay3(VEC3 const* P, RAY3 const* R, f32* t);
135 f32 DistSqPoint3ToPlane(VEC3 const* P, PLANE const* J, VEC3* Q);
136 f32 DistSqSphereToPlane(SPHERE const* S, PLANE const* J);
137 f32 DistSqPoint3ToPolyline3(VEC3 const* P, VEC3 const* vertices, unsigned nVertices);
138 f32 DistSqLine3ToLine3(LINE3 const* L0, LINE3 const* L1, f32* s, f32* t);
140 f32 DistSqLine3ToRay3(LINE3 const* L, RAY3 const* R, f32* s, f32* t);
141 f32 DistSqLine3ToSegment3(LINE3 const* L0, SEGMENT3 const* S, f32* s, f32* t);
142 f32 DistSqRay3ToRay3(RAY3 const* R0, RAY3 const* R1, f32* s, f32* t);
143 f32 DistSqRay3ToSegment3(RAY3 const* R0, SEGMENT3 const* S, f32* s, f32* t);
144
148 VEC3* I);
150 f32* t1);
152 f32* t1);
153 bool IntersectionRay3Sphere(RAY3 const* R, SPHERE const* sphere);
155 f32* t0, f32* t1);
156
157 bool IntersectionRay3AABB(RAY3 const* R, AABB const* box, f32* t);
158 bool IntersectionAABB(AABB const* a, AABB const* b);
159 bool IntersectionSphereAABB(SPHERE const* sphere, AABB const* aabb);
160 bool IntersectionSphere(SPHERE const* s0, SPHERE const* s1);
161 bool IntersectionCapsule(CAPSULE const* C0, CAPSULE const* C1);
162 bool IntersectionRay3Capsule(RAY3 const* R, CAPSULE const* C);
163 bool IntersectionLine3Capsule(LINE3 const* L, CAPSULE const* C);
164 bool IntersectionPlaneCapsule(PLANE const* J, CAPSULE const* C);
165
167 AABB* MergeAABB(AABB* a2, AABB const* a0, AABB const* a1);
168 } // namespace math
169} // namespace nw4hbm
170
171#endif // NW4HBM_MATH_GEOMETRY_H
Definition geometry.h:108
PLANE bottomPlane
Definition geometry.h:125
PLANE rightPlane
Definition geometry.h:123
IntersectionResult IntersectAABB_Ex(AABB const *B) const
bool IntersectAABB(AABB const *B) const
f32 near
Definition geometry.h:126
AABB box
Definition geometry.h:128
PLANE planes[6]
Definition geometry.h:129
void Set(f32 top, f32 bottom, f32 left, f32 right, f32 n, f32 f, MTX34 const &camera)
PLANE leftPlane
Definition geometry.h:122
f32 far
Definition geometry.h:127
bool IntersectSphere(SPHERE const *S) const
MTX34 cam
Definition geometry.h:121
void Set(f32 fovy, f32 aspect, f32 n, f32 f, MTX34 const &camera)
PLANE topPlane
Definition geometry.h:124
static u32 t0
Definition dsp_task.c:8
static u32 t1
Definition dsp_task.c:8
s
Definition e_acos.c:99
t
Definition e_asin.c:100
static const static double double P2
Definition e_exp.c:94
static const static double double P1
Definition e_exp.c:93
n
Definition e_fmod.c:115
f
Definition e_log.c:119
R
Definition e_log.c:146
s2
Definition e_pow.c:284
static const static double double L1
Definition e_pow.c:84
unsigned s1
Definition e_sqrt.c:100
int s0
Definition e_sqrt.c:101
float f32
Definition types.h:25
a
Definition k_cos.c:89
static const static double double C1
Definition k_cos.c:57
static const static double double S2
Definition k_sin.c:51
static const static double double S1
Definition k_sin.c:50
f32 DistSqRay3ToRay3(RAY3 const *R0, RAY3 const *R1, f32 *s, f32 *t)
IntersectionResult IntersectionSegment3Plane(SEGMENT3 const *S, PLANE const *J, f32 *t, VEC3 *I)
bool IntersectionCapsule(CAPSULE const *C0, CAPSULE const *C1)
bool IntersectionRay3AABB(RAY3 const *R, AABB const *box, f32 *t)
f32 DistSqSegment3ToSegment3(SEGMENT3 const *S1, SEGMENT3 const *S2, f32 *s, f32 *t)
IntersectionResult IntersectionRay3Sphere(RAY3 const *R, SPHERE const *sphere, f32 *t0, f32 *t1)
IntersectionResult
Definition geometry.h:10
@ INTERSECTION_INTERSECT
Definition geometry.h:21
@ INTERSECTION_OUTSIDE
Definition geometry.h:19
@ INTERSECTION_RAY3_ON_PLANE
Definition geometry.h:16
@ INTERSECTION_1
Definition geometry.h:12
@ INTERSECTION_NONE
Definition geometry.h:11
@ INTERSECTION_INSIDE
Definition geometry.h:20
@ INTERSECTION_LINE3_ON_PLANE
Definition geometry.h:15
@ INTERSECTION_2
Definition geometry.h:13
@ INTERSECTION_SEGMENT3_ON_PLANE
Definition geometry.h:17
f32 DistSqPoint3ToLine3(VEC3 const *P, LINE3 const *L, f32 *t)
f32 DistSqLine3ToLine3(LINE3 const *L0, LINE3 const *L1, f32 *s, f32 *t)
f32 DistSqLine3ToSegment3(LINE3 const *L0, SEGMENT3 const *S, f32 *s, f32 *t)
f32 DistSqSphereToPlane(SPHERE const *S, PLANE const *J)
AABB * MergeAABB(AABB *a2, AABB const *a0, AABB const *a1)
f32 DistSqRay3ToSegment3(RAY3 const *R0, SEGMENT3 const *S, f32 *s, f32 *t)
bool IntersectionAABB(AABB const *a, AABB const *b)
VEC3 * VEC3Sub(register VEC3 *pOut, register VEC3 const *p1, register VEC3 const *p2)
Definition types.h:250
bool IntersectionPlaneCapsule(PLANE const *J, CAPSULE const *C)
SPHERE * MergeSphere(SPHERE *s2, SPHERE const *s0, SPHERE const *s1)
f32 VEC3Dot(register VEC3 const *p1, register VEC3 const *p2)
Definition types.h:343
f32 DistSqPoint3ToPolyline3(VEC3 const *P, VEC3 const *vertices, unsigned nVertices)
bool IntersectionLine3Capsule(LINE3 const *L, CAPSULE const *C)
bool IntersectionRay3Capsule(RAY3 const *R, CAPSULE const *C)
VEC3 * VEC3Normalize(VEC3 *pOut, VEC3 const *p)
Definition types.h:405
IntersectionResult IntersectionRay3Plane(RAY3 const *R, PLANE const *J, f32 *t, VEC3 *I)
bool IntersectionSphereAABB(SPHERE const *sphere, AABB const *aabb)
IntersectionResult IntersectionSegment3Sphere(SEGMENT3 const *S, SPHERE const *sphere, f32 *t0, f32 *t1)
f32 DistSqPoint3ToSegment3(VEC3 const *P, SEGMENT3 const *S, f32 *t)
bool IntersectionSphere(SPHERE const *s0, SPHERE const *s1)
IntersectionResult IntersectionLine3Plane(LINE3 const *L, PLANE const *J, f32 *t, VEC3 *I)
IntersectionResult IntersectionLine3Sphere(LINE3 const *L, SPHERE const *sphere, f32 *t0, f32 *t1)
f32 DistSqPoint3ToRay3(VEC3 const *P, RAY3 const *R, f32 *t)
f32 DistSqLine3ToRay3(LINE3 const *L, RAY3 const *R, f32 *s, f32 *t)
f32 DistSqPoint3ToPlane(VEC3 const *P, PLANE const *J, VEC3 *Q)
Definition HBMAnmController.h:6
Definition geometry.h:79
void Set(AABB const *box, MTX34 const *M)
VEC3 Pmax
Definition geometry.h:93
AABB()
Definition geometry.h:83
VEC3 Pmin
Definition geometry.h:92
void Set(VEC3 const *arrayPoint, unsigned numPoints)
Definition geometry.h:60
f32 r
Definition geometry.h:62
SEGMENT3 S
Definition geometry.h:61
Definition geometry.h:34
VEC3 d
Definition geometry.h:57
LINE3(VEC3 const &Pt, VEC3 const &dir, bool isNormalized)
Definition geometry.h:39
VEC3 P
Definition geometry.h:56
void Set(SEGMENT3 const *S)
Definition geometry.h:47
LINE3()
Definition geometry.h:38
void Normalize()
Definition geometry.h:45
Definition types.h:189
Definition geometry.h:65
f32 Test(VEC3 const &P) const
Definition geometry.h:71
VEC3 N
Definition geometry.h:75
f32 d
Definition geometry.h:76
void Set(VEC3 const *P0, VEC3 const *P1, VEC3 const *P2)
Definition geometry.h:29
VEC3 P
Definition geometry.h:30
VEC3 d
Definition geometry.h:31
Definition geometry.h:24
VEC3 P0
Definition geometry.h:25
VEC3 P1
Definition geometry.h:26
Definition geometry.h:96
VEC3 C
Definition geometry.h:104
void Set(VEC3 const *arrayPoint, unsigned numPoints)
f32 r
Definition geometry.h:105
Definition types.h:125