diff --git a/src/r_main.c b/src/r_main.c index 12022b068..8e5d8dc83 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -437,19 +437,32 @@ angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) 0; } +// +// R_PointToPseudoAngle +// ! Returns the pseudoangle between the line p1 to (infinity, p1.y) and the +// line from p1 to p2. The pseudoangle has the property that the ordering of +// points by true angle anround p1 and ordering of points by pseudoangle are the +// same. +// +// For clipping exact angles are not needed. Only the ordering matters. +// This is about as fast as the fixed point R_PointToAngle2 but without +// the precision issues associated with that function. +// + FUNCINLINE ATTRINLINE angle_t R_PointToPseudoAngle (fixed_t x, fixed_t y) { // Note: float won't work here as it's less precise than the BAM values being passed as parameters - INT64 vecx = x - viewx; - INT64 vecy = y - viewy; + double vecx = (double)x - viewx; + double vecy = (double)y - viewy; + double epsilon = 1e-9; - if (vecx == 0 && vecy == 0) + if (fabs(vecx) < epsilon && fabs(vecy) < epsilon) { return 0; } else { - double result = vecy / (vecx + vecy); + double result = vecy / (fabs(vecx) + fabs(vecy)); if (vecx < 0) { result = 2.0 - result;