diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 7d89d4de9..986984cf3 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -4761,11 +4761,10 @@ static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int dayscale = scale(dayscale, mulscale16(xdimenscale,viewingrangerecip), xdimen<<8); const int32_t daxscalerecip = divideu32_noinline(1<<30, daxscale); - const int32_t dayscalerecip = divideu32_noinline(1<<30, dayscale); int32_t *longptr = (int32_t *)davoxptr; const int32_t daxsiz = B_LITTLE32(longptr[0]), daysiz = B_LITTLE32(longptr[1]), dazsiz = B_LITTLE32(longptr[2]); - int32_t daxpivot = B_LITTLE32(longptr[3]), daypivot = B_LITTLE32(longptr[4]);// dazpivot = B_LITTLE32(longptr[5]); + int32_t daxpivot = B_LITTLE32(longptr[3]), daypivot = B_LITTLE32(longptr[4]), dazpivot = B_LITTLE32(longptr[5]); if (cstat & 4) daxpivot = (daxsiz<<8)-daxpivot; davoxptr += (6<<2); @@ -4782,8 +4781,8 @@ static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int x = (dasprx-globalposx) - dmulscale18(daxpivot,sprcosang, daypivot,-sprsinang); y = (daspry-globalposy) - dmulscale18(daypivot,sprcosang, daxpivot,sprsinang); - cosang = mulscale16(cosang, dayscalerecip); - sinang = mulscale16(sinang, dayscalerecip); + cosang <<= 2; + sinang <<= 2; const voxint_t gxstart = (voxint_t)y*cosang - (voxint_t)x*sinang; const voxint_t gystart = (voxint_t)x*cosang + (voxint_t)y*sinang; @@ -4800,9 +4799,18 @@ static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int if ((klabs(globalposz-dasprz)>>10) >= klabs(odayscale)) return; - const int32_t syoff = divscale21(globalposz-dasprz,odayscale) + (dazsiz<<14); - floorz = min(floorz, dasprz+mulscale7(dazsiz,odayscale)); - ceilingz = max(ceilingz, dasprz-mulscale7(dazsiz, odayscale)); + int32_t zoff = dazsiz<<14; + if (!(cstat & 128)) + zoff += dazpivot<<7; + else if ((cstat&48) != 48) + { + zoff += dazpivot<<7; + zoff -= dazsiz<<14; + } + + const int32_t syoff = divscale21(globalposz-dasprz,odayscale)+zoff; + floorz = min(floorz, dasprz+mulscale21(-zoff+(dazsiz<<15),odayscale)); + ceilingz = max(ceilingz, dasprz+mulscale21(-zoff, odayscale)); const int32_t flooroff = divscale21(floorz-globalposz,odayscale); const int32_t ceilingoff = divscale21(ceilingz-globalposz,odayscale); int32_t yoff = (klabs(gxinc)+klabs(gyinc))>>1; @@ -4951,10 +4959,10 @@ static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int rx -= lx; - const int32_t l1 = distrecip[clamp((ny-yoff)>>14, 1, DISTRECIPSIZ-1)]; + const int32_t l1 = mulscale12(distrecip[clamp((ny-yoff)>>14, 1, DISTRECIPSIZ-1)], dayscale); // FIXME! AMCTC RC2/beta shotgun voxel // (e.g. training map right after M16 shooting): - const int32_t l2 = distrecip[clamp((ny+yoff)>>14, 1, DISTRECIPSIZ-1)]; + const int32_t l2 = mulscale12(distrecip[clamp((ny+yoff)>>14, 1, DISTRECIPSIZ-1)], dayscale); int32_t cz1 = 0, cz2 = INT32_MAX; if (clipcf) @@ -6116,8 +6124,6 @@ draw_as_face_sprite: nyrepeat = ((int32_t)tspr->yrepeat)*voxscale[vtilenum]; } - if (!(cstat&128)) - tspr->z -= mulscale22(B_LITTLE32(longptr[5]),nyrepeat); off.x = tspr->xoffset; off.y = /*picanm[sprite[tspr->owner].picnum].yofs +*/ tspr->yoffset; if (cstat & 4) off.x = -off.x; @@ -6158,6 +6164,9 @@ draw_as_face_sprite: if ((cstat&4) == 0) x1 -= i; else x1 += i; y1 = mulscale16(tspr->z-globalposz,xdsiz); + + if (!(cstat & 128)) + y1 -= mulscale16(mulscale22(B_LITTLE32(longptr[5]), nyrepeat), xdsiz); //y1 -= mulscale30(xdsiz,nyrepeat*yoff); y1 += (globalhoriz<<8)-siz.y; //if (cstat&128) //Already fixed up above @@ -6196,7 +6205,7 @@ draw_as_face_sprite: const int32_t floorz = (sec->floorstat&3) == 0 ? sec->floorz : INT32_MAX; classicDrawVoxel(tspr->x,tspr->y,tspr->z,i,daxrepeat,(int32_t)tspr->yrepeat,vtilenum, - tspr->shade,tspr->pal,lwall,swall,cstat,(tspr->cstat&48)!=48,floorz,ceilingz); + tspr->shade,tspr->pal,lwall,swall,tspr->cstat,(tspr->cstat&48)!=48,floorz,ceilingz); } } diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index a8942e021..2c1c6dec8 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1013,7 +1013,7 @@ voxmodel_t *loadkvxfrombuf(const char *kvxbuffer, int32_t length) int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) { // float clut[6] = {1.02,1.02,0.94,1.06,0.98,0.98}; - float f, g, k0; + float f, g, k0, zoff; if ((intptr_t)m == (intptr_t)(-1)) // hackhackhack return 0; @@ -1048,7 +1048,14 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) k0 = (float) tspr->z; f = ((globalorientation&8) && (sprite[tspr->owner].cstat&48)!=0) ? -4.f : 4.f; k0 -= (tspr->yoffset*tspr->yrepeat)*f*m->bscale; - if (!(tspr->cstat&128)) k0 -= (m->piv.z*tspr->yrepeat)*4.f*m->scale; + zoff = m->siz.z*.5f; + if (!(tspr->cstat&128)) + zoff += m->piv.z; + else if ((tspr->cstat&48) != 48) + { + zoff += m->piv.z; + zoff -= m->siz.z*.5f; + } f = (65536.f*512.f) / ((float)xdimen*viewingrange); g = 32.f / ((float)xdimen*gxyaspect); @@ -1114,9 +1121,9 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) g = m0.y*f; mat[4] = omat[8]*g; mat[5] = omat[9]*g; mat[6] = omat[10]*g; g =-m0.z*f; mat[8] = omat[4]*g; mat[9] = omat[5]*g; mat[10] = omat[6]*g; // - mat[12] -= (m->piv.x*mat[0] + m->piv.y*mat[4] + m->siz.z*.5f*mat[8]); - mat[13] -= (m->piv.x*mat[1] + m->piv.y*mat[5] + m->siz.z*.5f*mat[9]); - mat[14] -= (m->piv.x*mat[2] + m->piv.y*mat[6] + m->siz.z*.5f*mat[10]); + mat[12] -= (m->piv.x*mat[0] + m->piv.y*mat[4] + zoff*mat[8]); + mat[13] -= (m->piv.x*mat[1] + m->piv.y*mat[5] + zoff*mat[9]); + mat[14] -= (m->piv.x*mat[2] + m->piv.y*mat[6] + zoff*mat[10]); // glMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f;