diff --git a/raycaster.c b/raycaster.c index 94878fb..40b9657 100644 --- a/raycaster.c +++ b/raycaster.c @@ -859,6 +859,7 @@ void drawRays3D() int x, y; int textureX; + float textureY; if (shade == 1) // North-south walls (PI -> (2 * PI)) { @@ -880,7 +881,7 @@ void drawRays3D() for (x = xStart; x < xEnd; x++) { - float textureY = textureYoffset * textureYstep + (horizontalMapTexture * 32); + textureY = textureYoffset * textureYstep + (horizontalMapTexture * 32); for (y = 0; y < lineHeight; y++) { float c = All_Textures[((int)textureY * mapSize) + textureX] * shade; @@ -918,6 +919,43 @@ void drawRays3D() { rayAngle -= 2 * PI; } + + // * Draw Floors (camera-plane floor casting) + // The walls use angular rays, but floors need projection-plane directions + // where every column spans both world axes, so the vertical texture + // coordinate advances everywhere (no degenerate center column). + float planeLen = tanf(DR * 30.0f); // half-FOV for the 60-degree view + float planeX = -sin(playerAngle) * planeLen; + float planeY = cos(playerAngle) * planeLen; + + for (x = xStart; x < xEnd; x++) + { + // Projection-plane offset for this screen column, in [-1, 1]. + float cameraX = 2.0f * (x + 0.5f) / (float)gameWidth - 1.0f; + float rayDirX = cos(playerAngle) + planeX * cameraX; + float rayDirY = sin(playerAngle) + planeY * cameraX; + + for (y = lineOffset + lineHeight; y < TOTAL_HEIGHT; y++) + { + // Vertical distance below the horizon; grows the closer to the player. + float dy = y - (TOTAL_HEIGHT / 2.0); + + // Perspective: world distance along the ray to reach this screen row. + // Scaled by mapSize so one texture tile spans one map unit, matching the + // wall texture sampling. + float rowDistance = (gameHeight / 2.0) * mapSize / dy; + + float fx = playerX + rowDistance * rayDirX; + float fy = playerY + rowDistance * rayDirY; + + int tx = ((int)fx) & (mapSize - 1); + int ty = ((int)fy) & (mapSize - 1); + + float c = All_Textures[(ty * mapSize) + tx] * 0.7; + glColor3f(c, c, c); + glVertex2i(MAP_WIDTH + GAP + x, (int)y); + } + } } glEnd(); }