From d76c2ccc346a53b8e0f262989b95727e289decc9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 4 Apr 2021 13:24:33 +0200 Subject: [PATCH] - voxel rotation. --- source/core/rendering/scene/hw_drawinfo.cpp | 6 ++++-- source/core/rendering/scene/hw_drawstructs.h | 2 +- source/core/rendering/scene/hw_sprites.cpp | 12 ++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index 89b55d39f..4377fac7e 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -304,13 +304,15 @@ void HWDrawInfo::DispatchSprites() if ((tspr->cstat & CSTAT_SPRITE_ALIGNMENT) != CSTAT_SPRITE_ALIGNMENT_SLAB && tiletovox[tspr->picnum] >= 0 && voxmodels[tiletovox[tspr->picnum]]) { HWSprite hwsprite; - if (hwsprite.ProcessVoxel(this, voxmodels[tiletovox[tspr->picnum]], tspr, §or[tspr->sectnum])) return; + int num = tiletovox[tspr->picnum]; + if (hwsprite.ProcessVoxel(this, voxmodels[tiletovox[tspr->picnum]], tspr, §or[tspr->sectnum], voxrotate[num >> 3] & (1 << (num & 7)))) return; break; } else if ((tspr->cstat & CSTAT_SPRITE_ALIGNMENT) == CSTAT_SPRITE_ALIGNMENT_SLAB && tspr->picnum < MAXVOXELS && voxmodels[tspr->picnum]) { HWSprite hwsprite; - hwsprite.ProcessVoxel(this, voxmodels[tspr->picnum], tspr, §or[tspr->sectnum]); + int num = tspr->picnum; + hwsprite.ProcessVoxel(this, voxmodels[tspr->picnum], tspr, §or[tspr->sectnum], voxrotate[num >> 3] & (1 << (num & 7))); break; } } diff --git a/source/core/rendering/scene/hw_drawstructs.h b/source/core/rendering/scene/hw_drawstructs.h index 06892c6cc..e987adbc7 100644 --- a/source/core/rendering/scene/hw_drawstructs.h +++ b/source/core/rendering/scene/hw_drawstructs.h @@ -327,7 +327,7 @@ public: void CreateVertices(HWDrawInfo* di); void PutSprite(HWDrawInfo *di, bool translucent); void Process(HWDrawInfo *di, spritetype* thing,sectortype * sector, int thruportal = false); - bool ProcessVoxel(HWDrawInfo* di, voxmodel_t* voxel, spritetype* tspr, sectortype* sector); + bool ProcessVoxel(HWDrawInfo* di, voxmodel_t* voxel, spritetype* tspr, sectortype* sector, bool rotate); void DrawSprite(HWDrawInfo* di, FRenderState& state, bool translucent); }; diff --git a/source/core/rendering/scene/hw_sprites.cpp b/source/core/rendering/scene/hw_sprites.cpp index 27b1f2b35..c3a7032c2 100644 --- a/source/core/rendering/scene/hw_sprites.cpp +++ b/source/core/rendering/scene/hw_sprites.cpp @@ -468,7 +468,7 @@ void HWSprite::Process(HWDrawInfo* di, spritetype* spr, sectortype* sector, int // //========================================================================== -bool HWSprite::ProcessVoxel(HWDrawInfo* di, voxmodel_t* vox, spritetype* spr, sectortype* sector) +bool HWSprite::ProcessVoxel(HWDrawInfo* di, voxmodel_t* vox, spritetype* spr, sectortype* sector, bool rotate) { sprite = spr; @@ -481,6 +481,14 @@ bool HWSprite::ProcessVoxel(HWDrawInfo* di, voxmodel_t* vox, spritetype* spr, se visibility = sectorVisibility(sector); voxel = vox; + auto ang = spr->ang; + if ((spr->cstat & CSTAT_SPRITE_MDLROTATE) || rotate) + { + int myclock = (PlayClock << 3) + MulScale(4 << 3, (int)di->Viewpoint.TicFrac, 16); + ang = (ang + myclock) & 2047; // will be applied in md3_vox_calcmat_common. + } + + if (!vox || (spr->cstat & CSTAT_SPRITE_ALIGNMENT) == CSTAT_SPRITE_ALIGNMENT_FLOOR) return false; bool trans = (spr->cstat & CSTAT_SPRITE_TRANSLUCENT); @@ -549,7 +557,7 @@ bool HWSprite::ProcessVoxel(HWDrawInfo* di, voxmodel_t* vox, spritetype* spr, se rotmat.loadIdentity(); rotmat.translate(x + translatevec.X, z - translatevec.Z, y - translatevec.Y); - rotmat.rotate(buildang(spr->ang).asdeg() - 90.f, 0, 1, 0); + rotmat.rotate(buildang(ang).asdeg() - 90.f, 0, 1, 0); rotmat.scale(scalevec.X, scalevec.Z, scalevec.Y); // Apply pivot last rotmat.translate(-voxel->piv.x, zoff, voxel->piv.y);