- voxel rotation.

This commit is contained in:
Christoph Oelckers 2021-04-04 13:24:33 +02:00
parent 55ad51ee1f
commit d76c2ccc34
3 changed files with 15 additions and 5 deletions

View file

@ -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, &sector[tspr->sectnum])) return;
int num = tiletovox[tspr->picnum];
if (hwsprite.ProcessVoxel(this, voxmodels[tiletovox[tspr->picnum]], tspr, &sector[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, &sector[tspr->sectnum]);
int num = tspr->picnum;
hwsprite.ProcessVoxel(this, voxmodels[tspr->picnum], tspr, &sector[tspr->sectnum], voxrotate[num >> 3] & (1 << (num & 7)));
break;
}
}

View file

@ -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);
};

View file

@ -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);