From 4941a86cbe9adeea4fde7a33f450403bc34283dc Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 7 Jun 2022 19:49:39 -0600 Subject: [PATCH] qbsp: rest of fix for qbsp_q2_bmodel_collision, only needed on type-cleanup branch --- include/qbsp/brush.hh | 1 + qbsp/brush.cc | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/qbsp/brush.hh b/include/qbsp/brush.hh index b0d675d3..63f0af07 100644 --- a/include/qbsp/brush.hh +++ b/include/qbsp/brush.hh @@ -53,3 +53,4 @@ void FreeBrushes(mapentity_t *ent); int FindPlane(const qplane3d &plane, int *side); int FindPositivePlane(int planenum); +int FindPositivePlane(const qplane3d &plane, int *side); diff --git a/qbsp/brush.cc b/qbsp/brush.cc index a085484f..9b9d84b1 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -253,6 +253,22 @@ int FindPositivePlane(int planenum) return FindPlane(-plane, nullptr); } +int FindPositivePlane(const qplane3d &plane, int *side) +{ + int planenum = FindPlane(plane, side); + int positive_plane = FindPositivePlane(planenum); + + if (planenum == positive_plane) { + return planenum; + } + + // planenum itself isn't positive, so flip the planeside and return the positive version + if (side) { + *side = !*side; + } + return positive_plane; +} + /* ============================================================================= @@ -394,7 +410,7 @@ static std::vector CreateBrushFaces(const mapentity_t *src, hullbrush_t plane.dist = qv::dot(plane.normal, point); f.texinfo = hullnum > 0 ? 0 : mapface.texinfo; - f.planenum = FindPlane(plane, &f.planeside); + f.planenum = FindPositivePlane(plane, &f.planeside); f.src_entity = const_cast(src); // FIXME: get rid of consts on src in the callers? CheckFace(&f, mapface);