#### Archived

This topic is now archived and is closed to further replies.

# Raycasting floors?

This topic is 5545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ve had a go at adding simple floors to my raycasting engine but am not having much luck.. I''ve created a second map that represents floor colors: map[]={1,0,1,0,1 0,1,0,1,0...etc}; Where a 1 is dark grey and 0 is light grey (the aim is to get a sort of chessboard floor). And the code:- //use the ray cast out for the wall while(RAYLEN>=0){ RAYX-=sin[angle]; //move back towards the player RAYY-=cos[angle]; color=(map.floor[(map.w*(RAYY>>6))+(RAYX>>6)])?"#cccccc":"#eeeeee"; //get the color of the current position of RAYX,RAYY //draw the color to the screen RAYLEN-=1; } The idea is to start at the bottom of the wall and work back to the player, drawing the floor. But it looks very very wrong.. I''ve read the permadi tutorial but don''t understand the floor section Any help would be appreciated.

##### Share on other sites
I have never done floors in raycasting, but this is what I can figure out:

Note that as you go from the bottom of a wall to the bottom of the screen, you walk in screen space. You need to transform this into world space. When you''re in the middle of the screen, you walk quickly in the floor tiles and you slow down as you get closer to the viewpoint. Setup a LUT with these steppings (they will be constant horizontally over the screen).

Practically, you could start from the wall intersection point and you set a ptr to that location on the screen as well. Read from the floor and put the appropriate pixel. Move down on the screen and move towards the view on the floor. But how much?
Cast a ray from the view, through the last pixel and down into the floor. Cast another ray for the current pixel and calculate the distance between the two samples and move the floor point by this amount. Perhaps casting directly would work too, but implemented, I don''t know what would be quicker.

That''s it I think. Get a pen and a sheet of paper and sketch a little on it.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• ### Who's Online (See full list)

There are no registered users currently online

×