mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2024-11-27 06:02:18 +00:00
Fix AABB culling bug
This commit is contained in:
parent
2ba2dc7611
commit
e7d64a380a
2 changed files with 36 additions and 50 deletions
|
@ -130,7 +130,7 @@ void PolyCull::MarkSegmentCulled(int x1, int x2)
|
||||||
{
|
{
|
||||||
// Find last segment
|
// Find last segment
|
||||||
int merge = cur;
|
int merge = cur;
|
||||||
while (merge + 1 != SolidSegments.size() && SolidSegments[merge + 1].X1 <= x2)
|
while (merge + 1 != (int)SolidSegments.size() && SolidSegments[merge + 1].X1 <= x2)
|
||||||
merge++;
|
merge++;
|
||||||
|
|
||||||
// Apply new merged range
|
// Apply new merged range
|
||||||
|
@ -168,57 +168,43 @@ bool PolyCull::CheckBBox(float *bspcoord)
|
||||||
|
|
||||||
// Occlusion test using solid segments:
|
// Occlusion test using solid segments:
|
||||||
|
|
||||||
int boxx;
|
static const int lines[4][4] =
|
||||||
int boxy;
|
|
||||||
int boxpos;
|
|
||||||
|
|
||||||
double x1, y1, x2, y2;
|
|
||||||
|
|
||||||
// Find the corners of the box
|
|
||||||
// that define the edges from current viewpoint.
|
|
||||||
if (ViewPos.X <= bspcoord[BOXLEFT])
|
|
||||||
boxx = 0;
|
|
||||||
else if (ViewPos.X < bspcoord[BOXRIGHT])
|
|
||||||
boxx = 1;
|
|
||||||
else
|
|
||||||
boxx = 2;
|
|
||||||
|
|
||||||
if (ViewPos.Y >= bspcoord[BOXTOP])
|
|
||||||
boxy = 0;
|
|
||||||
else if (ViewPos.Y > bspcoord[BOXBOTTOM])
|
|
||||||
boxy = 1;
|
|
||||||
else
|
|
||||||
boxy = 2;
|
|
||||||
|
|
||||||
boxpos = (boxy << 2) + boxx;
|
|
||||||
if (boxpos == 5)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
static const int checkcoord[12][4] =
|
|
||||||
{
|
{
|
||||||
{ 3,0,2,1 },
|
{ BOXLEFT, BOXBOTTOM, BOXRIGHT, BOXBOTTOM },
|
||||||
{ 3,0,2,0 },
|
{ BOXRIGHT, BOXBOTTOM, BOXRIGHT, BOXTOP },
|
||||||
{ 3,1,2,0 },
|
{ BOXRIGHT, BOXTOP, BOXLEFT, BOXTOP },
|
||||||
{ 0 },
|
{ BOXLEFT, BOXTOP, BOXLEFT, BOXBOTTOM }
|
||||||
{ 2,0,2,1 },
|
|
||||||
{ 0,0,0,0 },
|
|
||||||
{ 3,1,3,0 },
|
|
||||||
{ 0 },
|
|
||||||
{ 2,0,3,1 },
|
|
||||||
{ 2,1,3,1 },
|
|
||||||
{ 2,1,3,0 }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
x1 = bspcoord[checkcoord[boxpos][0]];
|
bool foundline = false;
|
||||||
y1 = bspcoord[checkcoord[boxpos][1]];
|
int minsx1, maxsx2;
|
||||||
x2 = bspcoord[checkcoord[boxpos][2]];
|
for (int i = 0; i < 4; i++)
|
||||||
y2 = bspcoord[checkcoord[boxpos][3]];
|
{
|
||||||
|
int j = i < 3 ? i + 1 : 0;
|
||||||
int sx1, sx2;
|
int x1 = bspcoord[lines[i][0]];
|
||||||
if (GetSegmentRangeForLine(x1, y1, x2, y2, sx1, sx2))
|
int y1 = bspcoord[lines[i][1]];
|
||||||
return !IsSegmentCulled(sx1, sx2);
|
int x2 = bspcoord[lines[i][2]];
|
||||||
else
|
int y2 = bspcoord[lines[i][3]];
|
||||||
return true;
|
int sx1, sx2;
|
||||||
|
if (GetSegmentRangeForLine(x1, y1, x2, y2, sx1, sx2))
|
||||||
|
{
|
||||||
|
if (foundline)
|
||||||
|
{
|
||||||
|
minsx1 = MIN(minsx1, sx1);
|
||||||
|
maxsx2 = MAX(maxsx2, sx2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
minsx1 = sx1;
|
||||||
|
maxsx2 = sx2;
|
||||||
|
foundline = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundline)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return !IsSegmentCulled(minsx1, maxsx2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PolyCull::GetSegmentRangeForLine(double x1, double y1, double x2, double y2, int &sx1, int &sx2) const
|
bool PolyCull::GetSegmentRangeForLine(double x1, double y1, double x2, double y2, int &sx1, int &sx2) const
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
|
|
||||||
void SetTexture(FTexture *texture, uint32_t translationID)
|
void SetTexture(FTexture *texture, uint32_t translationID)
|
||||||
{
|
{
|
||||||
if (translationID != -1 && translationID != 0)
|
if (translationID != 0xffffffff && translationID != 0)
|
||||||
{
|
{
|
||||||
FRemapTable *table = TranslationToTable(translationID);
|
FRemapTable *table = TranslationToTable(translationID);
|
||||||
if (table != nullptr && !table->Inactive)
|
if (table != nullptr && !table->Inactive)
|
||||||
|
|
Loading…
Reference in a new issue