Revert "use vectors P_ClosestPointOnLine3D and kill vertex z"

This reverts commit e0ae6aa85c.
This commit is contained in:
Alug committed 2025-03-10 12:31:44 +01:00
1 parent 801d1a3056
commit 5c2adca262
5 files changed
+72 -39

No files matched your search

+2 -1
View File
@@ -860,7 +860,8 @@ static int vertex_get(lua_State *L)
lua_pushfixed(L, vertex->y);
return 1;
case vertex_z:
return luaL_error(L, "accessed vertex_t doesn't exist anymore.");
lua_pushfixed(L, vertex->z);
return 1;
}
return 0;
}
+44 -17
View File
@@ -69,37 +69,64 @@ void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result)
// P_ClosestPointOnLine3D
// Finds the closest point on a given line to the supplied point IN 3D!!!
//
/// Similar to FV3_ClosestPointOnLine() except it actually works.
void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *Line, vector3_t *result)
void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, vertex_t *result)
{
const vector3_t* v1 = &Line[0];
const vector3_t* v2 = &Line[1];
vector3_t c, V, n;
fixed_t t, d;
FV3_SubEx(v2, v1, &V);
FV3_SubEx(p, v1, &c);
fixed_t startx = line->v1->x;
fixed_t starty = line->v1->y;
fixed_t startz = line->v1->z;
fixed_t dx = line->dx;
fixed_t dy = line->dy;
fixed_t dz = line->v2->z - line->v1->z;
d = R_PointToDist2(0, v2->z, R_PointToDist2(v2->x, v2->y, v1->x, v1->y), v1->z);
FV3_Copy(&n, &V);
FV3_Divide(&n, d);
// Determine t (the length of the vector from �Line[0]� to �p�)
fixed_t cx, cy, cz;
fixed_t vx, vy, vz;
fixed_t magnitude;
fixed_t t;
t = FV3_Dot(&n, &c);
//Sub (p, &Line[0], &c);
cx = x - startx;
cy = y - starty;
cz = z - startz;
//Sub (&Line[1], &Line[0], &V);
vx = dx;
vy = dy;
vz = dz;
//Normalize (&V, &V);
magnitude = R_PointToDist2(0, line->v2->z, R_PointToDist2(line->v2->x, line->v2->y, startx, starty), startz);
vx = FixedDiv(vx, magnitude);
vy = FixedDiv(vy, magnitude);
vz = FixedDiv(vz, magnitude);
t = (FixedMul(vx, cx) + FixedMul(vy, cy) + FixedMul(vz, cz));
// Set closest point to the end if it extends past -Red
if (t <= 0)
{
FV3_Copy(result, v1);
result->x = line->v1->x;
result->y = line->v1->y;
result->z = line->v1->z;
return;
}
else if (t >= d)
else if (t >= magnitude)
{
FV3_Copy(result, v2);
result->x = line->v2->x;
result->y = line->v2->y;
result->z = line->v2->z;
return;
}
FV3_Mul(&n, t);
// Return the point between �Line[0]� and �Line[1]�
vx = FixedMul(vx, t);
vy = FixedMul(vy, t);
vz = FixedMul(vz, t);
FV3_AddEx(v1, &n, result);
//Add (&Line[0], &V, out);
result->x = startx + vx;
result->y = starty + vy;
result->z = startz + vz;
return;
}
+1 -1
View File
@@ -43,7 +43,7 @@ boolean P_PathTraverse(fixed_t px1, fixed_t py1, fixed_t px2, fixed_t py2,
#define P_AproxDistance(dx, dy) FixedHypot(dx, dy)
void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result);
void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *line, vector3_t *result);
void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, vertex_t *result);
INT32 P_PointOnLineSide(fixed_t x, fixed_t y, const line_t *line);
void P_MakeDivline(line_t *li, divline_t *dl);
void P_CameraLineOpening(line_t *plinedef);
+24 -19
View File
@@ -3983,7 +3983,8 @@ DoneSection2:
mobj_t *waypointhigh = NULL;
mobj_t *waypointlow = NULL;
mobj_t *closest = NULL;
vector3_t p, line[2], resulthigh, resultlow;
line_t junk;
vertex_t v1, v2, resulthigh, resultlow;
if (player->mo->tracer && player->mo->tracer->type == MT_TUBEWAYPOINT)
break;
@@ -4041,34 +4042,38 @@ DoneSection2:
// Next, we need to find the closest point on the line between each set, and determine which one we're
// closest to.
p.x = player->mo->x;
p.y = player->mo->y;
p.z = player->mo->z;
// Waypointmid and Waypointlow:
if (waypointlow)
{
line[0].x = waypointmid->x;
line[0].y = waypointmid->y;
line[0].z = waypointmid->z;
line[1].x = waypointlow->x;
line[1].y = waypointlow->y;
line[1].z = waypointlow->z;
v1.x = waypointmid->x;
v1.y = waypointmid->y;
v1.z = waypointmid->z;
v2.x = waypointlow->x;
v2.y = waypointlow->y;
v2.z = waypointlow->z;
junk.v1 = &v1;
junk.v2 = &v2;
junk.dx = v2.x - v1.x;
junk.dy = v2.y - v1.y;
P_ClosestPointOnLine3D(&p, line, &resultlow);
P_ClosestPointOnLine3D(player->mo->x, player->mo->y, player->mo->z, &junk, &resultlow);
}
// Waypointmid and Waypointhigh:
if (waypointhigh)
{
line[0].x = waypointmid->x;
line[0].y = waypointmid->y;
line[0].z = waypointmid->z;
line[1].x = waypointhigh->x;
line[1].y = waypointhigh->y;
line[1].z = waypointhigh->z;
v1.x = waypointmid->x;
v1.y = waypointmid->y;
v1.z = waypointmid->z;
v2.x = waypointhigh->x;
v2.y = waypointhigh->y;
v2.z = waypointhigh->z;
junk.v1 = &v1;
junk.v2 = &v2;
junk.dx = v2.x - v1.x;
junk.dy = v2.y - v1.y;
P_ClosestPointOnLine3D(&p, line, &resulthigh);
P_ClosestPointOnLine3D(player->mo->x, player->mo->y, player->mo->z, &junk, &resulthigh);
}
// 3D support now available. Disregard the previous notice here. -Red
+1 -1
View File
@@ -76,7 +76,7 @@ typedef struct
*/
typedef struct
{
fixed_t x, y;
fixed_t x, y, z;
} vertex_t;
// Forward of linedefs, for sectors.