In the mandatory part, a raycaster is implemented using pure vector relations. The bonus part utilizes trigonometry for implementation.
-
Camera Plane Setup:
- Begin by creating a camera plane.
- Generate rays based on the window size. I made this link for visualization.
-
Ray Generation and Collision Detection:
- Generate vectors for each ray.
- Use the DDA (Digital Differential Analyzer) algorithm to check collisions with walls.
-
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.
Using mathematical relations:
(mapY - posY + (1 - stepY) / 2) / raydirY = perpWallDist
-
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