[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Raycaster Demo



Luke Paireepinart wrote:
Kris:
One way to correct for this is to, instead of using a single point to cast rays, use a camera plane.
This plane will be parallel to the wall when the wall is perpendicular to the player, which means that the fish-eye problem doesn't occur at all,
since you're casting from a set distance away from the wall, instead of from a single point.


I don't know if I explained that very well.

The problem is that you're casting rays spaced at equal angles, but projecting them onto linearly-spaced slices across the screen.

Instead of iterating over angles, you should be iterating
over the x-coordinates of the screen, and casting a ray
through each one. These rays will *not* be spaced at
equal angles.

Did you use F. Permadi's raycasting tutorial?
http://www.permadi.com/tutorial/raycast/

It is a fantastic tutorial, IMHO, but it doesn't use the camera plane system.

I don't know why some people seem to suggest doing it that way; not only is it wrong, but it's computationally more difficult, requiring sines and cosines to be calculated or looked up for each ray. If you're doing it right, you shouldn't need to do any trigonometry in the inner loop -- it's all just vector arithmetic and scalings based on similar triangles.

http://student.kuleuven.be/~m0216922/CG/raycasting.html

That one looks a lot better in terms of the basic technique.

You may also like to do some reading about coordinate
transformation and perspective projection in general.

--
Greg