- added spriteGetZOfSlopeF for the backend

This commit is contained in:
Christoph Oelckers 2022-09-16 19:30:48 +02:00
parent fd4f04b5fd
commit cbfc9a8252
5 changed files with 21 additions and 21 deletions

View file

@ -59,6 +59,15 @@ static inline void get_floorspr_points(DCoreActor *spr, int32_t px, int32_t py,
}
inline int32_t spriteGetZOfSlope(const spritetypebase* tspr, int dax, int day, int heinum)
{
if (heinum == 0) return tspr->int_pos().Z;
int const j = DMulScale(bsin(tspr->int_ang() + 1024), day - tspr->int_pos().Y, -bsin(tspr->int_ang() + 512), dax - tspr->int_pos().X, 4);
return tspr->int_pos().Z + MulScale(heinum, j, 18);
}
//
// clipinsideboxline
//

View file

@ -461,12 +461,12 @@ inline int tspriteGetSlope(const tspritetype* spr)
return !(spr->clipdist & TSPR_SLOPESPRITE) ? 0 : uint8_t(spr->xoffset) + (int8_t(spr->yoffset) << 8);
}
inline int32_t spriteGetZOfSlope(const spritetypebase* tspr, int dax, int day, int heinum)
inline double spriteGetZOfSlopef(const spritetypebase* tspr, const DVector2& pos, int heinum)
{
if (heinum == 0) return tspr->int_pos().Z;
int const j = DMulScale(bsin(tspr->int_ang() + 1024), day - tspr->int_pos().Y, -bsin(tspr->int_ang() + 512), dax - tspr->int_pos().X, 4);
return tspr->int_pos().Z + MulScale(heinum, j, 18);
if (heinum == 0) return tspr->pos.Z;
auto ang = tspr->angle;
double factor = -ang.Sin() * (pos.X - tspr->pos.Y) - ang.Cos() * (pos.X - tspr->pos.X);
return tspr->pos.Z + heinum * factor * (1./4096.);
}
inline int inside(int x, int y, const sectortype* sect)

View file

@ -146,7 +146,6 @@ void HWDrawInfo::StartScene(FRenderViewpoint& parentvp, HWViewpointUniforms* uni
VPUniforms.mClipLine.X = -10000000.0f;
VPUniforms.mShadowmapFilter = gl_shadowmap_filter;
}
vec2_t view = { int(Viewpoint.Pos.X * 16), int(Viewpoint.Pos.Y * -16) };
ClearBuffers();

View file

@ -133,18 +133,16 @@ void HWFlat::MakeVertices(HWDrawInfo* di)
float y = !(Sprite->cstat & CSTAT_SPRITE_YFLIP) ? 0.f : 1.f;
if (Sprite->clipdist & TSPR_SLOPESPRITE)
{
int posx = int(di->Viewpoint.Pos.X * 16.f);
int posy = int(di->Viewpoint.Pos.Y * -16.f);
int posz = int(di->Viewpoint.Pos.Z * -256.f);
DVector3 posi = { di->Viewpoint.Pos.X, -di->Viewpoint.Pos.Y, -di->Viewpoint.Pos.Z };
// Make adjustments for poorly aligned slope sprites on floors or ceilings
constexpr float ONPLANE_THRESHOLD = 3.f;
if (spriteGetZOfSlope(Sprite, posx, posy, tspriteGetSlope(Sprite)) < posz)
if (spriteGetZOfSlopef(Sprite, posi.XY(), tspriteGetSlope(Sprite)) < posi.Z)
{
float maxofs = -FLT_MAX, minofs = FLT_MAX;
for (int i = 0; i < 4; i++)
{
float vz = -getceilzofslopeptrf(Sprite->sectp, pos[i].X, pos[i].Y);
float vz = -getceilzofslopeptrf(Sprite->sectp, posi);
float sz = z - ofsz[i];
int diff = vz - sz;
if (diff > maxofs) maxofs = diff;
@ -157,7 +155,7 @@ void HWFlat::MakeVertices(HWDrawInfo* di)
float maxofs = -FLT_MAX, minofs = FLT_MAX;
for (int i = 0; i < 4; i++)
{
float vz = -getflorzofslopeptrf(Sprite->sectp, pos[i].X, pos[i].Y);
float vz = -getflorzofslopeptrf(Sprite->sectp, posi);
float sz = z - ofsz[i];
int diff = vz - sz;
if (diff > maxofs) maxofs = diff;
@ -435,8 +433,9 @@ void HWFlat::ProcessFlatSprite(HWDrawInfo* di, tspritetype* sprite, sectortype*
// Weird Build logic that really makes no sense.
if ((sprite->cstat & CSTAT_SPRITE_ONE_SIDE) != 0)
{
double myz = !(sprite->clipdist & TSPR_SLOPESPRITE) ? z :
spriteGetZOfSlope(sprite, int(di->Viewpoint.Pos.X * 16), int(di->Viewpoint.Pos.Y * -16), tspriteGetSlope(sprite)) * -(1. / 256.);
DVector2 pos = { di->Viewpoint.Pos.X, -di->Viewpoint.Pos.Y };
double myz = !(sprite->clipdist & TSPR_SLOPESPRITE) ? z : -spriteGetZOfSlopef(sprite, pos, tspriteGetSlope(sprite));
if ((di->Viewpoint.Pos.Z < myz) == ((sprite->cstat & CSTAT_SPRITE_YFLIP) == 0))
return;
}

View file

@ -231,14 +231,7 @@ public:
struct HWLinePortal : public HWScenePortalBase
{
protected:
// this must be the same as at the start of line_t, so that we can pass in this structure directly to P_ClipLineToPortal.
walltype* line;
/*
vec2_t *v1, *v2; // vertices, from v1 to v2
DVector2 delta; // precalculated v2 - v1 for side checking
angle_t angv1, angv2; // for quick comparisons with a line or subsector
*/
HWLinePortal(FPortalSceneState *state, walltype *line) : HWScenePortalBase(state)
{