Extract flat rotation from SetPlaneTextureRotation

This commit is contained in:
RaveYard 2023-09-20 16:50:37 +02:00 committed by Christoph Oelckers
parent 29b8fcf6c8
commit ccc4d6c7e0
3 changed files with 42 additions and 22 deletions

View file

@ -1016,6 +1016,11 @@ public:
return pos == floor? floorplane:ceilingplane;
}
const secplane_t& GetSecPlane(int pos) const
{
return pos == floor ? floorplane : ceilingplane;
}
bool isSecret() const
{
return !!(Flags & SECF_SECRET);

View file

@ -79,7 +79,7 @@ struct HWSectorPlane
FVector2 Offs;
FVector2 Scale;
void GetFromSector(sector_t * sec, int ceiling)
void GetFromSector(const sector_t * sec, int ceiling)
{
Offs.X = (float)sec->GetXOffset(ceiling);
Offs.Y = (float)sec->GetYOffset(ceiling);

View file

@ -57,6 +57,41 @@ CVAR(Int, gl_breaksec, -1, 0)
//
//==========================================================================
VSMatrix GetPlaneTextureRotationMatrix(FGameTexture* gltexture, const FVector2& uvOffset, float angle, const FVector2& scale)
{
float uoffs = uvOffset.X / gltexture->GetDisplayWidth();
float voffs = uvOffset.Y / gltexture->GetDisplayHeight();
float yscale1 = scale.Y;
if (gltexture->isHardwareCanvas())
{
yscale1 = 0 - yscale1;
}
float xscale2 = 64.f / gltexture->GetDisplayWidth();
float yscale2 = 64.f / gltexture->GetDisplayHeight();
VSMatrix mat;
mat.loadIdentity();
mat.scale(scale.X, yscale1, 1.0f);
mat.translate(uoffs, voffs, 0.0f);
mat.scale(xscale2, yscale2, 1.0f);
mat.rotate(angle, 0.0f, 0.0f, 1.0f);
return mat;
}
VSMatrix GetPlaneTextureRotationMatrix(FGameTexture* gltexture, const HWSectorPlane& secplane)
{
return GetPlaneTextureRotationMatrix(gltexture, secplane.Offs, -secplane.Angle, secplane.Scale);
}
VSMatrix GetPlaneTextureRotationMatrix(FGameTexture* gltexture, const sector_t* sector, int plane)
{
HWSectorPlane splane;
splane.GetFromSector(sector, plane);
return GetPlaneTextureRotationMatrix(gltexture, splane);
}
bool SetPlaneTextureRotation(FRenderState& state, HWSectorPlane* secplane, FGameTexture* gltexture)
{
// only manipulate the texture matrix if needed.
@ -66,27 +101,7 @@ bool SetPlaneTextureRotation(FRenderState& state, HWSectorPlane* secplane, FGame
gltexture->GetDisplayWidth() != 64 ||
gltexture->GetDisplayHeight() != 64)
{
float uoffs = secplane->Offs.X / gltexture->GetDisplayWidth();
float voffs = secplane->Offs.Y / gltexture->GetDisplayHeight();
float xscale1 = secplane->Scale.X;
float yscale1 = secplane->Scale.Y;
if (gltexture->isHardwareCanvas())
{
yscale1 = 0 - yscale1;
}
float angle = -secplane->Angle;
float xscale2 = 64.f / gltexture->GetDisplayWidth();
float yscale2 = 64.f / gltexture->GetDisplayHeight();
VSMatrix mat;
mat.loadIdentity();
mat.scale(xscale1, yscale1, 1.0f);
mat.translate(uoffs, voffs, 0.0f);
mat.scale(xscale2, yscale2, 1.0f);
mat.rotate(angle, 0.0f, 0.0f, 1.0f);
state.SetTextureMatrix(mat);
state.SetTextureMatrix(GetPlaneTextureRotationMatrix(gltexture, *secplane));
return true;
}
return false;