Skip to content

Commit

Permalink
bounds_t
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Dec 30, 2024
1 parent 67812ef commit 3264a8c
Show file tree
Hide file tree
Showing 31 changed files with 687 additions and 628 deletions.
15 changes: 7 additions & 8 deletions src/common/cm/cm_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ CM_BoundBrush
*/
void CM_BoundBrush( cbrush_t *b )
{
b->bounds[ 0 ][ 0 ] = -b->sides[ 0 ].plane->dist;
b->bounds[ 1 ][ 0 ] = b->sides[ 1 ].plane->dist;
b->bounds.mins[ 0 ] = -b->sides[ 0 ].plane->dist;
b->bounds.maxs[ 0 ] = b->sides[ 1 ].plane->dist;

b->bounds[ 0 ][ 1 ] = -b->sides[ 2 ].plane->dist;
b->bounds[ 1 ][ 1 ] = b->sides[ 3 ].plane->dist;
b->bounds.mins[ 1 ] = -b->sides[ 2 ].plane->dist;
b->bounds.maxs[ 1 ] = b->sides[ 3 ].plane->dist;

b->bounds[ 0 ][ 2 ] = -b->sides[ 4 ].plane->dist;
b->bounds[ 1 ][ 2 ] = b->sides[ 5 ].plane->dist;
b->bounds.mins[ 2 ] = -b->sides[ 4 ].plane->dist;
b->bounds.maxs[ 2 ] = b->sides[ 5 ].plane->dist;
}

