From 0d4eabc93c4b47f310bdec1c627471532709c210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 31 Oct 2020 17:56:04 +0100 Subject: [PATCH] Fix mapping bug --- programs/test.c | 163 +++++++++++++++++++++++---------------------- programs/testSDL.c | 4 +- raycastlib.h | 82 ++++++++++++++++------- 3 files changed, 143 insertions(+), 106 deletions(-) diff --git a/programs/test.c b/programs/test.c index 54dee80..0ec4927 100644 --- a/programs/test.c +++ b/programs/test.c @@ -13,88 +13,89 @@ #include static const char renderSimpleExpect[] = - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,DD,,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EEEEEDD,,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EEEEEEEEDD,,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EEEEEEEEEEEEEDD,,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFEEEEEEEEEEEEEEEDD,,,,,,,,,"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eeefffffffffffffggggggg,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiii,FFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhi.....FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhh..........FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggg...............FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffg.....................FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffff..........................FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeeeeeffff.................................FFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeeeeeeee............................................EEEEEEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeeeeeeee.....................................................EEEEEEEEEEDDDDDDDDDDD" - "dddddddddddddddeeeeee..............................................................EEEEEEDDDDDDDDDDD" - "ddddddddddddddde.......................................................................EEDDDDDDDDDDD" - "ddddddddddd.................................................................................DDDDDDDD" - "ddddddd........................................................................................DDDDD"; +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EEDD,,,,,,,,,"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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," +"dddddddddddddddeeeeeeeeeeeeeeee,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffg,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhi,,,,,FFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDD,,,,,,,,," +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhii....FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhh.........FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggg...............FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffg.....................FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeeffffffff...........................FFFFFFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeeeeeeff.....................................FFEEEEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeeeeeeee..............................................EEEEEEEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeeeeeeeeee........................................................EEEEEEEEDDDDDDDDDDD" +"dddddddddddddddeee....................................................................EEEDDDDDDDDDDD" +"ddddddddddddd.............................................................................DDDDDDDDDD" +"ddddddd........................................................................................DDDDD" +"dd.................................................................................................D" +"...................................................................................................."; + static const char renderComplexExpect[] = - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,DD,,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EEEEEDDe,,,,,,,," - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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,," - "dddddddddddddddeeeeeeee,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeef,,,," - "dddddddddddddddeeeeeeeeeeeeeeeeeeffff,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeef,,,," - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffgggggg,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeef,GGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiii,FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhi.....FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhh..........FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffgggggg................FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" - "dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffg.....................FFFFFFEEEEEEEEEEEEEEEDDeeeef...." - "dddddddddddddddeeeeeeeeeeeeeeeeeeffffffff...........................FFFFFFEEEEEEEEEEEEEEEDDeeeef...." - "dddddddddddddddeeeeeeeeeeeeeeeeeefff...................................FFFEEEEEEEEEEEEEEEDDeeeef...." - "dddddddddddddddeeeeeeeeeeeeeeee............................................EEEEEEEEEEEEEEDDeeeefFFFE" - "dddddddddddddddeeeeeeeeeee.....................................................EEEEEEEEEEDDeeeefFFFE" - "dddddddddddddddeeeee................................................................EEEEEDDeeee....E" - "ddddddddddddddd..........................................................................DDeee......" - "ddddddddddd.................................................................................e......." - "dddd................................................................................................"; +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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EEEEEEDDeeeef,,,," +",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeef,,,," +"ddddddddddddddd,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeef,,,," +"dddddddddddddddeeeeeeeeeeeeeee,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeef,,,," +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffff,,,,,,,,,,,,,,,,,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeef,,,," +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhh,,,,,,FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhiiiiiiFFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhhhhhhii....FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffggggggggghhh..........FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffgggggg................FFFFFFEEEEEEEEEEEEEEEDDeeeefGGGG" +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffffffffffg.....................FFFFFFEEEEEEEEEEEEEEEDDeeeef...." +"dddddddddddddddeeeeeeeeeeeeeeeeeefffffff............................FFFFFFEEEEEEEEEEEEEEEDDeeeef...." +"dddddddddddddddeeeeeeeeeeeeeeeeeeff.....................................FFEEEEEEEEEEEEEEEDDeeeefF..." +"dddddddddddddddeeeeeeeeeeeeee................................................EEEEEEEEEEEEDDeeeefFFFE" +"dddddddddddddddeeeeeeee...........................................................EEEEEEEDDeeeefFFFE" +"dddddddddddddddeee....................................................................EEEDDeeee....." +"ddddddddddd.................................................................................ee......" +"ddddddd............................................................................................." +"...................................................................................................." +"...................................................................................................."; RCL_Unit testArrayFunc(int16_t x, int16_t y) { @@ -530,7 +531,7 @@ int main() RCL_UNITS_PER_SQUARE / 4, (RCL_UNITS_PER_SQUARE * 5) / 6, 287, - 370, + 365, 2027 )) return 1; diff --git a/programs/testSDL.c b/programs/testSDL.c index ed34068..1d27cda 100644 --- a/programs/testSDL.c +++ b/programs/testSDL.c @@ -10,8 +10,8 @@ #include #define RCL_COMPUTE_FLOOR_TEXCOORDS 1 -#define RCL_HORIZONTAL_FOV (RCL_UNITS_PER_SQUARE / 5) -#define RCL_VERTICAL_FOV RCL_UNITS_PER_SQUARE // redefine camera vertical FOV +//#define RCL_HORIZONTAL_FOV (RCL_UNITS_PER_SQUARE / 5) +#define RCL_VERTICAL_FOV 380 // redefine camera vertical FOV #define RCL_TEXTURE_VERTICAL_STRETCH 1 diff --git a/raycastlib.h b/raycastlib.h index b4f6ffb..38a70ff 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -111,7 +111,7 @@ #endif #ifndef RCL_VERTICAL_FOV -#define RCL_VERTICAL_FOV (RCL_UNITS_PER_SQUARE / 5) +#define RCL_VERTICAL_FOV (RCL_UNITS_PER_SQUARE / 3) #endif #define RCL_VERTICAL_FOV_TAN (RCL_VERTICAL_FOV * 4) ///< tan approximation @@ -120,7 +120,7 @@ #define RCL_HORIZONTAL_FOV (RCL_UNITS_PER_SQUARE / 4) #endif -#define RCL_HORIZONTAL_FOV_TAN (RCL_VERTICAL_FOV * 4) +#define RCL_HORIZONTAL_FOV_TAN (RCL_HORIZONTAL_FOV * 4) #define RCL_HORIZONTAL_FOV_HALF (RCL_HORIZONTAL_FOV / 2) @@ -517,6 +517,7 @@ RCL_Unit _RCL_cHorizontalDepthStart = 0; int16_t _RCL_cameraHeightScreen = 0; RCL_ArrayFunction _RCL_rollFunction = 0; // says door rolling RCL_Unit *_RCL_floorPixelDistances = 0; +RCL_Unit _RCL_fovCorrectionFactors[2] = {0,0}; //correction for hor/vert fov RCL_Unit RCL_clamp(RCL_Unit value, RCL_Unit valueMin, RCL_Unit valueMax) { @@ -620,7 +621,10 @@ RCL_Unit RCL_sin(RCL_Unit input) RCL_Unit RCL_tan(RCL_Unit input) { - return (RCL_sin(input) * RCL_UNITS_PER_SQUARE) / RCL_cos(input); + return (RCL_sin(input) * RCL_UNITS_PER_SQUARE) / RCL_nonZero(RCL_cos(input) +); + + return (RCL_sin(input) * RCL_UNITS_PER_SQUARE) / RCL_nonZero(RCL_cos(input)); } RCL_Unit RCL_ctg(RCL_Unit input) @@ -937,15 +941,15 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc, RCL_HitResult RCL_castRay(RCL_Ray ray, RCL_ArrayFunction arrayFunc) { RCL_HitResult result; - uint16_t RCL_len; + uint16_t len; RCL_RayConstraints c; c.maxSteps = 1000; c.maxHits = 1; - RCL_castRayMultiHit(ray,arrayFunc,0,&result,&RCL_len,c); + RCL_castRayMultiHit(ray,arrayFunc,0,&result,&len,c); - if (RCL_len == 0) + if (len == 0) result.distance = -1; return result; @@ -1652,6 +1656,7 @@ RCL_Unit RCL_vectorsAngleCos(RCL_Vector2D v1, RCL_Vector2D v2) return (v1.x * v2.x + v1.y * v2.y) / RCL_UNITS_PER_SQUARE; } + RCL_PixelInfo RCL_mapToScreen(RCL_Vector2D worldPosition, RCL_Unit height, RCL_Camera camera) { @@ -1676,14 +1681,15 @@ RCL_PixelInfo RCL_mapToScreen(RCL_Vector2D worldPosition, RCL_Unit height, result.depth = toPoint.x; - result.position.x = - middleColumn + (-1 * toPoint.y * middleColumn) / RCL_nonZero(result.depth); + result.position.x = middleColumn - + (RCL_perspectiveScaleHorizontal(toPoint.y,result.depth) * middleColumn) / + RCL_UNITS_PER_SQUARE; result.position.y = - camera.resolution.y / 2 - (RCL_perspectiveScaleVertical(height - camera.height,result.depth) - * camera.resolution.y) / RCL_UNITS_PER_SQUARE - + camera.shear; + * camera.resolution.y) / RCL_UNITS_PER_SQUARE; + + result.position.y = camera.resolution.y / 2 - result.position.y + camera.shear; return result; } @@ -1692,37 +1698,66 @@ RCL_Unit RCL_degreesToUnitsAngle(int16_t degrees) { return (degrees * RCL_UNITS_PER_SQUARE) / 360; } + +/** + Ugly temporary hack to solve mapping to screen. This function computes + (approximately, usin a table) a divisor needed for FOV correction. +*/ +RCL_Unit _RCL_fovCorrectionFactor(RCL_Unit fov) +{ + uint16_t table[9] = + {1,208,408,692,1024,1540,2304,5376,30000}; + + fov = RCL_min(RCL_UNITS_PER_SQUARE / 2 - 1,fov); + + uint8_t index = fov / 64; + uint32_t t = ((fov - index * 64) * RCL_UNITS_PER_SQUARE) / 64; + uint32_t v1 = table[index]; + uint32_t v2 = table[index + 1]; + + return v1 + ((v2 - v1) * t) / RCL_UNITS_PER_SQUARE; +} RCL_Unit RCL_perspectiveScaleVertical(RCL_Unit originalSize, RCL_Unit distance) { - return distance != 0 ? - (originalSize * RCL_UNITS_PER_SQUARE) / - ((RCL_VERTICAL_FOV_TAN * 2 * distance) / RCL_UNITS_PER_SQUARE) - : 0; + if (_RCL_fovCorrectionFactors[1] == 0) + _RCL_fovCorrectionFactors[1] = _RCL_fovCorrectionFactor(RCL_VERTICAL_FOV); + + return distance != 0 ? ((originalSize * RCL_UNITS_PER_SQUARE) / + RCL_nonZero((_RCL_fovCorrectionFactors[1] * distance) / RCL_UNITS_PER_SQUARE) + ) : 0; } RCL_Unit RCL_perspectiveScaleVerticalInverse(RCL_Unit originalSize, RCL_Unit scaledSize) { + if (_RCL_fovCorrectionFactors[1] == 0) + _RCL_fovCorrectionFactors[1] = _RCL_fovCorrectionFactor(RCL_VERTICAL_FOV); + return scaledSize != 0 ? - (originalSize * RCL_UNITS_PER_SQUARE + RCL_UNITS_PER_SQUARE / 2) / - // ^ take the middle - ((RCL_VERTICAL_FOV_TAN * 2 * scaledSize) / RCL_UNITS_PER_SQUARE) - : RCL_INFINITY; + + ((originalSize * RCL_UNITS_PER_SQUARE) / + RCL_nonZero((_RCL_fovCorrectionFactors[1] * scaledSize) + / RCL_UNITS_PER_SQUARE)) : RCL_INFINITY; } RCL_Unit RCL_perspectiveScaleHorizontal(RCL_Unit originalSize, RCL_Unit distance) { + if (_RCL_fovCorrectionFactors[0] == 0) + _RCL_fovCorrectionFactors[0] = _RCL_fovCorrectionFactor(RCL_HORIZONTAL_FOV); + return distance != 0 ? - (originalSize * RCL_UNITS_PER_SQUARE) / - ((RCL_HORIZONTAL_FOV_TAN * 2 * distance) / RCL_UNITS_PER_SQUARE) - : 0; + ((originalSize * RCL_UNITS_PER_SQUARE) / + RCL_nonZero((_RCL_fovCorrectionFactors[0] * distance) / RCL_UNITS_PER_SQUARE) + ) : 0; } RCL_Unit RCL_perspectiveScaleHorizontalInverse(RCL_Unit originalSize, RCL_Unit scaledSize) { + // TODO: probably doesn't work + return scaledSize != 0 ? (originalSize * RCL_UNITS_PER_SQUARE + RCL_UNITS_PER_SQUARE / 2) / ((RCL_HORIZONTAL_FOV_TAN * 2 * scaledSize) / RCL_UNITS_PER_SQUARE) @@ -1805,10 +1840,11 @@ void RCL_moveCameraWithCollision(RCL_Camera *camera, RCL_Vector2D planeOffset, RCL_ArrayFunction ceilingHeightFunc, int8_t computeHeight, int8_t force) { int8_t movesInPlane = planeOffset.x != 0 || planeOffset.y != 0; - int16_t xSquareNew, ySquareNew; if (movesInPlane || force) { + int16_t xSquareNew, ySquareNew; + RCL_Vector2D corner; // BBox corner in the movement direction RCL_Vector2D cornerNew;