diff --git a/src/r_poly.cpp b/src/r_poly.cpp index e9edacae1..184498692 100644 --- a/src/r_poly.cpp +++ b/src/r_poly.cpp @@ -152,9 +152,9 @@ void RenderPolyBsp::RenderSubsector(subsector_t *sub) for (AActor *thing = sub->sector->thinglist; thing != nullptr; thing = thing->snext) { if ((thing->renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE) - AddWallSprite(thing); + AddWallSprite(thing, sub); else - AddSprite(thing); + AddSprite(thing, sub); } } @@ -273,7 +273,7 @@ bool RenderPolyBsp::IsThingCulled(AActor *thing) return false; } -void RenderPolyBsp::AddSprite(AActor *thing) +void RenderPolyBsp::AddSprite(AActor *thing, subsector_t *sub) { if (IsThingCulled(thing)) return; @@ -308,6 +308,20 @@ void RenderPolyBsp::AddSprite(AActor *thing) { pos.X + ViewSin * spriteHalfWidth, pos.Y - ViewCos * spriteHalfWidth } }; + // Is this sprite inside? (To do: clip the points) + for (int i = 0; i < 2; i++) + { + for (uint32_t i = 0; i < sub->numlines; i++) + { + seg_t *line = &sub->firstline[i]; + double nx = line->v1->fY() - line->v2->fY(); + double ny = line->v2->fX() - line->v1->fX(); + double d = -(line->v1->fX() * nx + line->v1->fY() * ny); + if (pos.X * nx + pos.Y * ny + d > 0.0) + return; + } + } + //double depth = 1.0; //visstyle_t visstyle = GetSpriteVisStyle(thing, depth); // Rumor has it that AlterWeaponSprite needs to be called with visstyle passed in somewhere around here.. @@ -347,7 +361,7 @@ void RenderPolyBsp::AddSprite(AActor *thing) TriangleDrawer::draw(worldToClip, vertices, 4, TriangleDrawMode::Fan, false, 0, viewwidth, cliptop, clipbottom, tex); } -void RenderPolyBsp::AddWallSprite(AActor *thing) +void RenderPolyBsp::AddWallSprite(AActor *thing, subsector_t *sub) { if (IsThingCulled(thing)) return; diff --git a/src/r_poly.h b/src/r_poly.h index 1baaeddfb..cd1cd1215 100644 --- a/src/r_poly.h +++ b/src/r_poly.h @@ -62,8 +62,8 @@ private: void AddLine(seg_t *line, sector_t *frontsector); TriVertex PlaneVertex(vertex_t *v1, sector_t *sector, const secplane_t &plane); - void AddSprite(AActor *thing); - void AddWallSprite(AActor *thing); + void AddSprite(AActor *thing, subsector_t *sub); + void AddWallSprite(AActor *thing, subsector_t *sub); bool IsThingCulled(AActor *thing); visstyle_t GetSpriteVisStyle(AActor *thing, double z); FTexture *GetSpriteTexture(AActor *thing, /*out*/ bool &flipX);