mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 22:11:43 +00:00
- fixed the center point calculation for triangular sectors.
The old method does not work as expected with the higher precision of doubles, so instead just average the 3 vertex positions to get the triangle's center.
This commit is contained in:
parent
56508a2d82
commit
cebd877191
1 changed files with 15 additions and 33 deletions
|
@ -3192,51 +3192,33 @@ static void P_GroupLines (bool buildmap)
|
|||
{
|
||||
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)
|
||||
{
|
||||
li = sector->lines[j];
|
||||
bbox.AddToBox (li->v1->fPos());
|
||||
bbox.AddToBox (li->v2->fPos());
|
||||
}
|
||||
bbox.AddToBox(li->v1->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)
|
||||
{
|
||||
// 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)
|
||||
DVector2 pos = { 0,0 };
|
||||
for (int i = 0; i < sector->linecount; i++)
|
||||
{
|
||||
vertex_t *Triangle[2];
|
||||
Triangle[0] = sector->lines[0]->v1;
|
||||
Triangle[1] = sector->lines[0]->v2;
|
||||
if (sector->linecount > 1)
|
||||
{
|
||||
double dx = Triangle[1]->fX() - Triangle[0]->fX();
|
||||
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;
|
||||
pos += sector->lines[i]->v1->fPos() + sector->lines[i]->v2->fPos();
|
||||
}
|
||||
sector->centerspot = pos / (2 * sector->linecount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
delete[] linesDoneInEachSector;
|
||||
times[3].Unclock();
|
||||
|
||||
|
|
Loading…
Reference in a new issue