-2

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 ?

Quentin Laillé
  • 125
  • 1
  • 12
  • welcome to [so]! I'm afraid your question rather belongs to http://math.stackexchange.com ! The tanges function is 0 at 0 and pi, infinity at n/2*pi! – jkalden Dec 23 '16 at 14:13
  • There's a [computer graphics](http://computergraphics.stackexchange.com/) site by the way. – Olivier Dec 23 '16 at 14:14
  • ... and also a [game development](https://gamedev.stackexchange.com/) site! :) Lots of choices. – cxw Dec 23 '16 at 14:16
  • My bad, didn't know Stack Exchange had such sites, thanks for your answers. – Quentin Laillé Dec 23 '16 at 14:18

1 Answers1

1

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.

Olivier
  • 1,144
  • 1
  • 8
  • 15