Skip to content

rghouzra/raycaster-game-vec2-trigonemtry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

raycaster-game-vec2-trigonemtry

In the mandatory part, a raycaster is implemented using pure vector relations. The bonus part utilizes trigonometry for implementation.

Steps

  1. Camera Plane Setup:

    • Begin by creating a camera plane.
    • Generate rays based on the window size. I made this link for visualization.
  2. Ray Generation and Collision Detection:

    • Generate vectors for each ray.
    • Use the DDA (Digital Differential Analyzer) algorithm to check collisions with walls.
  3. Distance Calculation:

    • Find the position of the wall upon collision.
    • Calculate the distance using a modified version of the DDA algorithm.
    • To avoid fisheye effects, use the distance to the camera plane for calculations.

    image

    Using mathematical relations:

    (mapY - posY + (1 - stepY) / 2) / raydirY = perpWallDist
    
  4. Wall Height Calculation:

    • Calculate the height of the wall to create the illusion of depth.
    • Utilize the concept of raycasting where distant walls appear shorter.
    • Adjust the wall height using the inverse of the distance and the height of the window.

    Example adjustment:

    1.5 * windowHeight / perpWallDist
    

Resources

In-Game Screenshots

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4