Turning 2D map into a 3D first person view

I have spinodal decomposition code to create “maps” like in the image below and I would like to turn it into a 3D walk-around game like Daniel Shiffman’s example with ray casting, but I don’t know how ray casting could be used effectively in a situation like this because I don’t have linear boundaries to easily calculate ray-boundary intersections.

The idea that I have is to check pixels along the length of the rays to see if there is a color change, but this doesn’t seem very efficient. Is there another way I could go about this that would be more efficient?

1 Like

You could just check the color of 4 Pixels (maybe more). Top/Bottom/Left/Right. If they return White, you can move there, else it counts as obstacle.

For the left part for example it would be :

``````get(playerPosX-playerWidth/2, playerPosY);
``````

I assume that black are the pathway and white are walls

Now ray casting aside wouldn’t it be a goal to translate the image to a 3D world where you can go through? Hard enough this is.

Then obstacle detection might be possible because of mapping your pos in 3D to that in the image as has been said

Remark

There are black spots inside the white. I would just fill the spots white.
Then you could have an edge detection of sorts and then make a list of 2D vertexes for each obstacle.
Then use QuadStrip to make 3D objects by using a upper y height and a lower floor y height.

Draw the floor separately

Or you might want to draw a 2D Grid and set the z of the vertices to either 0 for black (the path) and the height you want for the Walls for white (the walls).

That way you could still detect collision without having seperate objects. It should be pretty easy to realize.

1 Like

Thank you all for your advice! I think I have some good ideas on how to proceed now. I think I will go with a height map like Lexyth suggested. The only issue I see happening from this is that I could be rendering the entire map all at once instead of just the walls that are visible to the player. A good way to avoid this would be to render walls within a certain “visibility” distance parameter.

Thanks again!