Understanding a raycast method

667 views Asked by At

For the purpose of my school, I am learning how to do a raycast in C.

Based on this tutorial I found http://permadi.com/1996/05/ray-casting-tutorial-7/, the author explains his method to find deltaX and deltaY to check whenever there is a wall at a position based on deltaX or deltaY.

However he's getting deltaX and deltaY via the tangent of an angle a, and it wont work with 0, pi/2, pi and 3pi/2.

How can it work with such solution ? Am I missing something ?

1

There are 1 answers

0
Olivier On BEST ANSWER

At 0 and pi, there's no point in searching for horizontal intersections as the ray is horizontal. You'll need to explicitly check for that case.

At pi/2 and 3pi/2, the tangent is infinite so 1/tan() should give you zero with floating point math. It will work even if it looks ugly.

For vertical intersections, shift the angles by pi/2 and the same reasoning applies.