From 3d1f7d9b9570b94f1503498268b1019d1d02f98d Mon Sep 17 00:00:00 2001 From: ac-stef Date: Thu, 4 Jun 2015 12:49:43 +0200 Subject: [PATCH] fix mapmodel occlusion when using pitch and roll may need a bit more work, though --- source/src/md2.h | 2 +- source/src/md3.h | 2 +- source/src/model.h | 4 ++-- source/src/rendermodel.cpp | 7 ++++++- source/src/vertmodel.h | 18 ++++++++++-------- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/source/src/md2.h b/source/src/md2.h index 19367d34..b46da84c 100644 --- a/source/src/md2.h +++ b/source/src/md2.h @@ -272,7 +272,7 @@ struct md2 : vertmodel per_idents = true; loadingmd2 = 0; loopv(parts) parts[i]->scaleverts(scale/16.0f, vec(translate.x, -translate.y, translate.z)); - radius = calcradius(); + radius = calcradius(zradius); if(shadowdist) calcneighbors(); calcbbs(); return loaded = true; diff --git a/source/src/md3.h b/source/src/md3.h index b45ac039..cd11774e 100644 --- a/source/src/md3.h +++ b/source/src/md3.h @@ -248,7 +248,7 @@ struct md3 : vertmodel if(skin==notexture) conoutf("could not load model skin for %s", name1); } loopv(parts) parts[i]->scaleverts(scale/16.0f, vec(translate.x, -translate.y, translate.z)); - radius = calcradius(); + radius = calcradius(zradius); if(shadowdist) calcneighbors(); calcbbs(); return loaded = true; diff --git a/source/src/model.h b/source/src/model.h index aac10f17..a5e4c13d 100644 --- a/source/src/model.h +++ b/source/src/model.h @@ -42,12 +42,12 @@ class dynent; struct model { bool cullface, vertexlight, alphablend; //ALX Alpha channel models - float alphatest, translucency, scale, radius, shadowdist; + float alphatest, translucency, scale, radius, zradius, shadowdist; vec translate; int cachelimit, batch; //model() : cullface(true), vertexlight(false), alphatest(0.9f), translucency(0.25f), scale(1), radius(0), shadowdist(0), translate(0, 0, 0), cachelimit(8), batch(-1) {} - model() : cullface(true), vertexlight(false), alphablend(false), alphatest(0.9f), translucency(0.25f), scale(1), radius(0), shadowdist(0), translate(0, 0, 0), cachelimit(8), batch(-1) {} + model() : cullface(true), vertexlight(false), alphablend(false), alphatest(0.9f), translucency(0.25f), scale(1), radius(0), zradius(0), shadowdist(0), translate(0, 0, 0), cachelimit(8), batch(-1) {} virtual ~model() {} virtual bool load() = 0; diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index e87b05f9..a5df34ca 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -612,7 +612,12 @@ void rendermodel(const char *mdl, int anim, int tex, float rad, const vec &o, fl if(rad >= 0) { - if(!rad) rad = m->radius * scale; + if(!rad) + { + rad = m->radius; + if(roll != 0 || pitch != 0) rad = max(m->radius, m->zradius); // FIXME: this assumes worst-case even for small angles and should be eased up (especially for lamp posts) + rad *= scale; + } if(isoccluded(camera1->o.x, camera1->o.y, o.x-rad, o.y-rad, rad*2)) return; } diff --git a/source/src/vertmodel.h b/source/src/vertmodel.h index 90d565a1..972a94dc 100644 --- a/source/src/vertmodel.h +++ b/source/src/vertmodel.h @@ -566,10 +566,11 @@ __attribute__((optimize(2))) return vert; } - float calcradius() + float calcradius(float &zradius) { - float rad = 0; - loopi(numverts) rad = max(rad, verts[i].magnitudexy()); + float rad = 0, zrad = 0; + loopi(numverts) rad = max(rad, verts[i].magnitudexy()), zrad = max(zrad, fabsf(verts[i].z)); + zradius = zrad; return rad; } @@ -1195,10 +1196,10 @@ __attribute__((optimize(2))) return s; } - float calcradius() + float calcradius(float &zradius) { - float rad = 0; - loopv(meshes) rad = max(rad, meshes[i]->calcradius()); + float rad = 0, zrad = 0; + loopv(meshes) rad = max(rad, meshes[i]->calcradius(zrad)), zradius = max(zradius, zrad); return rad; } @@ -1260,9 +1261,10 @@ __attribute__((optimize(2))) return parts.length()==1 && parts[0]->shadows; } - float calcradius() + float calcradius(float &zradius) { - return parts.empty() ? 0.0f : parts[0]->calcradius(); + zradius = 0; + return parts.empty() ? 0.0f : parts[0]->calcradius(zradius); } void calcneighbors()