Skip to content

Commit

Permalink
fix regressions caused by FLT_MIN
Browse files Browse the repository at this point in the history
misunderstanding that FLT_MIN is near 0 and not negative infinity broke clipnode rendering and probably lots of other things.
  • Loading branch information
wootguy committed Oct 16, 2023
1 parent 988fc70 commit 63086b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ bool getPlaneFromVerts(vector<vec3>& verts, vec3& outNormal, float& outDist) {
}

vec2 getCenter(vector<vec2>& 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++) {
Expand All @@ -422,7 +422,7 @@ vec2 getCenter(vector<vec2>& verts) {
}

vec3 getCenter(vector<vec3>& 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++) {
Expand All @@ -433,7 +433,7 @@ vec3 getCenter(vector<vec3>& verts) {
}

void getBoundingBox(vector<vec3>& 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++) {
Expand Down

0 comments on commit 63086b3

Please sign in to comment.