Jump to content
  • Advertisement

Archived

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

robertgamble

Raycasting floors?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!