Sign in to follow this  
Nathannoob

Need help drawing floors in ray caster

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[quote name='Nathannoob' timestamp='1307598185' post='4821210']
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.
[/quote]

[url="http://doom.wikia.com/wiki/Doom_source_code"]http://doom.wikia.com/wiki/Doom_source_code[/url]

Perhaps this might help?

Share this post


Link to post
Share on other sites
[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?
[/quote]

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.

Share this post


Link to post
Share on other sites
[quote name='bluntman' timestamp='1307647532' post='4821448']
[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?
[/quote]

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.

Share this post


Link to post
Share on other sites
[url="http://archive.gamedev.net/reference/articles/article337.asp"]http://archive.gamedev.net/reference/articles/article337.asp[/url]
You can do super fast software texture mapping using these techniques. Convert them to SIMD for an even bigger boost.

Share this post


Link to post
Share on other sites
[quote name='bluntman' timestamp='1307654656' post='4821489']
[url="http://archive.gamedev.net/reference/articles/article337.asp"]http://archive.gamed.../article337.asp[/url]
You can do super fast software texture mapping using these techniques. Convert them to SIMD for an even bigger boost.
[/quote]

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.
[code]
// 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);
}
[/code]
It would be great if someone could show me what I'm doing wrong.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this