From d85ca375e57301eaccc022ee6a38220e78719ecb Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Mon, 6 Sep 2021 12:03:59 -0600 Subject: [PATCH] qbsp: fix node/leaf mins/maxs calculations they should use floor/ceil. Otherwise a node with max X=10.5 will be written to bsp29 as having a max of 10 --- qbsp/writebsp.cc | 61 ++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index 5e3e15b8..1645f906 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -25,6 +25,7 @@ #include #include +#include #include static void @@ -364,12 +365,10 @@ ExportLeaf_BSP29(mapentity_t *entity, node_t *node) * write bounding box info * (VectorCopy doesn't work since dest are shorts) */ - dleaf->mins[0] = (short)node->mins[0]; - dleaf->mins[1] = (short)node->mins[1]; - dleaf->mins[2] = (short)node->mins[2]; - dleaf->maxs[0] = (short)node->maxs[0]; - dleaf->maxs[1] = (short)node->maxs[1]; - dleaf->maxs[2] = (short)node->maxs[2]; + for (int i = 0; i < 3; ++i) { + dleaf->mins[i] = (short)floor(node->mins[i]); + dleaf->maxs[i] = (short)ceil(node->maxs[i]); + } dleaf->visofs = -1; // no vis info yet @@ -414,12 +413,10 @@ ExportLeaf_BSP2(mapentity_t *entity, node_t *node) * write bounding box info * (VectorCopy doesn't work double->float) */ - dleaf->mins[0] = node->mins[0]; - dleaf->mins[1] = node->mins[1]; - dleaf->mins[2] = node->mins[2]; - dleaf->maxs[0] = node->maxs[0]; - dleaf->maxs[1] = node->maxs[1]; - dleaf->maxs[2] = node->maxs[2]; + for (int i = 0; i < 3; ++i) { + dleaf->mins[i] = node->mins[i]; + dleaf->maxs[i] = node->maxs[i]; + } dleaf->visofs = -1; // no vis info yet @@ -464,12 +461,10 @@ ExportLeaf_BSP2rmq(mapentity_t *entity, node_t *node) * write bounding box info * (VectorCopy doesn't work since dest are shorts) */ - dleaf->mins[0] = (short)node->mins[0]; - dleaf->mins[1] = (short)node->mins[1]; - dleaf->mins[2] = (short)node->mins[2]; - dleaf->maxs[0] = (short)node->maxs[0]; - dleaf->maxs[1] = (short)node->maxs[1]; - dleaf->maxs[2] = (short)node->maxs[2]; + for (int i = 0; i < 3; ++i) { + dleaf->mins[i] = (short)floor(node->mins[i]); + dleaf->maxs[i] = (short)ceil(node->maxs[i]); + } dleaf->visofs = -1; // no vis info yet @@ -510,12 +505,10 @@ ExportDrawNodes_BSP29(mapentity_t *entity, node_t *node) map.cTotal[LUMP_NODES]++; // VectorCopy doesn't work since dest are shorts - dnode->mins[0] = (short)node->mins[0]; - dnode->mins[1] = (short)node->mins[1]; - dnode->mins[2] = (short)node->mins[2]; - dnode->maxs[0] = (short)node->maxs[0]; - dnode->maxs[1] = (short)node->maxs[1]; - dnode->maxs[2] = (short)node->maxs[2]; + for (int i = 0; i < 3; ++i) { + dnode->mins[i] = (short)floor(node->mins[i]); + dnode->maxs[i] = (short)ceil(node->maxs[i]); + } dnode->planenum = ExportMapPlane(node->planenum); dnode->firstface = node->firstface; @@ -564,12 +557,10 @@ ExportDrawNodes_BSP2(mapentity_t *entity, node_t *node) map.cTotal[LUMP_NODES]++; // VectorCopy doesn't work double->float - dnode->mins[0] = node->mins[0]; - dnode->mins[1] = node->mins[1]; - dnode->mins[2] = node->mins[2]; - dnode->maxs[0] = node->maxs[0]; - dnode->maxs[1] = node->maxs[1]; - dnode->maxs[2] = node->maxs[2]; + for (int i = 0; i < 3; ++i) { + dnode->mins[i] = node->mins[i]; + dnode->maxs[i] = node->maxs[i]; + } dnode->planenum = ExportMapPlane(node->planenum); dnode->firstface = node->firstface; @@ -606,12 +597,10 @@ ExportDrawNodes_BSP2rmq(mapentity_t *entity, node_t *node) map.cTotal[LUMP_NODES]++; // VectorCopy doesn't work since dest are shorts - dnode->mins[0] = node->mins[0]; - dnode->mins[1] = node->mins[1]; - dnode->mins[2] = node->mins[2]; - dnode->maxs[0] = node->maxs[0]; - dnode->maxs[1] = node->maxs[1]; - dnode->maxs[2] = node->maxs[2]; + for (int i = 0; i < 3; ++i) { + dnode->mins[i] = (short)floor(node->mins[i]); + dnode->maxs[i] = (short)ceil(node->maxs[i]); + } dnode->planenum = ExportMapPlane(node->planenum); dnode->firstface = node->firstface;