From a5b5d6d43e0175ba38b33353465d2e069f2e9ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 28 Sep 2018 17:07:32 +0200 Subject: [PATCH] Adjust floor texturing --- raycastlib.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index ae5e593..35369e2 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -1102,7 +1102,7 @@ static inline int16_t _RCL_drawHorizontal( {\ dx = pixelInfo->hit.position.x - _RCL_camera.position.x;\ dy = pixelInfo->hit.position.y - _RCL_camera.position.y;\ - pixPos = yCurrent - _RCL_middleRow - 1;\ + pixPos = yCurrent - _RCL_middleRow;\ rayCameraCos = RCL_vectorsAngleCos(\ RCL_angleToDirection(_RCL_camera.direction),ray->direction);\ }\ @@ -1589,16 +1589,11 @@ void RCL_renderSimple(RCL_Camera cam, RCL_ArrayFunction floorHeightFunc, this will contain precomputed distance to the camera */ RCL_Unit camHeightScreenSize = -#ifdef RCL_RAYCAST_TINY - (cam.height -#else - (((cam.height >> 6) << 6) // prevent weird floor movement with rounding -#endif - * cam.resolution.y) / RCL_UNITS_PER_SQUARE; + (cam.height * cam.resolution.y) / RCL_UNITS_PER_SQUARE; for (uint16_t i = 0; i < halfResY; ++i) // precompute the distances floorPixelDistances[i] = - RCL_perspectiveScaleInverse(camHeightScreenSize,i); + RCL_perspectiveScaleInverse(camHeightScreenSize,i + 1); // pass to _RCL_columnFunctionSimple _RCL_floorPixelDistances = floorPixelDistances; @@ -1700,9 +1695,10 @@ RCL_Unit RCL_perspectiveScaleInverse(RCL_Unit originalSize, RCL_Unit scaledSize) { return scaledSize != 0 ? - (originalSize * RCL_UNITS_PER_SQUARE) / + (originalSize * RCL_UNITS_PER_SQUARE + RCL_UNITS_PER_SQUARE / 2) / + // ^ take the middle ((RCL_VERTICAL_FOV * 2 * scaledSize) / RCL_UNITS_PER_SQUARE) - : 0; + : RCL_INFINITY; } void RCL_moveCameraWithCollision(RCL_Camera *camera, RCL_Vector2D planeOffset,