Ray Casting(Wolfenstein style)

BlitzMax Forums/BlitzMax Programming/Ray Casting(Wolfenstein style)

Yahfree(Posted 2011) [#1]
Hey, I'm working on a raycaster for psuedo 3d.. and I seem to have something SERIOUSLY wrong with my math.



Can anyone with experience with this sort of thing give me some pointers? I'm trying to follow this guide:
http://www.permadi.com/tutorial/raycast/rayc8.html

my code should highlight the walls in RED that are hit by rays.. though it seems to be really random and weird!


xlsior(Posted 2011) [#2]
No idea and I haven't looked at the code you posted, but just in case:

A common issue people run into is that Blitzmax trigonometry functions (cos, sin, tan, etc.) use degrees instead of radians. Just something to keep in mind, especially if you are getting unexpected results.


Yahfree(Posted 2011) [#3]
I'm pretty sure it has to do with the tracing code..

When I just run tracing to the first point(ax,ay) it finds the correct first point..

However when I increment the first point by xa, and ya respectively, it seems to be tracing in the wrong direction or something.

The tutorial I'm following ( http://www.permadi.com/tutorial/raycast/rayc8.html )

seems to just say general things such as "the tangent of alpha".. so I don't think it's a problem with angles.. the tangent of PI should be equal to the tangent of 180 degrees, no?


xlsior(Posted 2011) [#4]
tangent in degrees is different than a tangent in radians...


Noobody(Posted 2011) [#5]
I had a quick glance over your code and the main issue I see is that you didn't implement vertical collision. Horizontal collision seems to work quite good, even though the ray angles are a bit off compared to what is drawn.

Although, in my opinion, the method proposed on that site seems way more complicated and inefficient than it should be. Instead of artificially splitting the raymarching process into horizontal and vertical steps and then taking the solution that is closer, why not do both at once? This is what is known as a DDA algorithm; here's a quick raycasting demonstration of how it works:

This paper gives a nice explanation of how it works (just ignore the voxel and raytracing talk and skip right to the two dimensional case).


Jesse(Posted 2011) [#6]
it is true, the tutorial uses degrees. the problem I believe is that the tutorial uses counter clockwise angle increment while BlitzMax uses clockwise angle increment.