diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index cf8392e8bb..e6f40dd0d3 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -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); diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index bef85dccfd..1791808846 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -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); diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 01f62bb5da..d11bbe8868 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -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;