Need help drawing floors in ray caster

Started by
7 comments, last by Nathannoob 12 years, 10 months ago
For the past couple of days I've been working on a ray casting game in java, but I can't figure out how to draw the floors.
I've tried looking at many tutorials to no success so I was wondering if someone could thoroughly explain how to do it or
give me a project I could look at to figure it out.
Here's the java project I'm working on: [attachment=2967:RayCast2.zip]

Thanks.
Advertisement

For the past couple of days I've been working on a ray casting game in java, but I can't figure out how to draw the floors.
I've tried looking at many tutorials to no success so I was wondering if someone could thoroughly explain how to do it or
give me a project I could look at to figure it out.
Here's the java project I'm working on: [attachment=2967:RayCast2.zip]

Thanks.


http://doom.wikia.com/wiki/Doom_source_code

Perhaps this might help?
I may be missing something here, but fundamentally what makes floors any different from anything else your ray caster will be drawing?

I may be missing something here, but fundamentally what makes floors any different from anything else your ray caster will be drawing?


If he means ray caster as in Doom then the walls and floors use different techniques. In a Doom style engine the walls are drawn by intersecting a ray in 2D with a wall section, then scaling a 1D slice of texture onto the screen. Obviously to draw the floor needs a completely different technique. My guess is that you simply project a pixel onto a plane and then mod the plane coordinates by texture size, and that's your pixel colour.

[quote name='WavyVirus' timestamp='1307645859' post='4821435']
I may be missing something here, but fundamentally what makes floors any different from anything else your ray caster will be drawing?


If he means ray caster as in Doom then the walls and floors use different techniques. In a Doom style engine the walls are drawn by intersecting a ray in 2D with a wall section, then scaling a 1D slice of texture onto the screen. Obviously to draw the floor needs a completely different technique. My guess is that you simply project a pixel onto a plane and then mod the plane coordinates by texture size, and that's your pixel colour.
[/quote]

I'm pretty much trying to make a game like wolfenstein except with the addition of textured floors instead of a solid color. To do this I need to loop through every pixel below the drawn wall slice. What I'm having trouble figuring out is how to find the correct pixel to draw from the floor texture.
Just cheat and make the floor a textured quad? ;)

Just cheat and make the floor a textured quad? ;)


Nah, I really want to do it the old way
http://archive.gamedev.net/reference/articles/article337.asp
You can do super fast software texture mapping using these techniques. Convert them to SIMD for an even bigger boost.

http://archive.gamed.../article337.asp
You can do super fast software texture mapping using these techniques. Convert them to SIMD for an even bigger boost.


I can't make any sense of how to implement whats in the article, Is there any Java or XNA examples of floor casting you can show?

Here's the part of code that does the floors but it doesn't draw anything correctly and I'm not sure why.

// draw wall column
if (disthorizontaltilehit < distverticaltilehit)
{
dist = disthorizontaltilehit / Map.fishtable[Column];
wallslice = (int)xintersection % Map.tile;
distwall = Math.abs(horizontaltile - Game.player.posy);
}
else
{
dist = distverticaltilehit / Map.fishtable[Column];
wallslice = (int)yintersection % Map.tile;
distwall = Math.abs(verticaltile - Game.player.posx);
}

wallbottom = Map.planeycenter + (int)(Map.tile * (float)Player.distancetoprojectionplane / dist * 0.5f);
walltop = Map.projectplaneheight - wallbottom;

if (disthorizontaltilehit < distverticaltilehit)
{
g.drawImage(Main.lightwall, Column, walltop,
Column + Game.resolution, wallbottom, wallslice, 0, wallslice + 1, Map.tile, null);
}
else
{
g.drawImage(Main.darkwall, Column, walltop,
Column + Game.resolution, wallbottom, wallslice, 0, wallslice + 1, Map.tile, null);
}


// floor casting
//x, y position of the floor texel at the bottom of the wall
double floorXWall = 0;
double floorYWall = 0;

//4 different wall directions possible
int side = 1;
if(disthorizontaltilehit < distverticaltilehit)
side = 0;
if(side == 0 && xdistnextintersection > 0)
{
floorXWall = hxtileindex;
floorYWall = hytileindex + Column;
}
else if(side == 0 && xdistnextintersection < 0)
{
floorXWall = hxtileindex + 1.0;
floorYWall = hytileindex + Column;
}
else if(side == 1 && ydistnextintersection > 0)
{
floorXWall = vxtileindex + Column;
floorYWall = vytileindex;
}
else if(side == 1 && ydistnextintersection < 0)
{
floorXWall = vxtileindex + Column;
floorYWall = vytileindex + 1.0;
}

//draw the floor from drawEnd to the bottom of the screen
for(int y = wallbottom; y < Map.projectplaneheight; y += 1)
{
currentdist = Map.projectplaneheight / (2.0f * y - Map.projectplaneheight);

weight = currentdist / distwall;

double currentFloorX = weight * floorXWall + (1.0 - weight) * Game.player.posx;
double currentFloorY = weight * floorYWall + (1.0 - weight) * Game.player.posy;

int floorTexX = (int)(currentFloorX * Map.tile) % Map.tile;
int floorTexY = (int)(currentFloorY * Map.tile) % Map.tile;

//floor
g.drawImage(Main.floor, Column, y,
Column + Game.resolution, y + 1, floorTexX, floorTexY, floorTexX + 1, floorTexY + 1, null);
}

It would be great if someone could show me what I'm doing wrong.

This topic is closed to new replies.

Advertisement