Correct bug

This commit is contained in:
Miloslav Číž 2020-08-22 19:59:43 +02:00
parent 462b5e4524
commit 68285eebfa
2 changed files with 18 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -26,7 +26,7 @@
author: Miloslav "drummyfish" Ciz author: Miloslav "drummyfish" Ciz
license: CC0 1.0 license: CC0 1.0
version: 0.907 version: 0.908
*/ */
#include <stdint.h> #include <stdint.h>
@ -825,18 +825,21 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc,
#if RCL_RECTILINEAR #if RCL_RECTILINEAR
/* Here we compute the fish eye corrected distance (perpendicular to /* Here we compute the fish eye corrected distance (perpendicular to
the projection plane) as the Euclidean distance divided by the length the projection plane) as the Euclidean distance (of hit from camera
of the ray direction vector. This can be computed without actually position) divided by the length of the ray direction vector. This can
computing Euclidean distances as a hypothenuse A (distance) divided be computed without actually computing Euclidean distances as a
by hypothenuse B (length) is equal to leg A (distance along one axis) hypothenuse A (distance) divided by hypothenuse B (length) is equal to
divided by leg B (length along the same axis). */ leg A (distance along principal axis) divided by leg B (length along
the same principal axis). */
h.distance = #define CORRECT(dir1,dir2)\
(((h.position.x - ray.start.x) / 4) * RCL_Unit tmp = diff / 4; /* 4 to prevent overflow */ \
RCL_UNITS_PER_SQUARE * rayDirXRecip) h.distance = ((tmp / 8) != 0) ? /* prevent a bug with small dists */ \
/ (RECIP_SCALE / 4); ((tmp * RCL_UNITS_PER_SQUARE * rayDir ## dir1 ## Recip) / (RECIP_SCALE / 4)):\
RCL_abs(h.position.dir2 - ray.start.dir2);
CORRECT(X,y)
// ^ / 4 is here to prevent overflow
#endif #endif
} }
else else
@ -856,10 +859,10 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc,
ray.start.x + (ray.direction.x * diff * rayDirYRecip) / RECIP_SCALE; ray.start.x + (ray.direction.x * diff * rayDirYRecip) / RECIP_SCALE;
#if RCL_RECTILINEAR #if RCL_RECTILINEAR
h.distance =
(((h.position.y - ray.start.y) / 4) * CORRECT(Y,x) // same as above but for different axis
RCL_UNITS_PER_SQUARE * rayDirYRecip)
/ (RECIP_SCALE / 4); #undef CORRECT
// ^ / 4 is here to prevent overflow // ^ / 4 is here to prevent overflow
#endif #endif