From 5158b6d296cbc4e1d5516413fd8810ce01ad243f Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 22 Jul 2017 17:09:03 -0600 Subject: [PATCH] qbsp: add BoundBrush (from q3map) --- include/qbsp/brush.hh | 1 + include/qbsp/qbsp.hh | 6 ++++++ qbsp/brush.cc | 32 ++++++++++++++++++++++++++++++++ qbsp/test_qbsp.cc | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/include/qbsp/brush.hh b/include/qbsp/brush.hh index eaf700a1..39de1f11 100644 --- a/include/qbsp/brush.hh +++ b/include/qbsp/brush.hh @@ -48,6 +48,7 @@ int FindPlane(const vec3_t normal, const vec_t dist, int *side); bool PlaneEqual(const qbsp_plane_t *p1, const qbsp_plane_t *p2); bool PlaneInvEqual(const qbsp_plane_t *p1, const qbsp_plane_t *p2); +bool BoundBrush (brush_t *brush); vec_t BrushVolume (const brush_t *brush); int BrushMostlyOnSide (const brush_t *brush, const plane_t *plane); diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 9c48abc8..3466e648 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -152,8 +152,14 @@ #define T_EPSILON 0.0002 #define CONTINUOUS_EPSILON 0.0005 +// FIXME: replace with MAX_WORLD_COORD/MIN_WORLD_COORD/WORLD_SIZE #define BOGUS_RANGE 65536 +// from q3map +#define MAX_WORLD_COORD ( 128*1024 ) +#define MIN_WORLD_COORD ( -128*1024 ) +#define WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD ) + // the exact bounding box of the brushes is expanded some for the headnode // volume. is this still needed? #define SIDESPACE 24 diff --git a/qbsp/brush.cc b/qbsp/brush.cc index df10fb23..95e2c67b 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -1214,6 +1214,38 @@ Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int hullnum) } } +//============================================================ + +/* +================== +BoundBrush + +Sets the mins/maxs based on the windings +returns false if the brush doesn't enclose a valid volume + +from q3map +================== +*/ +bool BoundBrush (brush_t *brush) +{ + ClearBounds (brush->mins, brush->maxs); + + for (face_t *face = brush->faces; face; face = face->next) { + const winding_t *w = &face->w; + for (int j=0 ; jnumpoints ; j++) + AddPointToBounds (w->points[j], brush->mins, brush->maxs); + } + + for (int i=0 ; i<3 ; i++) { + if (brush->mins[i] < MIN_WORLD_COORD || brush->maxs[i] > MAX_WORLD_COORD + || brush->mins[i] >= brush->maxs[i] ) { + return false; + } + } + + return true; +} + /* ================== BrushVolume diff --git a/qbsp/test_qbsp.cc b/qbsp/test_qbsp.cc index 7302a993..c9bf3044 100644 --- a/qbsp/test_qbsp.cc +++ b/qbsp/test_qbsp.cc @@ -177,6 +177,24 @@ TEST(qbsp, BrushMostlyOnSide2) { FreeMem(brush, BRUSH, 1); } +TEST(qbsp, BoundBrush) { + brush_t *brush = load128x128x32Brush(); + + ClearBounds(brush->mins, brush->maxs); + + EXPECT_EQ(true, BoundBrush(brush)); + + EXPECT_FLOAT_EQ(-64, brush->mins[0]); + EXPECT_FLOAT_EQ(-64, brush->mins[1]); + EXPECT_FLOAT_EQ(-16, brush->mins[2]); + + EXPECT_FLOAT_EQ(64, brush->maxs[0]); + EXPECT_FLOAT_EQ(64, brush->maxs[1]); + EXPECT_FLOAT_EQ(16, brush->maxs[2]); + + FreeMem(brush, BRUSH, 1); +} + TEST(mathlib, WindingArea) { winding_t w; w.numpoints = 5;