Author Topic: The most messed up 3D known to man!  (Read 8593 times)

0 Members and 1 Guest are viewing this topic.

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
The most messed up 3D known to man!
« 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.



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.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: The most messed up 3D known to man!
« Reply #1 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.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: The most messed up 3D known to man!
« Reply #2 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



However when I try to fix it this happens:


Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: The most messed up 3D known to man!
« Reply #3 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.

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: The most messed up 3D known to man!
« Reply #4 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.

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: The most messed up 3D known to man!
« Reply #5 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.
« Last Edit: November 01, 2012, 09:20:19 pm by shmibs »

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: The most messed up 3D known to man!
« Reply #6 on: November 01, 2012, 06:51:39 pm »
OK, but it looks bad.


Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: The most messed up 3D known to man!
« Reply #7 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.

Offline Goplat

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 289
  • Rating: +82/-0
    • View Profile
Re: The most messed up 3D known to man!
« Reply #8 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.
« Last Edit: November 01, 2012, 08:05:24 pm by Goplat »
Numquam te deseram; numquam te deficiam; numquam circa curram et te desolabo
Numquam te plorare faciam; numquam valedicam; numquam mendacium dicam et te vulnerabo

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: The most messed up 3D known to man!
« Reply #9 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.
« Last Edit: November 01, 2012, 08:43:29 pm by Augs »

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: The most messed up 3D known to man!
« Reply #10 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.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: The most messed up 3D known to man!
« Reply #11 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).
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: The most messed up 3D known to man!
« Reply #12 on: November 02, 2012, 11:12:18 am »
There is not hit collision if that's what you mean. You walk into blocks.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: The most messed up 3D known to man!
« Reply #13 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

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: The most messed up 3D known to man!
« Reply #14 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

« Last Edit: November 02, 2012, 04:25:57 pm by shmibs »