Raycasting

Started by
4 comments, last by hendrix7 20 years ago
I bought this book a while ago that explained how to use raycasting (Larry Myers I think) to display maze-like backgrounds. Trouble is, when I tried to code my own I found I couldn''t get the walls to look right. The reason was that instead of a wall being drawn with a constant gradient I got a ''stepped'' look or, for some distances, a curved look. If you haven''t a clue what I''m on about I''ll need to explain a bit better but I''m hoping someone out there goes ''yeah, I know what he means'' to save me the time. Can someone guide me.
Advertisement
>I got a ''stepped'' look
rounding errors
>or, for some distances
confusing tan(y/z) with (y/z) (well known problem, called fisheye?)
I was just explaining this effect (in more detail) 5 minutes ago in another post.

It is called the fish-eye effect and it appears when you take panoramic photographs of near subjects (e.g. a room), or when you calculate your own 3D world using maths (e.g. raycasting).

Larry Myers'' books are usually quite good, so if you look up fish-eye or fish-bowl in the index you''ll probably find a good description and ways to code for it.
Thanks for replies.
I think I'm right in saying that this 'fisheye effect' is caused by taking actual distance instead of perpendicular distance when calculating heights of walls, and, if so, this is not the cause. (If I'm wrong about this, feel free to tell me I'm talking out of my ****, I won't be offended). I'm pretty sure my problem is rounding or something else. Something did occur to me though and I'd appreciate your views on this: Is there some kind of limit as to when the raycasting effect breaks down, i.e. walls at distances too far or too near to the viewer?

I've just realised that I am indeed talking out of my **** since the perpendicular distance between two points is ambiguous but anyway walls in front of the viewer appear the same height, i.e. not sloping off at the left and right edge (fisheye), so that's o.k., but the tops of the walls to the left and right of the viewer either have this 'stepped' or curved look. I hope you can see what I mean despite my cock-eyed (or maybe fisheyed) way of explaining it!

[edited by - hendrix7 on April 21, 2004 1:05:26 PM]
Your problem sounds like a classic example of "Fisheye" lens
Just to reiterate, arnero is quite right in stating that you have 2 separate problems, and each of these problems has a different solution.

Stepping (more than a pixel) is usually caused by rounding numbers too early in the raycasting equations, so that by the time you run the final equation to get the wall height, the intial rounding error is compounded into something more serious, which is clearly visible, i.e. the stepped walls. To solve this problem, re-check your maths, avoid early rounding, store more accurate versions of your intermediate calculations, or use more accurate sin/cos pi values etc.

The diminishing of wall heights the further away they are from the centre of the view, is definitely the fish eye effect. This is solved by adding code to compensating for the fish eye effect. I describe the high level algorithm for this in the other post.

Raycasting can breakdown around the tan infinity points (tan 90, tan 270 degrees) and other angles which give divide by zeros, but usually this is when the wall in question is so far away it wouldn''t have any height anyway. These situations should be coded for (you probably have already), but they don''t have anything to do with the problems you have described.

If you have a Java mobile phone you are welcome to download a free 2 level trial of our raycasting game StrangeMaze 3D - a 3D first person maze racing game. Details about the game can be found at www.strangemaze.com and the game can be downloaded by pointing your Java phone''s WAP browser at our WAP site: w w w . a w j g . c o m

This topic is closed to new replies.

Advertisement