/*
Expand Down Expand Up @@ -999,8 +999,7 @@ clipHandle_t CM_TempBoxModel( const vec3_t mins, const vec3_t maxs, bool capsule
box_planes[ 10 ].dist = mins[ 2 ];
box_planes[ 11 ].dist = -mins[ 2 ];

VectorCopy( mins, box_brush->bounds[ 0 ] );
VectorCopy( maxs, box_brush->bounds[ 1 ] );
BoundsSet( box_brush->bounds, mins, maxs );

return BOX_MODEL_HANDLE;
}
Expand Down
8 changes: 4 additions & 4 deletions src/common/cm/cm_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct cbrushside_t
struct cbrush_t
{
int contents;
vec3_t bounds[ 2 ];
bounds_t bounds;
int numsides;
cbrushside_t *sides;
int checkcount; // to avoid repeated testings
Expand Down Expand Up @@ -129,7 +129,7 @@ struct cFacet_t

struct cSurfaceCollide_t
{
vec3_t bounds[ 2 ];
bounds_t bounds;
int numPlanes; // surface planes plus edge planes
cPlane_t *planes;

Expand Down Expand Up @@ -238,7 +238,7 @@ struct traceWork_t
vec3_t offsets[ 8 ]; // [signbits][x] = either size[0][x] or size[1][x]
float maxOffset; // longest corner length from origin
vec3_t extents; // greatest of abs(size[0]) and abs(size[1])
vec3_t bounds[ 2 ]; // enclosing box of start and end surrounding by size
bounds_t bounds; // enclosing box of start and end surrounding by size
vec3_t modelOrigin; // origin of the model tracing through
int contents; // ored contents of the model tracing through
int skipContents; // ored contents that shall be ignored
Expand All @@ -253,7 +253,7 @@ struct leafList_t
int maxcount;
bool overflowed;
int *list;
vec3_t bounds[ 2 ];
bounds_t bounds; // for bounding box culling
int lastLeaf; // for overflows where each leaf can't be stored individually
void ( *storeLeafs )( leafList_t *ll, int nodenum );
};
Expand Down
16 changes: 8 additions & 8 deletions src/common/cm/cm_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,13 @@ cSurfaceCollide_t *CM_GeneratePatchCollide( int width, int height, const vec3_t
// the approximate surface defined by these points will be
// collided against
sc = ( cSurfaceCollide_t * ) CM_Alloc( sizeof( *sc ) );
ClearBounds( sc->bounds[ 0 ], sc->bounds[ 1 ] );
ClearBounds( sc->bounds );

for ( i = 0; i < grid.width; i++ )
{
for ( j = 0; j < grid.height; j++ )
{
AddPointToBounds( grid.points[ i ][ j ], sc->bounds[ 0 ], sc->bounds[ 1 ] );
AddPointToBounds( grid.points[ i ][ j ], sc->bounds );
}
}

Expand All @@ -838,13 +838,13 @@ cSurfaceCollide_t *CM_GeneratePatchCollide( int width, int height, const vec3_t
CM_SurfaceCollideFromGrid( &grid, sc );

// expand by one unit for epsilon purposes
sc->bounds[ 0 ][ 0 ] -= 1;
sc->bounds[ 0 ][ 1 ] -= 1;
sc->bounds[ 0 ][ 2 ] -= 1;
sc->bounds.mins[ 0 ] -= 1;
sc->bounds.mins[ 1 ] -= 1;
sc->bounds.mins[ 2 ] -= 1;

sc->bounds[ 1 ][ 0 ] += 1;
sc->bounds[ 1 ][ 1 ] += 1;
sc->bounds[ 1 ][ 2 ] += 1;
sc->bounds.maxs[ 0 ] += 1;
sc->bounds.maxs[ 1 ] += 1;
sc->bounds.maxs[ 2 ] += 1;

return sc;
}
7 changes: 3 additions & 4 deletions src/common/cm/cm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void CM_BoxLeafnums_r( leafList_t *ll, int nodenum )

node = &cm.nodes[ nodenum ];
plane = node->plane;
s = BoxOnPlaneSide( ll->bounds[ 0 ], ll->bounds[ 1 ], plane );
s = BoxOnPlaneSide( ll->bounds, plane );

if ( s == 1 )
{
Expand Down Expand Up @@ -170,8 +170,7 @@ int CM_BoxLeafnums( const vec3_t mins, const vec3_t maxs, int *list, int listsiz

cm.checkcount++;

VectorCopy( mins, ll.bounds[ 0 ] );
VectorCopy( maxs, ll.bounds[ 1 ] );
BoundsSet( ll.bounds, mins, maxs );
ll.count = 0;
ll.maxcount = listsize;
ll.list = list;
Expand Down Expand Up @@ -236,7 +235,7 @@ int CM_PointContents( const vec3_t p, clipHandle_t model )
const cbrush_t *b = &cm.brushes[ *brushNum ];

// XreaL BEGIN
if ( !CM_BoundsIntersectPoint( b->bounds[ 0 ], b->bounds[ 1 ], p ) )
if ( !CM_BoundsIntersectPoint( b->bounds.mins, b->bounds.maxs, p ) )
{
continue;
}
Expand Down
61 changes: 31 additions & 30 deletions src/common/cm/cm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ static void CM_TestBoxInBrush( traceWork_t *tw, const cbrush_t *brush )

// special test for axial
// the first 6 brush planes are always axial
if ( tw->bounds[ 0 ][ 0 ] > brush->bounds[ 1 ][ 0 ]
|| tw->bounds[ 0 ][ 1 ] > brush->bounds[ 1 ][ 1 ]
|| tw->bounds[ 0 ][ 2 ] > brush->bounds[ 1 ][ 2 ]
|| tw->bounds[ 1 ][ 0 ] < brush->bounds[ 0 ][ 0 ]
|| tw->bounds[ 1 ][ 1 ] < brush->bounds[ 0 ][ 1 ] || tw->bounds[ 1 ][ 2 ] < brush->bounds[ 0 ][ 2 ] )
if ( tw->bounds.mins[ 0 ] > brush->bounds.maxs[ 0 ]
|| tw->bounds.mins[ 1 ] > brush->bounds.maxs[ 1 ]
|| tw->bounds.mins[ 2 ] > brush->bounds.maxs[ 2 ]
|| tw->bounds.maxs[ 0 ] < brush->bounds.mins[ 0 ]
|| tw->bounds.maxs[ 1 ] < brush->bounds.mins[ 1 ]
|| tw->bounds.maxs[ 2 ] < brush->bounds.mins[ 2 ] )
{
return;
}
Expand Down Expand Up @@ -613,17 +614,17 @@ void CM_PositionTest( traceWork_t *tw )
leafList_t ll;

// identify the leafs we are touching
VectorAdd( tw->start, tw->size[ 0 ], ll.bounds[ 0 ] );
VectorAdd( tw->start, tw->size[ 1 ], ll.bounds[ 1 ] );
VectorAdd( tw->start, tw->size[ 0 ], ll.bounds.mins );
VectorAdd( tw->start, tw->size[ 1 ], ll.bounds.maxs );

{
ll.bounds[ 0 ][ 0 ] -= 1;
ll.bounds[ 0 ][ 1 ] -= 1;
ll.bounds[ 0 ][ 2 ] -= 1;
ll.bounds.mins[ 0 ] -= 1;
ll.bounds.mins[ 1 ] -= 1;
ll.bounds.mins[ 2 ] -= 1;

ll.bounds[ 1 ][ 0 ] += 1;
ll.bounds[ 1 ][ 1 ] += 1;
ll.bounds[ 1 ][ 2 ] += 1;
ll.bounds.maxs[ 0 ] += 1;
ll.bounds.maxs[ 1 ] += 1;
ll.bounds.maxs[ 2 ] += 1;
}

ll.count = 0;
Expand Down Expand Up @@ -850,7 +851,7 @@ void CM_TraceThroughSurfaceCollide( traceWork_t *tw, const cSurfaceCollide_t *sc
cFacet_t *facet;
vec3_t startp, endp;

if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], sc->bounds[ 0 ], sc->bounds[ 1 ] ) )
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, sc->bounds.mins, sc->bounds.maxs ) )
{
return;
}
Expand Down Expand Up @@ -1290,7 +1291,7 @@ void CM_TraceThroughLeaf( traceWork_t *tw, const cLeaf_t *leaf )
continue;
}

if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], b->bounds[ 0 ], b->bounds[ 1 ] ) )
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, b->bounds.mins, b->bounds.maxs ) )
{
continue;
}
Expand Down Expand Up @@ -1338,7 +1339,7 @@ void CM_TraceThroughLeaf( traceWork_t *tw, const cLeaf_t *leaf )
continue;
}

if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], surface->sc->bounds[ 0 ], surface->sc->bounds[ 1 ] ) )
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, surface->sc->bounds.mins, surface->sc->bounds.maxs ) )
{
continue;
}
Expand Down Expand Up @@ -1590,12 +1591,12 @@ void CM_TraceCapsuleThroughCapsule( traceWork_t *tw, clipHandle_t model )
CM_ModelBounds( model, mins, maxs );

// test trace bounds vs. capsule bounds
if ( tw->bounds[ 0 ][ 0 ] > maxs[ 0 ] + RADIUS_EPSILON
|| tw->bounds[ 0 ][ 1 ] > maxs[ 1 ] + RADIUS_EPSILON
|| tw->bounds[ 0 ][ 2 ] > maxs[ 2 ] + RADIUS_EPSILON
|| tw->bounds[ 1 ][ 0 ] < mins[ 0 ] - RADIUS_EPSILON
|| tw->bounds[ 1 ][ 1 ] < mins[ 1 ] - RADIUS_EPSILON
|| tw->bounds[ 1 ][ 2 ] < mins[ 2 ] - RADIUS_EPSILON )
if ( tw->bounds.mins[ 0 ] > maxs[ 0 ] + RADIUS_EPSILON
|| tw->bounds.mins[ 1 ] > maxs[ 1 ] + RADIUS_EPSILON
|| tw->bounds.mins[ 2 ] > maxs[ 2 ] + RADIUS_EPSILON
|| tw->bounds.maxs[ 0 ] < mins[ 0 ] - RADIUS_EPSILON
|| tw->bounds.maxs[ 1 ] < mins[ 1 ] - RADIUS_EPSILON
|| tw->bounds.maxs[ 2 ] < mins[ 2 ] - RADIUS_EPSILON )
{
return;
}
Expand Down Expand Up @@ -1964,13 +1965,13 @@ static void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, co
{
if ( tw.start[ i ] < tw.end[ i ] )
{
tw.bounds[ 0 ][ i ] = tw.start[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
tw.bounds[ 1 ][ i ] = tw.end[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
tw.bounds.mins[ i ] = tw.start[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
tw.bounds.maxs[ i ] = tw.end[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
}
else
{
tw.bounds[ 0 ][ i ] = tw.end[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
tw.bounds[ 1 ][ i ] = tw.start[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
tw.bounds.mins[ i ] = tw.end[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
tw.bounds.maxs[ i ] = tw.start[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
}
}
}
Expand All @@ -1980,13 +1981,13 @@ static void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, co
{
if ( tw.start[ i ] < tw.end[ i ] )
{
tw.bounds[ 0 ][ i ] = tw.start[ i ] + tw.size[ 0 ][ i ];
tw.bounds[ 1 ][ i ] = tw.end[ i ] + tw.size[ 1 ][ i ];
tw.bounds.mins[ i ] = tw.start[ i ] + tw.size[ 0 ][ i ];
tw.bounds.maxs[ i ] = tw.end[ i ] + tw.size[ 1 ][ i ];
}
else
{
tw.bounds[ 0 ][ i ] = tw.end[ i ] + tw.size[ 0 ][ i ];
tw.bounds[ 1 ][ i ] = tw.start[ i ] + tw.size[ 1 ][ i ];
tw.bounds.mins[ i ] = tw.end[ i ] + tw.size[ 0 ][ i ];
tw.bounds.maxs[ i ] = tw.start[ i ] + tw.size[ 1 ][ i ];
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/common/cm/cm_trisoup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,27 +318,27 @@ cSurfaceCollide_t *CM_GenerateTriangleSoupCollide( int numVertexes, vec3_t *vert
//for(i = 0; i < triSoup.num

sc = ( cSurfaceCollide_t * ) CM_Alloc( sizeof( *sc ) );
ClearBounds( sc->bounds[ 0 ], sc->bounds[ 1 ] );
ClearBounds( sc->bounds );

for ( i = 0; i < triSoup.numTriangles; i++ )
{
for ( j = 0; j < 3; j++ )
{
AddPointToBounds( triSoup.points[ i ][ j ], sc->bounds[ 0 ], sc->bounds[ 1 ] );
AddPointToBounds( triSoup.points[ i ][ j ], sc->bounds );
}
}

// generate a bsp tree for the surface
CM_SurfaceCollideFromTriangleSoup( &triSoup, sc );

// expand by one unit for epsilon purposes
sc->bounds[ 0 ][ 0 ] -= 1;
sc->bounds[ 0 ][ 1 ] -= 1;
sc->bounds[ 0 ][ 2 ] -= 1;
sc->bounds.mins[ 0 ] -= 1;
sc->bounds.mins[ 1 ] -= 1;
sc->bounds.mins[ 2 ] -= 1;

sc->bounds[ 1 ][ 0 ] += 1;
sc->bounds[ 1 ][ 1 ] += 1;
sc->bounds[ 1 ][ 2 ] += 1;
sc->bounds.maxs[ 0 ] += 1;
sc->bounds.maxs[ 1 ] += 1;
sc->bounds.maxs[ 2 ] += 1;

cmLog.Debug( "CM_GenerateTriangleSoupCollide: %i planes %i facets", sc->numPlanes, sc->numFacets );

Expand Down
22 changes: 12 additions & 10 deletions src/engine/client/cg_msgdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ namespace Util {
{
stream.Write<uint32_t>(Util::ordinal(skel.type));
stream.WriteSize(skel.numBones);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
stream.Write<float>(skel.bounds[i][j]);
}
}
stream.Write<float>(skel.bounds.mins[0]);
stream.Write<float>(skel.bounds.mins[1]);
stream.Write<float>(skel.bounds.mins[2]);
stream.Write<float>(skel.bounds.maxs[0]);
stream.Write<float>(skel.bounds.maxs[1]);
stream.Write<float>(skel.bounds.maxs[2]);
stream.Write<float>(skel.scale);
size_t length = sizeof(refBone_t) * skel.numBones;
stream.WriteData(&skel.bones, length);
Expand All @@ -80,11 +81,12 @@ namespace Util {
refSkeleton_t skel;
skel.type = static_cast<refSkeletonType_t>(stream.Read<uint32_t>());
skel.numBones = stream.ReadSize<refBone_t>();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
skel.bounds[i][j] = stream.Read<float>();
}
}
skel.bounds.mins[0] = stream.Read<float>();
skel.bounds.mins[1] = stream.Read<float>();
skel.bounds.mins[2] = stream.Read<float>();
skel.bounds.maxs[0] = stream.Read<float>();
skel.bounds.maxs[1] = stream.Read<float>();
skel.bounds.maxs[2] = stream.Read<float>();
skel.scale = stream.Read<float>();

if (skel.numBones > sizeof(skel.bones) / sizeof(refBone_t)) {
Expand Down
5 changes: 4 additions & 1 deletion src/engine/client/cl_cgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,10 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha

case CG_R_MODELBOUNDS:
IPC::HandleMsg<Render::ModelBoundsMsg>(channel, std::move(reader), [this] (int handle, std::array<float, 3>& mins, std::array<float, 3>& maxs) {
re.ModelBounds(handle, mins.data(), maxs.data());
bounds_t bounds;
re.ModelBounds(handle, bounds);
VectorCopy(bounds.mins, mins);
VectorCopy(bounds.maxs, maxs);
});
break;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/null/null_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int R_LerpTag( orientation_t*, const refEntity_t*, const char*, int )
{
return 0;
}
void R_ModelBounds( qhandle_t, vec3_t, vec3_t ) { }
void R_ModelBounds( qhandle_t, bounds_t& ) { }
void R_RemapShader( const char*, const char*, const char* ) { }
bool R_GetEntityToken( char*, int )
{
Expand Down
Loading

0 comments on commit 3264a8c

Please sign in to comment.