From 834e2231545fae9710a91866e17af595c9f47d93 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 12 Sep 2008 01:57:54 +0000 Subject: [PATCH] model culling fix git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2536 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entities.cpp | 8 ++++---- source/src/geom.h | 1 + source/src/md2.h | 1 + source/src/md3.h | 2 +- source/src/menus.cpp | 2 +- source/src/model.h | 4 ++-- source/src/rendermodel.cpp | 6 +++++- source/src/vertmodel.h | 19 +++++++++++++++++++ source/src/weapon.cpp | 4 ++-- 9 files changed, 36 insertions(+), 11 deletions(-) diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 6d6ef607..28585e58 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -23,7 +23,7 @@ const char *entmdlnames[] = void renderent(entity &e, const char *mdlname, float z, float yaw, int anim = ANIM_MAPMODEL|ANIM_LOOP, int basetime = 0, float speed = 0) { - rendermodel(mdlname, anim, 0, 1.1f, vec(e.x, e.y, z+S(e.x, e.y)->floor), yaw, 0, speed, basetime); + rendermodel(mdlname, anim, 0, 0, vec(e.x, e.y, z+S(e.x, e.y)->floor), yaw, 0, speed, basetime); } void renderentities() @@ -45,7 +45,7 @@ void renderentities() { mapmodelinfo &mmi = getmminfo(e.attr2); if(!&mmi) continue; - rendermodel(mmi.name, ANIM_MAPMODEL|ANIM_LOOP, e.attr4, mmi.rad ? (float)mmi.rad : 1.1f, vec(e.x, e.y, (float)S(e.x, e.y)->floor+mmi.zoff+e.attr3), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 10.0f); + rendermodel(mmi.name, ANIM_MAPMODEL|ANIM_LOOP, e.attr4, 0, vec(e.x, e.y, (float)S(e.x, e.y)->floor+mmi.zoff+e.attr3), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 10.0f); } else if(isitem(e.type)) { @@ -64,7 +64,7 @@ void renderentities() if(f.actor && f.actor != player1) { s_sprintfd(path)("pickups/flags/small_%s%s", m_ktf || m_tktf ? "" : team_string(i), m_htf ? "_htf" : m_ktf || m_tktf ? "ktf" : ""); - rendermodel(path, ANIM_FLAG|ANIM_START, 0, 1.1f, vec(f.actor->o).add(vec(0, 0, 0.3f+(sinf(lastmillis/100.0f)+1)/10)), lastmillis/2.5f, 0, 120.0f); + rendermodel(path, ANIM_FLAG|ANIM_START, 0, 0, vec(f.actor->o).add(vec(0, 0, 0.3f+(sinf(lastmillis/100.0f)+1)/10)), lastmillis/2.5f, 0, 120.0f); } break; case CTFF_INBASE: @@ -73,7 +73,7 @@ void renderentities() { entity &e = *f.flagent; s_sprintfd(path)("pickups/flags/%s%s", m_ktf || m_tktf ? "" : team_string(i), m_htf ? "_htf" : m_ktf || m_tktf ? "ktf" : ""); - rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 4, vec(e.x, e.y, f.state==CTFF_INBASE ? (float)S(e.x, e.y)->floor : e.z), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); + rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(e.x, e.y, f.state==CTFF_INBASE ? (float)S(e.x, e.y)->floor : e.z), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); break; } case CTFF_IDLE: diff --git a/source/src/geom.h b/source/src/geom.h index 86073474..36ec9112 100644 --- a/source/src/geom.h +++ b/source/src/geom.h @@ -37,6 +37,7 @@ struct vec float dist(const vec &e, vec &t) const { t = *this; t.sub(e); return t.magnitude(); } float distxy(const vec &e) const { float dx = e.x - x, dy = e.y - y; return sqrtf(dx*dx + dy*dy); } + float magnitudexy() const { return sqrtf(x*x + y*y); } bool reject(const vec &o, float max) const { return x>o.x+max || xo.y+max || yscaleverts(scale/16.0f, vec(translate.x, -translate.y, translate.z)); + radius = calcradius(); return loaded = true; } }; diff --git a/source/src/md3.h b/source/src/md3.h index 98c4d7e9..b48bf572 100644 --- a/source/src/md3.h +++ b/source/src/md3.h @@ -223,7 +223,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(); return loaded = true; } }; diff --git a/source/src/menus.cpp b/source/src/menus.cpp index e410e279..b0fc8225 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -676,7 +676,7 @@ void rendermenumdl() a[0].name = "weapons/subgun/world"; a[0].tag = "tag_weapon"; } - rendermodel(isplayermodel ? "playermodels" : m.mdl, m.anim, tex, 0, pos, yaw, 0, 0, 0, NULL, a, m.scale ? m.scale/25.0f : 1.0f); + rendermodel(isplayermodel ? "playermodels" : m.mdl, m.anim, tex, -1, pos, yaw, 0, 0, 0, NULL, a, m.scale ? m.scale/25.0f : 1.0f); glPopMatrix(); } diff --git a/source/src/model.h b/source/src/model.h index 11d56212..8eed0b84 100644 --- a/source/src/model.h +++ b/source/src/model.h @@ -38,11 +38,11 @@ struct dynent; struct model { bool cullface; - float alphatest, translucency, scale; + float alphatest, translucency, scale, radius; vec translate; int batch; - model() : cullface(true), alphatest(0.9f), translucency(0.25f), scale(1), translate(0, 0, 0), batch(-1) {} + model() : cullface(true), alphatest(0.9f), translucency(0.25f), scale(1), radius(0), translate(0, 0, 0), batch(-1) {} virtual ~model() {} virtual bool load() = 0; diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index b7ebbbcd..bc9660ca 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -294,7 +294,11 @@ void rendermodel(const char *mdl, int anim, int tex, float rad, const vec &o, fl model *m = loadmodel(mdl); if(!m) return; - if(rad > 0 && isoccluded(camera1->o.x, camera1->o.y, o.x-rad, o.y-rad, rad*2)) return; + if(rad >= 0) + { + if(!rad) rad = m->radius; + if(isoccluded(camera1->o.x, camera1->o.y, o.x-rad, o.y-rad, rad*2)) return; + } int varseed = 0; if(d) switch(anim&ANIM_INDEX) diff --git a/source/src/vertmodel.h b/source/src/vertmodel.h index e1f1e42c..1d89b504 100644 --- a/source/src/vertmodel.h +++ b/source/src/vertmodel.h @@ -231,6 +231,13 @@ struct vertmodel : model } return vert; } + + float calcradius() + { + float rad = 0; + loopi(numverts) rad = max(rad, verts[i].magnitudexy()); + return rad; + } }; struct animinfo @@ -718,6 +725,13 @@ struct vertmodel : model s_strcat(s, "shadows.dat"); return s; } + + float calcradius() + { + float rad = 0; + loopv(meshes) rad = max(rad, meshes[i]->calcradius()); + return rad; + } }; bool loaded; @@ -766,6 +780,11 @@ struct vertmodel : model return parts.length()==1 && parts[0]->shadows; } + float calcradius() + { + return parts.empty() ? 0.0f : parts[0]->calcradius(); + } + static bool enablealphablend, enablealphatest, enabledepthmask; static GLuint lasttex; static float lastalphatest; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index c40580ee..7d094b45 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -336,7 +336,7 @@ void renderbounceents() } } path(model); - rendermodel(model, ANIM_MAPMODEL|ANIM_LOOP, 0, 1.1f, o, p->yaw+90, p->pitch); + rendermodel(model, ANIM_MAPMODEL|ANIM_LOOP, 0, 0, o, p->yaw+90, p->pitch); } } @@ -544,7 +544,7 @@ void weapon::renderhudmodel(int lastaction, int index) lastanim[index] = wm.anim|(type<<24); lastswitch[index] = lastmillis; } - rendermodel(path, wm.anim|(index ? ANIM_MIRROR : 0)|(emit ? ANIM_PARTICLE : 0), 0, 0, wm.pos, player1->yaw+90, player1->pitch+wm.k_rot, 40.0f, lastswitch[index], NULL, NULL, 1.28f); + rendermodel(path, wm.anim|(index ? ANIM_MIRROR : 0)|(emit ? ANIM_PARTICLE : 0), 0, -1, wm.pos, player1->yaw+90, player1->pitch+wm.k_rot, 40.0f, lastswitch[index], NULL, NULL, 1.28f); } void weapon::updatetimers()