diff --git a/main.c b/main.c index 6610447..2263da6 100755 --- a/main.c +++ b/main.c @@ -96,9 +96,6 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel) uint8_t color; uint8_t shadow = 0; - pixel->texCoords.y = -1 * pixel->texCoords.y; - // ^ raycastlib gives negative coords here, so make them positive - if (pixel->isWall) { uint8_t textureIndex = @@ -114,12 +111,9 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel) ): ((pixel->hit.type & 0x38) >> 3); - RCL_Unit textureV = pixel->height + pixel->texCoords.y; + RCL_Unit textureV = pixel->texCoords.y; if ((pixel->hit.type & SFG_TILE_PROPERTY_MASK) == - SFG_TILE_PROPERTY_ELEVATOR) - textureV -= pixel->wallHeight; - else if ((pixel->hit.type & SFG_TILE_PROPERTY_MASK) == SFG_TILE_PROPERTY_SQUEEZER) textureV += pixel->wallHeight; diff --git a/raycastlib.h b/raycastlib.h index be61534..66455e7 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -26,7 +26,7 @@ author: Miloslav "drummyfish" Ciz license: CC0 1.0 - version: 0.82 + version: 0.84 */ #include @@ -266,8 +266,8 @@ typedef struct int8_t isFloor; ///< Whether the pixel is floor or ceiling. int8_t isHorizon; ///< If the pixel belongs to horizon segment. RCL_Unit depth; ///< Corrected depth. - RCL_Unit height; ///< World height (mostly for floor). RCL_Unit wallHeight;///< Only for wall pixels, says its height. + RCL_Unit height; ///< World height (mostly for floor). RCL_HitResult hit; ///< Corresponding ray hit. RCL_Vector2D texCoords; /**< Normalized (0 to RCL_UNITS_PER_SQUARE - 1) texture coordinates. */ @@ -1143,7 +1143,8 @@ static inline int16_t _RCL_drawWall( RCL_Unit limit = RCL_clamp(yTo,limit1,limit2); - RCL_Unit wallLength = yTo - yFrom - 1; + RCL_Unit wallLength = RCL_absVal(yTo - yFrom - 1); + wallLength = RCL_nonZero(wallLength); RCL_Unit wallPosition = RCL_absVal(yFrom - yCurrent) - increment; @@ -1159,6 +1160,19 @@ static inline int16_t _RCL_drawWall( pixelInfo->texCoords.y = RCL_COMPUTE_WALL_TEXCOORDS ? wallPosition * coordStep : 0; + if (increment < 0) + { + coordStep *= -1; + pixelInfo->texCoords.y = +#if RCL_TEXTURE_VERTICAL_STRETCH == 1 + RCL_UNITS_PER_SQUARE - pixelInfo->texCoords.y; +#else + height - pixelInfo->texCoords.y; +#endif + + wallPosition = wallLength - wallPosition; + } + #if RCL_ACCURATE_WALL_TEXTURING == 1 if (1) #else @@ -1176,13 +1190,15 @@ static inline int16_t _RCL_drawWall( #if RCL_COMPUTE_WALL_TEXCOORDS == 1 #if RCL_TEXTURE_VERTICAL_STRETCH == 1 - pixelInfo->texCoords.y = (wallPosition * RCL_UNITS_PER_SQUARE) / wallLength; + pixelInfo->texCoords.y = + (wallPosition * RCL_UNITS_PER_SQUARE) / wallLength; #else pixelInfo->texCoords.y = (wallPosition * height) / wallLength; #endif #endif - wallPosition++; + wallPosition += increment; + RCL_PIXEL_FUNCTION(pixelInfo); } } @@ -1237,9 +1253,9 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t RCL_PixelInfo p; p.position.x = x; p.height = 0; + p.wallHeight = 0; p.texCoords.x = 0; p.texCoords.y = 0; - p.wallHeight = 0; // we'll be simulatenously drawing the floor and the ceiling now for (RCL_Unit j = 0; j <= hitCount; ++j) @@ -1378,7 +1394,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t #if RCL_TEXTURE_VERTICAL_STRETCH == 1 RCL_UNITS_PER_SQUARE #else - cZ2World - cZ1World + cZ1World - cZ2World #endif ,1,&p);