Original Post
HEllo everybody I spent the last hour scouring the web for information on floor casting but did not find anything constructive. right now i can render perspectivly correct only a single texture. my map is stored as a simple integer array map.data= {{1,1,1,1}, {{1,0,0,1}, {{1,0,2,1}, {{1,0,0,1}, {{1,1,1,1}} right now it only renders texture 0 as the ground texture. i would like to extrapolate the ground tile intersected by the ray and then choose the correct texture to be shown. my aim is to reproduce an engine like Might and Magic IV, ie. to have water, grass, desert tiles and the like, not just a simple stone floor. hope you can help me Nukleon below is the floorcasting code CODE:
///floor casting
double floorXWall, floorYWall; //x, y position of the floor texel at the bottom of the wall
//4 different wall directions possible
if(side == 0 && rayDirX > 0)
{
floorXWall = mapX;
floorYWall = mapY + wallX;
}
else if(side == 0 && rayDirX < 0)
{
floorXWall = mapX + 1.0;
floorYWall = mapY + wallX;
}
else if(side == 1 && rayDirY > 0)
{
floorXWall = mapX + wallX;
floorYWall = mapY;
}
else
{
floorXWall = mapX + wallX;
floorYWall = mapY + 1.0;
}
double distWall, distPlayer, currentDist;
distWall = perpWallDist;
distPlayer = 0.0;
if (drawEnd < 0) drawEnd = resolution_y; //becomes < 0 when the integer overflows
//draw the floor from drawEnd to the bottom of the screen
for(int y = drawEnd +1; y < resolution_y; y++)
{
currentDist = resolution_y / (2.0 * y - resolution_y); //you could make a small lookup table for this instead
double weight = (currentDist - distPlayer) / (distWall - distPlayer);
double currentFloorX = weight * floorXWall + (1.0 - weight) * Party.posX;
double currentFloorY = weight * floorYWall + (1.0 - weight) * Party.posY;
int floorTexX, floorTexY;
floorTexX = (int)((currentFloorX * texWidth) % texWidth);
floorTexY = (int)((currentFloorY * texHeight) % texHeight);
//here i would like to change the 1. parameter to the texture interesected by the ray
buffer[y*resolution_x+x]= textures[1,floorTexX,floorTexY];
if(CurrentMap.outdoor==false)
buffer[(resolution_y-y)*resolution_x+x]= textures[2,floorTexX,floorTexY];
}