From 63086b3f366cf8b26dee9ead63156d060d2de3b5 Mon Sep 17 00:00:00 2001 From: wootguy Date: Mon, 16 Oct 2023 15:44:25 -0700 Subject: [PATCH] fix regressions caused by FLT_MIN misunderstanding that FLT_MIN is near 0 and not negative infinity broke clipnode rendering and probably lots of other things. --- src/bsp/Bsp.cpp | 8 ++++---- src/editor/Renderer.cpp | 10 +++++----- src/util/util.cpp | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 7c1c2950..961a0c95 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -100,7 +100,7 @@ void Bsp::get_bounding_box(vec3& mins, vec3& maxs) { void Bsp::get_model_vertex_bounds(int modelIdx, vec3& mins, vec3& maxs) { mins = vec3(FLT_MAX, FLT_MAX, FLT_MAX); - maxs = vec3(FLT_MIN, FLT_MIN, FLT_MIN); + maxs = vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX); BSPMODEL& model = models[modelIdx]; @@ -3176,7 +3176,7 @@ void Bsp::create_node_box(vec3 min, vec3 max, BSPMODEL* targetModel, int texture targetModel->iFirstFace = startFace; targetModel->nFaces = 6; - targetModel->nMaxs = vec3(FLT_MIN, FLT_MIN, FLT_MIN); + targetModel->nMaxs = vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX); targetModel->nMins = vec3(FLT_MAX, FLT_MAX, FLT_MAX); for (int i = 0; i < 8; i++) { vec3 v = verts[startVert + i]; @@ -3350,7 +3350,7 @@ void Bsp::create_nodes(Solid& solid, BSPMODEL* targetModel) { targetModel->iFirstFace = startFace; targetModel->nFaces = solid.faces.size(); - targetModel->nMaxs = vec3(FLT_MIN, FLT_MIN, FLT_MIN); + targetModel->nMaxs = vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX); targetModel->nMins = vec3(FLT_MAX, FLT_MAX, FLT_MAX); for (int i = 0; i < solid.hullVerts.size(); i++) { vec3 v = verts[startVert + i]; @@ -3453,7 +3453,7 @@ void Bsp::simplify_model_collision(int modelIdx, int hullIdx) { } vec3 vertMin(FLT_MAX, FLT_MAX, FLT_MAX); - vec3 vertMax(FLT_MIN, FLT_MIN, FLT_MIN); + vec3 vertMax(-FLT_MAX, -FLT_MAX, -FLT_MAX); get_model_vertex_bounds(modelIdx, vertMin, vertMax); create_clipnode_box(vertMin, vertMax, &model, hullIdx, true); diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index 8b6f0acd..cc7e1537 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -1735,7 +1735,7 @@ void Renderer::updateDragAxes() { if (transformTarget == TRANSFORM_VERTEX) { vec3 entOrigin = ent ? ent->getOrigin() : vec3(); vec3 min(FLT_MAX, FLT_MAX, FLT_MAX); - vec3 max(FLT_MIN, FLT_MIN, FLT_MIN); + vec3 max(-FLT_MAX, -FLT_MAX, -FLT_MAX); int selectTotal = 0; for (int i = 0; i < modelVerts.size(); i++) { if (modelVerts[i].selected) { @@ -2226,7 +2226,7 @@ void Renderer::scaleSelectedObject(vec3 dir, vec3 fromDir) { bool scaleFromOrigin = fromDir.x == 0 && fromDir.y == 0 && fromDir.z == 0; vec3 minDist = vec3(FLT_MAX, FLT_MAX, FLT_MAX); - vec3 maxDist = vec3(FLT_MIN, FLT_MIN, FLT_MIN); + vec3 maxDist = vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX); for (int i = 0; i < modelVerts.size(); i++) { expandBoundingBox(modelVerts[i].startPos, minDist, maxDist); @@ -2291,7 +2291,7 @@ void Renderer::scaleSelectedObject(vec3 dir, vec3 fromDir) { return; minDist = vec3(FLT_MAX, FLT_MAX, FLT_MAX); - maxDist = vec3(FLT_MIN, FLT_MIN, FLT_MIN); + maxDist = vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX); for (int i = 0; i < modelFaceVerts.size(); i++) { expandBoundingBox(modelFaceVerts[i].pos, minDist, maxDist); @@ -2530,7 +2530,7 @@ void Renderer::splitFace() { for (int i = 0; i < newSolid.faces.size(); i++) { Face& solidFace = newSolid.faces[i]; BSPFACE* bestMatch = NULL; - float bestdot = FLT_MIN; + float bestdot = -FLT_MAX; for (int k = 0; k < oldModel.nFaces; k++) { BSPFACE& bspface = map->faces[oldModel.iFirstFace + k]; BSPPLANE& plane = map->planes[bspface.iPlane]; @@ -2573,7 +2573,7 @@ void Renderer::scaleSelectedVerts(float x, float y, float z) { vec3 fromOrigin = activeAxes.origin; vec3 min(FLT_MAX, FLT_MAX, FLT_MAX); - vec3 max(FLT_MIN, FLT_MIN, FLT_MIN); + vec3 max(-FLT_MAX, -FLT_MAX, -FLT_MAX); int selectTotal = 0; for (int i = 0; i < modelVerts.size(); i++) { if (modelVerts[i].selected) { diff --git a/src/util/util.cpp b/src/util/util.cpp index ed8c32c8..d3062586 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -411,7 +411,7 @@ bool getPlaneFromVerts(vector& verts, vec3& outNormal, float& outDist) { } vec2 getCenter(vector& verts) { - vec2 maxs = vec2(FLT_MIN, FLT_MIN); + vec2 maxs = vec2(-FLT_MAX, -FLT_MAX); vec2 mins = vec2(FLT_MAX, FLT_MAX); for (int i = 0; i < verts.size(); i++) { @@ -422,7 +422,7 @@ vec2 getCenter(vector& verts) { } vec3 getCenter(vector& verts) { - vec3 maxs = vec3(FLT_MIN, FLT_MIN, FLT_MIN); + vec3 maxs = vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX); vec3 mins = vec3(FLT_MAX, FLT_MAX, FLT_MAX); for (int i = 0; i < verts.size(); i++) { @@ -433,7 +433,7 @@ vec3 getCenter(vector& verts) { } void getBoundingBox(vector& verts, vec3& mins, vec3& maxs) { - maxs = vec3(FLT_MIN, FLT_MIN, FLT_MIN); + maxs = vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX); mins = vec3(FLT_MAX, FLT_MAX, FLT_MAX); for (int i = 0; i < verts.size(); i++) {