Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: Augs on November 01, 2012, 03:15:53 pm

Title: The most messed up 3D known to man!
Post by: Augs on November 01, 2012, 03:15:53 pm
So I tried my hand at raycasting(at least what I think it is, not sure) and it did not go well. I need help.

(http://i.imgur.com/qGqgt.png)

Note that to see how bad it is messed up you should probably try it.

http://www.mediafire.com/?m9hhj5wdh05k3rs Here is a link to the C# file.
Title: Re: The most messed up 3D known to man!
Post by: ben_g on November 01, 2012, 05:40:28 pm
That does indeed look like raycasting. The extremely wide aspect ratio is one of the causes why it looks so bad. An other one is the scale of the bars. The corners look more like gentle curves. You should make walls that are further away smaller and the ones closer bigger.
Title: Re: The most messed up 3D known to man!
Post by: Augs on November 01, 2012, 06:00:28 pm
I am new to this. What is aspect ratio?

Also, I looked it up and it is called the "fishbowl effect". Here is an Image explaining it. I got it from This: http://www.permadi.com/tutorial/raycast/rayc8.html#FINDING DISTANCE TO WALLS

(http://i.imgur.com/1W6WK.png)

However when I try to fix it this happens:

(http://i.imgur.com/uC4cz.png)
Title: Re: The most messed up 3D known to man!
Post by: shmibs on November 01, 2012, 06:26:46 pm
why are you trying to compensate for that effect? it is natural for it to be there, so removing it will make your program look less natural. you may have to adjust the angular width or the total horizontal space you can see at once, though. one that's used a lot is 60 degrees.
Title: Re: The most messed up 3D known to man!
Post by: Augs on November 01, 2012, 06:32:41 pm
It really is not natural, if you download the program it looks awful. Also I use 40 degrees.
Title: Re: The most messed up 3D known to man!
Post by: shmibs on November 01, 2012, 06:35:18 pm
the "fishbowl effect" is natural
EDIT: it's not the right way to do things for a flat screen, though. i spoke without thinking =/

to get the actual distance to use, you have to take the distance from your chosen viewpoint to the object and subtract from that the distance from your viewpoint to the viewing window when travelling at that angle.
Title: Re: The most messed up 3D known to man!
Post by: Augs on November 01, 2012, 06:51:39 pm
OK, but it looks bad.

Title: Re: The most messed up 3D known to man!
Post by: Builderboy on November 01, 2012, 07:10:40 pm
the "fishbowl effect" is natural. the issue is that a screen is just a much smaller width than the total width visible by a human, so the angle must be much smaller
The fishbowl effect is not natural for humans to perceive, and this is because we have a radial cornea instead of a flat one.  The math behind raycasting uses a flat cornea, and thus the fishbowl effect is created, which does indeed making things look unnatural.  In 3D graphics, straight lines should appear straight :P

As for what is causing the weirdness, check to see if you are using radians or degrees, as it looks like the error is happening because of some mismatch.  For the Field-of-View, i would recommend 60 degrees.
Title: Re: The most messed up 3D known to man!
Post by: Goplat on November 01, 2012, 07:57:02 pm
No, the fishbowl effect is not natural. A straight line in 3D space should always be a straight line in a 2D perspective projection - look at a photograph of a building for example.

Fishbowl is caused by computing the ray vectors the wrong way. Right now you've got rays evenly spaced by angle, like the left side of the diagram below. There are two problems with this. The first, which has already been mentioned, is the since the rays are all the same length, the rays at more extreme angles take longer to get to the wall. The more subtle problem is that the rays don't hit the wall at evenly spaced points; the rays on the left and right sides hit the wall further apart than the rays in the center.

The right way to do raycasting is to imagine the game window as a literal window into your world: you want to make the player see what the in-game camera sees. Monitors are flat, not curved; as such the columns on the player's monitor are spaced a constant linear distance apart, not a constant angle apart, and the rays should be computed accordingly, like the right side of the diagram. (Edit: A simple way to compute each ray is to add the camera direction to a multiple of its perpendicular. Ranging the multiplier from -0.5 to +0.5 will produce a 60-degree field of view.)

This program actually has another problem: distance isn't translated to line height properly. The perceived height should be inversely proportional to the distance, i.e. a constant divided by the number of ray iterations, not subtracted.
Title: Re: The most messed up 3D known to man!
Post by: Augs on November 01, 2012, 08:39:54 pm
Quote
This program actually has another problem: distance isn't translated to line height properly. The perceived height should be inversely proportional to the distance, i.e. a constant divided by the number of ray iterations, not subtracted.

OK thanks but I am having some problems centring the lines. Before it was just the ray iterations/2 to get the y. So what would it be now?

Edit: found out how to centre them. But I am not sure this is correct. The walls seem to be getting big to fast.
Title: Re: The most messed up 3D known to man!
Post by: Augs on November 02, 2012, 10:57:39 am
Looking better, can you explain how to make the rays hit the wall at evenly spaced points?

Here is a picture of how it looks now! Thanks.
(http://i.imgur.com/075lQ.png)
Title: Re: The most messed up 3D known to man!
Post by: calc84maniac on November 02, 2012, 11:01:24 am
The behavior of that wall on the left makes me think that you're detecting collision with the block sides parallel to the screen instead of perpendicular (which should be closer).
Title: Re: The most messed up 3D known to man!
Post by: Augs on November 02, 2012, 11:12:18 am
There is not hit collision if that's what you mean. You walk into blocks.
Title: Re: The most messed up 3D known to man!
Post by: Builderboy on November 02, 2012, 02:56:29 pm
The behavior of that wall on the left makes me think that you're detecting collision with the block sides parallel to the screen instead of perpendicular (which should be closer).
It could also be that the ray stepping is too coarse
Title: Re: The most messed up 3D known to man!
Post by: DJ Omnimaga on November 02, 2012, 04:00:16 pm
why are you trying to compensate for that effect? it is natural for it to be there, so removing it will make your program look less natural. you may have to adjust the angular width or the total horizontal space you can see at once, though. one that's used a lot is 60 degrees.

For some reasons, I don't think I have noticed any FPS for the computer with that effect ???, or maybe it's due to the fact that every FPS I played were made back in the days where computer screens were not flat. Also when I take pictures with my camera walls always look like figure 18
(http://i.imgur.com/1W6WK.png)
Title: Re: The most messed up 3D known to man!
Post by: shmibs on November 02, 2012, 04:26:02 pm

i was speaking without thinking. see everyone elses disagreements with me to see what's actually correct :P
Title: Re: The most messed up 3D known to man!
Post by: flyingfisch on November 02, 2012, 04:32:17 pm
why are you trying to compensate for that effect? it is natural for it to be there, so removing it will make your program look less natural. you may have to adjust the angular width or the total horizontal space you can see at once, though. one that's used a lot is 60 degrees.

For some reasons, I don't think I have noticed any FPS for the computer with that effect ???, or maybe it's due to the fact that every FPS I played were made back in the days where computer screens were not flat. Also when I take pictures with my camera walls always look like figure 18
(http://i.imgur.com/1W6WK.png)

I think that's as a result of barrel distortion (http://en.wikipedia.org/wiki/Distortion_%28optics%29)... which sometimes happens with digital cameras.