From f09006066dd542e4b90a808abc603b8739143470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Tue, 25 Feb 2020 17:04:11 +0100 Subject: [PATCH] Ugly hack fix --- raycastlib.h | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index b577b5d..2974426 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -844,7 +844,7 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc, RCL_Unit diff = h.position.x - ray.start.x; h.position.y = // avoid division by multiplying with reciprocal - ray.start.y + ((ray.direction.y * diff) * rayDirXRecip) / RECIP_SCALE; + ray.start.y + (ray.direction.y * diff * rayDirXRecip) / RECIP_SCALE; #if RCL_RECTILINEAR /* Here we compute the fish eye corrected distance (perpendicular to @@ -876,7 +876,7 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc, RCL_Unit diff = h.position.y - ray.start.y; h.position.x = - ray.start.x + ((ray.direction.x * diff) * rayDirYRecip) / RECIP_SCALE; + ray.start.x + (ray.direction.x * diff * rayDirYRecip) / RECIP_SCALE; #if RCL_RECTILINEAR h.distance = @@ -1202,6 +1202,20 @@ static inline int16_t _RCL_drawWall( RCL_Unit textureCoordScaled = pixelInfo->texCoords.y; +#if RCL_RECTILINEAR + RCL_Unit tmp = pixelInfo->depth; + pixelInfo->depth = (pixelInfo->depth * 23) / 32; + + /* ^ UGLY HACK + + For some reason the computed distance with rectilinear is larger, the + correct distance is about 0.711 (~= 23/32) of the computed distance, so + we correct it here in this ugly way. + + TODO: investigate why, fix nicely + */ +#endif + for (RCL_Unit i = yCurrent + increment; increment == -1 ? i >= limit : i <= limit; // TODO: is efficient? i += increment) @@ -1217,7 +1231,11 @@ static inline int16_t _RCL_drawWall( RCL_PIXEL_FUNCTION(pixelInfo); } - + +#if RCL_RECTILINEAR + pixelInfo->depth = tmp; +#endif + return limit; } @@ -1680,8 +1698,7 @@ RCL_PixelInfo RCL_mapToScreen(RCL_Vector2D worldPosition, RCL_Unit height, middleColumn + (-1 * toPoint.y * middleColumn) / RCL_nonZero(result.depth); result.position.y = camera.resolution.y / 2 - -(((3 * camera.resolution.y) / 4 ) * -// ((camera.resolution.y / 2) * + (((3 * camera.resolution.y) / 4 ) * RCL_perspectiveScale(height - camera.height,result.depth)) / RCL_UNITS_PER_SQUARE + camera.shear;