From 426ef1494ea78f78d09332331c8ba3f4b889a9f0 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Tue, 17 Jan 2012 04:31:59 +0000 Subject: [PATCH] Add the 'yoffset' token to model definitions to allow models to compensate for ART tiles with large yoffsets, such as #603. Under normal circumstances the existing 'zadd' parameter should be used instead. Special thanks to Supertanker. git-svn-id: https://svn.eduke32.com/eduke32@2264 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 2 +- polymer/eduke32/build/include/mdsprite.h | 6 +++--- polymer/eduke32/build/src/defs.c | 9 ++++++--- polymer/eduke32/build/src/mdsprite.c | 6 +++++- polymer/eduke32/build/src/polymer.c | 3 +++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index 418c1e67e..27e34b228 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -767,7 +767,7 @@ int32_t hicclearsubst(int32_t picnum, int32_t palnum); int32_t Ptile2tile(int32_t tile, int32_t pallet); int32_t md_loadmodel(const char *fn); -int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, int32_t flags); +int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, float yoffset, int32_t flags); // int32_t md_tilehasmodel(int32_t tilenume, int32_t pal); extern char defsfilename[BMAX_PATH]; diff --git a/polymer/eduke32/build/include/mdsprite.h b/polymer/eduke32/build/include/mdsprite.h index b9a57b1d9..b8aa4294c 100644 --- a/polymer/eduke32/build/include/mdsprite.h +++ b/polymer/eduke32/build/include/mdsprite.h @@ -9,7 +9,7 @@ typedef struct { int32_t mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! int32_t shadeoff; - float scale, bscale, zadd; + float scale, bscale, zadd, yoffset; GLuint *texid; // skins int32_t flags; } mdmodel_t; @@ -68,7 +68,7 @@ typedef struct //WARNING: This top block is a union between md2model&md3model: Make sure it matches! int32_t mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! int32_t shadeoff; - float scale, bscale, zadd; + float scale, bscale, zadd, yoffset; GLuint *texid; // texture ids for base skin if no mappings defined int32_t flags; @@ -154,7 +154,7 @@ typedef struct //WARNING: This top block is a union between md2model&md3model: Make sure it matches! int32_t mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure! int32_t shadeoff; - float scale, bscale, zadd; + float scale, bscale, zadd, yoffset; uint32_t *texid; // texture ids for base skin if no mappings defined int32_t flags; diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index ab0e390d6..aff6e3dd6 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -728,7 +728,7 @@ static int32_t defsparser(scriptfile *script) initprintf("Warning: Failed loading MD2/MD3 model \"%s\"\n", modelfn); break; } - md_setmisc(lastmodelid,(float)scale, shadeoffs,0.0,0); + md_setmisc(lastmodelid,(float)scale, shadeoffs,0.0,0.0,0); if (glrendmode==4) md3postload_polymer((md3model_t *)models[lastmodelid]); #endif @@ -933,7 +933,7 @@ static int32_t defsparser(scriptfile *script) case T_MODEL: { char *modelend, *modelfn; - double scale=1.0, mzadd=0.0; + double scale=1.0, mzadd=0.0, myoffset=0.0; int32_t shadeoffs=0, pal=0, flags=0; uint8_t usedframebitmap[1024>>3]; @@ -944,6 +944,7 @@ static int32_t defsparser(scriptfile *script) { "scale", T_SCALE }, { "shade", T_SHADE }, { "zadd", T_ZADD }, + { "yoffset", T_YOFFSET }, { "frame", T_FRAME }, { "anim", T_ANIM }, { "skin", T_SKIN }, @@ -983,6 +984,8 @@ static int32_t defsparser(scriptfile *script) scriptfile_getnumber(script,&shadeoffs); break; case T_ZADD: scriptfile_getdouble(script,&mzadd); break; + case T_YOFFSET: + scriptfile_getdouble(script,&myoffset); break; case T_FLAGS: scriptfile_getnumber(script,&flags); break; case T_FRAME: @@ -1344,7 +1347,7 @@ static int32_t defsparser(scriptfile *script) } #ifdef USE_OPENGL - md_setmisc(lastmodelid,(float)scale,shadeoffs,(float)mzadd,flags); + md_setmisc(lastmodelid,(float)scale,shadeoffs,(float)mzadd,(float)myoffset,flags); // thin out the loaded model by throwing away unused frames // FIXME: CURRENTLY DISABLED: interpolation may access frames we consider 'unused'? diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 939b750a5..4d08693c6 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -210,7 +210,7 @@ int32_t md_loadmodel(const char *fn) return(nextmodelid-1); } -int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, int32_t flags) +int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, float yoffset, int32_t flags) { mdmodel_t *m; @@ -221,6 +221,7 @@ int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, i m->bscale = scale; m->shadeoff = shadeoff; m->zadd = zadd; + m->yoffset = yoffset; m->flags = flags; return 0; @@ -1948,6 +1949,9 @@ static int32_t md3draw(md3model_t *m, const spritetype *tspr) } if (globalorientation&4) { m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; } //x-flipping + // yoffset differs from zadd in that it does not follow cstat&8 y-flipping + a0.z += m->yoffset*m->scale; + f = ((float)tspr->xrepeat)/64*m->bscale; m0.x *= f; m1.x *= f; a0.x *= f; f = -f; // 20040610: backwards models aren't cool m0.y *= f; m1.y *= f; a0.y *= f; diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index fb4e73719..31abd61c6 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -3989,6 +3989,9 @@ static void polymer_drawmdsprite(spritetype *tspr) if ((tspr->cstat & 128) && (((tspr->cstat>>4) & 3) != 2)) bglTranslatef(0.0f, 0.0, -(float)(tilesizy[tspr->picnum] * tspr->yrepeat) / 8.0f); + // yoffset differs from zadd in that it does not follow cstat&8 y-flipping + bglTranslatef(0.0f, 0.0, m->yoffset * 64 * scale * tspr->yrepeat); + if (tspr->cstat & 8) { bglTranslatef(0.0f, 0.0, (float)(tilesizy[tspr->picnum] * tspr->yrepeat) / 4.0f);