Search code examples
c++graphics3dsdlraycasting

Looking up and down (Implementing Camera Pitch), and including multiple levels in ray casting engine


I have made a simple Ray casting Engine using SDL2 complete with player movement, and doing some research noticed from Wikipedia: "While the world appears 3D, the player cannot look up or down or only in limited angles with shearing distortion".

My understanding of Ray casting is essentially that a ray is shot from a player, and according to the distance from a ray to a wall, that wall is rendered to a certain size, allowing a pseudo-3d effect on a 2d surface. However, theoretically, would it not be possible to do the same thing while looking up and down, not just left and right?

Also, how does one go about including multiple heights/levels in Ray casting, as for now I only seem to be stuck with 1 level.

Could you please shine some light on looking up and down in a Ray casting Engine, and including multiple levels?


Solution

  • 2D raycast shoots single ray per x position of view. If you want to look up/down freely through multiple floors that would require to shoot ray on per pixel manner converting from 2D raycast to 3D raytrace which would be hugely slower.

    However of you want just look up/down inside single floor that is doable up to a point (straight up/down has singularity in goniometrics used and would require additional ifs slowing stuff down due brunching)

    having more levels/floors is simple you just add lifts or portals ... that way you can still have simple raycast where you never see anything else but current level/floor.

    take a look at this:

    with it you can add usable stairs so you could move through levels also by stairs you just have to make sure its properly shielded so you will not have holes in view while traversing between levels.

    you also need floor/ceiling tiles in your map something like I have in here:

    without knowing more about your project its hard to be specific. In some cases you might want to use Voxel space ray casting instead of levels ...