mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-19 18:41:28 +00:00
Merge branch 'fix-slope-convex-sectors' into 'next'
Fix physics quirkiness on slopes with convex sectors See merge request STJr/SRB2!2250
This commit is contained in:
commit
bae687a1b9
1 changed files with 29 additions and 12 deletions
41
src/r_main.c
41
src/r_main.c
|
@ -1023,26 +1023,43 @@ void R_Init(void)
|
||||||
boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y)
|
boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
line_t *closest = NULL;
|
size_t passes = 0;
|
||||||
fixed_t closestdist = INT32_MAX;
|
|
||||||
|
|
||||||
for (i = 0; i < sector->linecount; i++)
|
for (i = 0; i < sector->linecount; i++)
|
||||||
{
|
{
|
||||||
vertex_t v;
|
line_t *line = sector->lines[i];
|
||||||
fixed_t dist;
|
vertex_t *v1, *v2;
|
||||||
|
|
||||||
// find the line closest to the point we're looking for.
|
if (line->frontsector == line->backsector)
|
||||||
P_ClosestPointOnLine(x, y, sector->lines[i], &v);
|
continue;
|
||||||
dist = R_PointToDist2(0, 0, v.x - x, v.y - y);
|
|
||||||
if (dist < closestdist)
|
v1 = line->v1;
|
||||||
|
v2 = line->v2;
|
||||||
|
|
||||||
|
// make sure v1 is below v2
|
||||||
|
if (v1->y > v2->y)
|
||||||
{
|
{
|
||||||
closest = sector->lines[i];
|
vertex_t *tmp = v1;
|
||||||
closestdist = dist;
|
v1 = v2;
|
||||||
|
v2 = tmp;
|
||||||
|
}
|
||||||
|
else if (v1->y == v2->y)
|
||||||
|
// horizontal line, we can't match this
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (v1->y < y && y <= v2->y)
|
||||||
|
{
|
||||||
|
// if the y axis in inside the line, find the point where we intersect on the x axis...
|
||||||
|
fixed_t vx = v1->x + (INT64)(v2->x - v1->x) * (y - v1->y) / (v2->y - v1->y);
|
||||||
|
|
||||||
|
// ...and if that point is to the left of the point, count it as inside.
|
||||||
|
if (vx < x)
|
||||||
|
passes++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the side of the closest line is in this sector, we're inside of it.
|
// and odd number of passes means we're inside the polygon.
|
||||||
return P_PointOnLineSide(x, y, closest) == 0 ? closest->frontsector == sector : closest->backsector == sector;
|
return passes % 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue