qbsp: add BoundBrush (from q3map)
This commit is contained in:
parent
7ef5ad162d
commit
5158b6d296
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ; j<w->numpoints ; 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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue