This commit is contained in:
Christoph Oelckers 2016-06-19 11:53:17 +02:00
commit b364926e93

View file

@ -3192,50 +3192,32 @@ static void P_GroupLines (bool buildmap)
{ {
if (linesDoneInEachSector[i] != sector->linecount) if (linesDoneInEachSector[i] != sector->linecount)
{ {
I_Error ("P_GroupLines: miscounted"); I_Error("P_GroupLines: miscounted");
} }
if (sector->linecount != 0) if (sector->linecount > 3)
{ {
bbox.ClearBox (); bbox.ClearBox();
for (j = 0; j < sector->linecount; ++j) for (j = 0; j < sector->linecount; ++j)
{ {
li = sector->lines[j]; li = sector->lines[j];
bbox.AddToBox (li->v1->fPos()); bbox.AddToBox(li->v1->fPos());
bbox.AddToBox (li->v2->fPos()); bbox.AddToBox(li->v2->fPos());
} }
// set the center to the middle of the bounding box
sector->centerspot.X = (bbox.Right() + bbox.Left()) / 2;
sector->centerspot.Y = (bbox.Top() + bbox.Bottom()) / 2;
} }
else if (sector->linecount > 0)
// set the center to the middle of the bounding box
sector->centerspot.X = (bbox.Right() + bbox.Left()) / 2;
sector->centerspot.Y = (bbox.Top() + bbox.Bottom()) / 2;
// For triangular sectors the above does not calculate good points unless the longest of the triangle's lines is perfectly horizontal and vertical
if (sector->linecount == 3)
{ {
vertex_t *Triangle[2]; // For triangular sectors the above does not calculate good points unless the longest of the triangle's lines is perfectly horizontal and vertical
Triangle[0] = sector->lines[0]->v1; DVector2 pos = { 0,0 };
Triangle[1] = sector->lines[0]->v2; for (int i = 0; i < sector->linecount; i++)
if (sector->linecount > 1)
{ {
double dx = Triangle[1]->fX() - Triangle[0]->fX(); pos += sector->lines[i]->v1->fPos() + sector->lines[i]->v2->fPos();
double dy = Triangle[1]->fY() - Triangle[0]->fY();
// Find another point in the sector that does not lie
// on the same line as the first two points.
for (j = 0; j < 2; ++j)
{
vertex_t *v;
v = (j == 1) ? sector->lines[1]->v1 : sector->lines[1]->v2;
if ( (v->fY() - Triangle[0]->fY()) * dx + (Triangle[0]->fX() - v->fX() * dy) != 0)
{
sector->centerspot.X = (Triangle[0]->fX() / 3 + Triangle[1]->fX() / 3 + v->fX() / 3);
sector->centerspot.Y = (Triangle[0]->fY() / 3 + Triangle[1]->fY() / 3 + v->fY() / 3);
break;
}
}
} }
sector->centerspot = pos / (2 * sector->linecount);
} }
} }
delete[] linesDoneInEachSector; delete[] linesDoneInEachSector;
times[3].Unclock(); times[3].Unclock();