From e2fbbd36e80a854eddbc13311130cf62ef78f348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 29 Sep 2018 09:17:23 +0200 Subject: [PATCH] Fix floor texturing --- raycastlib.h | 7 ++++--- testSDL.c | 17 +++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index 8207ee6..6c4e1a7 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -1249,7 +1249,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t RCL_Unit fPosY = _RCL_camera.resolution.y; RCL_Unit cPosY = -1; - // world coordinates + // world coordinates (relative to camera height though) RCL_Unit fZ1World = _RCL_startFloorHeight; RCL_Unit cZ1World = _RCL_startCeil_Height; @@ -1261,7 +1261,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t // we'll be simulatenously drawing the floor and the ceiling now for (RCL_Unit j = 0; j <= hitCount; ++j) - { // ^ = add extra iteration for horizon plane + { // ^ = add extra iteration for horizon plane int8_t drawingHorizon = j == hitCount; RCL_HitResult hit; @@ -1320,6 +1320,8 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t p.depth = 0; #endif + p.hit = hit; + limit = _RCL_drawHorizontal(fPosY,fZ1Screen,cPosY + 1, _RCL_camera.resolution.y,fZ1World,-1,RCL_COMPUTE_FLOOR_DEPTH, // ^ purposfully allow outside screen bounds @@ -1352,7 +1354,6 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t p.isWall = 1; p.depth = distance; p.isFloor = 1; - p.hit = hit; p.texCoords.x = hit.textureCoord; p.height = 0; // don't compute this, no use diff --git a/testSDL.c b/testSDL.c index e61ca36..028e6d1 100644 --- a/testSDL.c +++ b/testSDL.c @@ -12,11 +12,7 @@ //#define RCL_USE_DIST_APPROX 2 -// redefine some parameters -#define FPS 40 -#define GRAVITY_ACCELERATION (RCL_UNITS_PER_SQUARE * 3) -#define PLAYER_JUMP_SPEED 700 -#define RCL_CAMERA_COLL_HEIGHT_BELOW ((3 * RCL_UNITS_PER_SQUARE) / 2) +#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 @@ -878,7 +874,7 @@ void pixelFunc(RCL_PixelInfo *pixel) if (pixel->isWall) c = sampleImage(textures[pixel->hit.type],pixel->texCoords.x,pixel->texCoords.y); else - c = pixel->isFloor ? 0b00010001 : 0b00001010; + c = sampleImage(textures[0],pixel->texCoords.x,pixel->texCoords.y); //pixel->isFloor ? 0b00010001 : 0b00001010; // int intensity = pixel->depth - 8 * RCL_UNITS_PER_SQUARE; int intensity = pixel->depth - 8 * RCL_UNITS_PER_SQUARE; @@ -913,6 +909,7 @@ if (pixel->isWall) else c = pixel->isFloor ? 0x00FF0000 : 0x00F00000; */ + pixels[index] = r | g | b; pixelCounter[index]++; } @@ -983,11 +980,11 @@ int main() placeSprite(6,sprite3,16,12,1,3000); #undef placeSprite - camera.position.x = RCL_UNITS_PER_SQUARE * 5; - camera.position.y = RCL_UNITS_PER_SQUARE * 4; + camera.position.x = 25699; + camera.position.y = 10717; camera.shear = 0; - camera.direction = 0; - camera.height = RCL_UNITS_PER_SQUARE * 2; + camera.direction = -205; + camera.height = 2048; camera.resolution.x = SCREEN_WIDTH; camera.resolution.y = SCREEN_HEIGHT;