Skip to content

Commit 0aca705

Browse files
committed
Match and link CAABox **FINALLY** 🎉
1 parent 575add8 commit 0aca705

2 files changed

Lines changed: 50 additions & 22 deletions

File tree

‎configure.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ def MatchingFor(*versions):
15401540
Object(MatchingFor("GM8E01_00", "GM8E01_01", "GM8E01_48"), "Kyoto/Particles/CWarp.cpp"),
15411541
Object(MatchingFor("GM8E01_00", "GM8E01_01", "GM8E01_48"), "Kyoto/Math/CPlane.cpp"),
15421542
Object(MatchingFor("GM8E01_00", "GM8E01_01", "GM8E01_48"), "Kyoto/Math/CSphere.cpp"),
1543-
Object(NonMatching, "Kyoto/Math/CAABox.cpp"),
1543+
Object(MatchingFor("GM8E01_00", "GM8E01_01", "GM8E01_48"), "Kyoto/Math/CAABox.cpp"),
15441544
Object(NonMatching, "Kyoto/CFactoryMgr.cpp"),
15451545
Object(NonMatching, "Kyoto/CResFactory.cpp"),
15461546
Object(NonMatching, "Kyoto/CResLoader.cpp"),

‎src/Kyoto/Math/CAABox.cpp‎

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -245,32 +245,60 @@ bool CAABox::PointInside(const CVector3f& vec) const {
245245

246246
// Non-matching: https://decomp.me/scratch/SXsmk
247247
float CAABox::DistanceBetween(const CAABox& a, const CAABox& b) {
248-
bool b1 = (a.GetMaxPoint().GetX() > b.GetMinPoint().GetX()) |
249-
(a.GetMinPoint().GetX() < b.GetMaxPoint().GetX());
250-
bool b2 = (a.GetMaxPoint().GetY() > b.GetMinPoint().GetY()) |
251-
(a.GetMinPoint().GetY() < b.GetMaxPoint().GetY());
252-
bool b3 = (a.GetMaxPoint().GetZ() > b.GetMinPoint().GetZ()) |
253-
(a.GetMinPoint().GetZ() < b.GetMaxPoint().GetZ());
254-
int intersects = b1 ? 1 : 0;
255-
if (b2) {
248+
const bool axLTbx = (a.GetMaxPoint().GetX() < b.GetMinPoint().GetX());
249+
const bool axGTbx = (a.GetMinPoint().GetX() > b.GetMaxPoint().GetX());
250+
251+
const bool ayLTby = (a.GetMaxPoint().GetY() < b.GetMinPoint().GetY());
252+
const bool ayGTby = (a.GetMinPoint().GetY() > b.GetMaxPoint().GetY());
253+
254+
const bool azLTbz = (a.GetMaxPoint().GetZ() < b.GetMinPoint().GetZ());
255+
const bool azGTbz = (a.GetMinPoint().GetZ() > b.GetMaxPoint().GetZ());
256+
257+
// do we care about NaNs? or no
258+
int intersects = 0;
259+
const bool axEQbx = !(axLTbx || axGTbx);
260+
const bool ayEQby = !(ayLTby || ayGTby);
261+
const bool azEQbz = !(azLTbz || azGTbz);
262+
263+
if (axEQbx) {
264+
intersects |= 1;
265+
}
266+
if (ayEQby) {
256267
intersects |= 2;
257268
}
258-
if (b3) {
269+
if (azEQbz) {
259270
intersects |= 4;
260271
}
261272

262-
const float minX = b.GetMinPoint().GetX() > a.GetMaxPoint().GetX() ? b.GetMinPoint().GetX()
263-
: b.GetMaxPoint().GetX();
264-
const float maxX = b.GetMinPoint().GetX() > a.GetMaxPoint().GetX() ? a.GetMaxPoint().GetX()
265-
: a.GetMinPoint().GetX();
266-
const float minY = b.GetMinPoint().GetY() > a.GetMaxPoint().GetY() ? b.GetMinPoint().GetY()
267-
: b.GetMaxPoint().GetY();
268-
const float maxY = b.GetMinPoint().GetY() > a.GetMaxPoint().GetY() ? a.GetMaxPoint().GetY()
269-
: a.GetMinPoint().GetY();
270-
const float minZ = b.GetMinPoint().GetZ() > a.GetMaxPoint().GetZ() ? b.GetMinPoint().GetZ()
271-
: b.GetMaxPoint().GetZ();
272-
const float maxZ = b.GetMinPoint().GetZ() > a.GetMaxPoint().GetZ() ? a.GetMaxPoint().GetZ()
273-
: a.GetMinPoint().GetZ();
273+
float minX;
274+
float maxX;
275+
float minY;
276+
float maxY;
277+
float minZ;
278+
float maxZ;
279+
if (axLTbx) {
280+
maxX = a.GetMaxPoint().GetX();
281+
minX = b.GetMinPoint().GetX();
282+
} else {
283+
maxX = a.GetMinPoint().GetX();
284+
minX = b.GetMaxPoint().GetX();
285+
}
286+
287+
if (ayLTby) {
288+
maxY = a.GetMaxPoint().GetY();
289+
minY = b.GetMinPoint().GetY();
290+
} else {
291+
maxY = a.GetMinPoint().GetY();
292+
minY = b.GetMaxPoint().GetY();
293+
}
294+
295+
if (azLTbz) {
296+
maxZ = a.GetMaxPoint().GetZ();
297+
minZ = b.GetMinPoint().GetZ();
298+
} else {
299+
maxZ = a.GetMinPoint().GetZ();
300+
minZ = b.GetMaxPoint().GetZ();
301+
}
274302

275303
switch (intersects) {
276304
case 0:

0 commit comments

Comments
 (0)