sead
Loading...
Searching...
No Matches
seadBoundBox.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
#
include
<
math
/
seadMathCalcCommon
.
h
>
4
5
namespace
sead
{
6
7
template
<
typename
T
>
8
inline
Vector2
<
T
>
9
BoundBox2
<
T
>::
getCenter
()
const
10
{
11
return
Vector2
((
mMin
.
x
+
mMax
.
x
) / 2.0f,
12
(
mMin
.
y
+
mMax
.
y
) / 2.0f);
13
}
14
15
template
<
typename
T
>
16
inline
void
17
BoundBox2
<
T
>::
getCenter
(
Vector2
*
center
)
const
18
{
19
center
->
set
((
mMin
.
x
+
mMax
.
x
) / 2.0f,
20
(
mMin
.
y
+
mMax
.
y
) / 2.0f);
21
}
22
23
template
<
typename
T
>
24
inline
bool
25
BoundBox2
<
T
>::
isUndef
()
const
26
{
27
return
mMin
.
x
>
mMax
.
x
||
mMin
.
y
>
mMax
.
y
;
28
}
29
30
template
<
typename
T
>
31
inline
bool
32
BoundBox2
<
T
>::
isInside
(
const
Vector2
&
p
)
const
33
{
34
return
mMin
.
x
<=
p
.
x
&&
p
.
x
<=
mMax
.
x
&&
mMin
.
y
<=
p
.
y
&&
p
.
y
<=
mMax
.
y
;
35
}
36
37
template
<
typename
T
>
38
inline
void
39
BoundBox2
<
T
>::
setUndef
()
40
{
41
mMin
.
set
(
MathCalcCommon
<
T
>::
maxNumber
(),
MathCalcCommon
<
T
>::
maxNumber
());
42
mMax
.
set
(
MathCalcCommon
<
T
>::
minNumber
(),
MathCalcCommon
<
T
>::
minNumber
());
43
}
44
45
template
<
typename
T
>
46
inline
void
47
BoundBox2
<
T
>::
set
(
T
x0
,
T
y0
,
T
x1
,
T
y1
)
48
{
49
if
(
x0
<
x1
)
50
{
51
mMin
.
x
=
x0
;
52
mMax
.
x
=
x1
;
53
}
54
else
55
{
56
mMin
.
x
=
x1
;
57
mMax
.
x
=
x0
;
58
}
59
60
if
(
y0
<
y1
)
61
{
62
mMin
.
y
=
y0
;
63
mMax
.
y
=
y1
;
64
}
65
else
66
{
67
mMin
.
y
=
y1
;
68
mMax
.
y
=
y0
;
69
}
70
}
71
72
template
<
typename
T
>
73
inline
void
74
BoundBox2
<
T
>::
set
(
const
Vector2
&
min
,
const
Vector2
&
max
)
75
{
76
mMin
=
min
;
77
mMax
=
max
;
78
}
79
80
template
<
typename
T
>
81
inline
void
82
BoundBox2
<
T
>::
setMin
(
const
Vector2
&
min
)
83
{
84
mMin
=
min
;
85
}
86
87
template
<
typename
T
>
88
inline
void
89
BoundBox2
<
T
>::
setMax
(
const
Vector2
&
max
)
90
{
91
mMax
=
max
;
92
}
93
94
template
<
typename
T
>
95
inline
void
96
BoundBox2
<
T
>::
setFromCenterAndXY
(
T
centerX
,
T
centerY
,
T
sizeX
,
T
sizeY
)
97
{
98
mMin
.
set
(
centerX
-
sizeX
/ 2.0f,
centerY
-
sizeY
/ 2.0f);
99
mMax
.
set
(
centerX
+
sizeX
/ 2.0f,
centerY
+
sizeY
/ 2.0f);
100
}
101
102
template
<
typename
T
>
103
inline
void
104
BoundBox2
<
T
>::
setFromCornerAndXY
(
T
cornerX
,
T
cornerY
,
T
sizeX
,
T
sizeY
)
105
{
106
mMin
.
set
(
cornerX
,
cornerY
);
107
mMax
.
set
(
cornerX
+
sizeX
,
cornerY
+
sizeY
);
108
}
109
110
template
<
typename
T
>
111
inline
void
112
BoundBox2
<
T
>::
setFromCornerAndXY
(
const
Vector2
&
corner
,
T
sizeX
,
T
sizeY
)
113
{
114
mMin
.
set
(
corner
.
x
,
corner
.
y
);
115
mMax
.
set
(
corner
.
x
+
sizeX
,
corner
.
y
+
sizeY
);
116
}
117
118
template
<
typename
T
>
119
inline
void
120
BoundBox2
<
T
>::
offset
(
T
dx
,
T
dy
)
121
{
122
mMin
.
x
+=
dx
;
123
mMin
.
y
+=
dy
;
124
mMax
.
x
+=
dx
;
125
mMax
.
y
+=
dy
;
126
}
127
128
template
<
typename
T
>
129
inline
void
130
BoundBox2
<
T
>::
offset
(
const
Vector2
&
dv
)
131
{
132
offset
(
dv
.
x
,
dv
.
y
);
133
}
134
135
template
<
typename
T
>
136
inline
void
137
BoundBox2
<
T
>::
scaleX
(
T
sx
)
138
{
139
T
sizeX
= (
mMax
.
x
-
mMin
.
x
) * (
sx
/ 2.0f);
140
T
centerX
= (
mMin
.
x
+
mMax
.
x
) / 2.0f;
141
142
mMin
.
x
=
centerX
-
sizeX
;
143
mMax
.
x
=
centerX
+
sizeX
;
144
}
145
146
template
<
typename
T
>
147
inline
void
148
BoundBox2
<
T
>::
scaleY
(
T
sy
)
149
{
150
T
sizeY
= (
mMax
.
y
-
mMin
.
y
) * (
sy
/ 2.0f);
151
T
centerY
= (
mMin
.
y
+
mMax
.
y
) / 2.0f;
152
153
mMin
.
y
=
centerY
-
sizeY
;
154
mMax
.
y
=
centerY
+
sizeY
;
155
}
156
157
template
<
typename
T
>
158
inline
Vector3
<
T
>
159
BoundBox3
<
T
>::
getCenter
()
const
160
{
161
return
Vector3
((
mMin
.
x
+
mMax
.
x
) / 2.0f,
162
(
mMin
.
y
+
mMax
.
y
) / 2.0f,
163
(
mMin
.
z
+
mMax
.
z
) / 2.0f);
164
}
165
166
template
<
typename
T
>
167
inline
void
168
BoundBox3
<
T
>::
getCenter
(
Vector3
*
center
)
const
169
{
170
center
->
set
((
mMin
.
x
+
mMax
.
x
) / 2.0f,
171
(
mMin
.
y
+
mMax
.
y
) / 2.0f,
172
(
mMin
.
z
+
mMax
.
z
) / 2.0f);
173
}
174
175
template
<
typename
T
>
176
inline
bool
177
BoundBox3
<
T
>::
isUndef
()
const
178
{
179
return
mMin
.
x
>
mMax
.
x
||
mMin
.
y
>
mMax
.
y
||
mMin
.
z
>
mMax
.
z
;
180
}
181
182
template
<
typename
T
>
183
inline
bool
184
BoundBox3
<
T
>::
isInside
(
const
Vector3
&
p
)
const
185
{
186
return
mMin
.
x
<=
p
.
x
&&
p
.
x
<=
mMax
.
x
&&
mMin
.
y
<=
p
.
y
&&
p
.
y
<=
mMax
.
y
&&
mMin
.
z
<=
p
.
z
&&
p
.
z
<=
mMax
.
z
;
187
}
188
189
template
<
typename
T
>
190
inline
void
191
BoundBox3
<
T
>::
setUndef
()
192
{
193
mMin
.
set
(
MathCalcCommon
<
T
>::
maxNumber
(),
MathCalcCommon
<
T
>::
maxNumber
(),
MathCalcCommon
<
T
>::
maxNumber
());
194
mMax
.
set
(
MathCalcCommon
<
T
>::
minNumber
(),
MathCalcCommon
<
T
>::
minNumber
(),
MathCalcCommon
<
T
>::
minNumber
());
195
}
196
197
template
<
typename
T
>
198
inline
void
199
BoundBox3
<
T
>::
set
(
T
x0
,
T
y0
,
T
z0
,
T
x1
,
T
y1
,
T
z1
)
200
{
201
if
(
x0
<
x1
)
202
{
203
mMin
.
x
=
x0
;
204
mMax
.
x
=
x1
;
205
}
206
else
207
{
208
mMin
.
x
=
x1
;
209
mMax
.
x
=
x0
;
210
}
211
212
if
(
y0
<
y1
)
213
{
214
mMin
.
y
=
y0
;
215
mMax
.
y
=
y1
;
216
}
217
else
218
{
219
mMin
.
y
=
y1
;
220
mMax
.
y
=
y0
;
221
}
222
223
if
(
z0
<
z1
)
224
{
225
mMin
.
z
=
z0
;
226
mMax
.
z
=
z1
;
227
}
228
else
229
{
230
mMin
.
z
=
z1
;
231
mMax
.
z
=
z0
;
232
}
233
}
234
235
template
<
typename
T
>
236
inline
void
237
BoundBox3
<
T
>::
set
(
const
Vector3
&
min
,
const
Vector3
&
max
)
238
{
239
mMin
=
min
;
240
mMax
=
max
;
241
}
242
243
template
<
typename
T
>
244
inline
void
245
BoundBox3
<
T
>::
setMin
(
const
Vector3
&
min
)
246
{
247
mMin
=
min
;
248
}
249
250
template
<
typename
T
>
251
inline
void
252
BoundBox3
<
T
>::
setMax
(
const
Vector3
&
max
)
253
{
254
mMax
=
max
;
255
}
256
257
template
<
typename
T
>
258
inline
void
259
BoundBox3
<
T
>::
offset
(
T
dx
,
T
dy
,
T
dz
)
260
{
261
mMin
.
x
+=
dx
;
262
mMin
.
y
+=
dy
;
263
mMin
.
z
+=
dz
;
264
mMax
.
x
+=
dx
;
265
mMax
.
y
+=
dy
;
266
mMax
.
z
+=
dz
;
267
}
268
269
template
<
typename
T
>
270
inline
void
271
BoundBox3
<
T
>::
offset
(
const
Vector3
&
dv
)
272
{
273
offset
(
dv
.
x
,
dv
.
y
,
dv
.
z
);
274
}
275
276
template
<
typename
T
>
277
inline
void
278
BoundBox3
<
T
>::
scaleX
(
T
sx
)
279
{
280
T
sizeX
= (
mMax
.
x
-
mMin
.
x
) * (
sx
/ 2.0f);
281
T
centerX
= (
mMin
.
x
+
mMax
.
x
) / 2.0f;
282
283
mMin
.
x
=
centerX
-
sizeX
;
284
mMax
.
x
=
centerX
+
sizeX
;
285
}
286
287
template
<
typename
T
>
288
inline
void
289
BoundBox3
<
T
>::
scaleY
(
T
sy
)
290
{
291
T
sizeY
= (
mMax
.
y
-
mMin
.
y
) * (
sy
/ 2.0f);
292
T
centerY
= (
mMin
.
y
+
mMax
.
y
) / 2.0f;
293
294
mMin
.
y
=
centerY
-
sizeY
;
295
mMax
.
y
=
centerY
+
sizeY
;
296
}
297
298
template
<
typename
T
>
299
inline
void
300
BoundBox3
<
T
>::
scaleZ
(
T
sz
)
301
{
302
T
sizeZ
= (
mMax
.
z
-
mMin
.
z
) * (
sz
/ 2.0f);
303
T
centerZ
= (
mMin
.
z
+
mMax
.
z
) / 2.0f;
304
305
mMin
.
z
=
centerZ
-
sizeZ
;
306
mMax
.
z
=
centerZ
+
sizeZ
;
307
}
308
309
}
// namespace sead
sead
Definition
seadAssert.h:44
engine
library
include
math
seadBoundBox.hpp
Generated by
1.14.0