6
\$\begingroup\$

I've just started making a 'raycast' engine, a pseudo 3D FPS engine similar to Wolfenstein/Doom. I haven't done much reading so my implementation is likely very naive.

My current working prototype has a 'fisheye' distortion [2nd image] which makes sense because the middle of the wall is closer than the far edges, but this is not how Doom looks.

What's the right way to do this? an orthogonal projection seems wrong because you would lose the foreshortening.

from a distance

close up

\$\endgroup\$
2
  • \$\begingroup\$ How are you calculating your projection? \$\endgroup\$ Commented Mar 31, 2015 at 1:06
  • \$\begingroup\$ Horizontal FOV is 90 degrees (pi/2 rad), all rays begin at the player, the distance for each ray is just the Euclidean distance from the user to the ray/wall intersection. The wall height is essentially the height/distance. Top left on the images shows the player in a box, pink lines are the rays. image here \$\endgroup\$ Commented Mar 31, 2015 at 9:48

2 Answers 2

8
\$\begingroup\$

You need to use the range instead of the distance when you cast the ray. The range is the length of the projection of the ray onto the camera plane.

image

See this source.

Though IMHO some amount of fisheye distortion is kind of cool to keep around.

\$\endgroup\$
2
  • \$\begingroup\$ I just started doing something very similar (scaling the ray to the the length of the middle vector), and it almost fixes it, but there is still a slight curve, so I suspect my distance calculation is wrong. Thank you very much for the link. \$\endgroup\$ Commented Mar 31, 2015 at 9:21
  • \$\begingroup\$ @ReubenCrimp if you want a second source that uses the same method described in this answer, see Lode's Computer Graphics Tutorial on Raycasting. If you prefer a video see Wolfenstein 3D's map renderer, which is based on the actual source code of Wolfenstein 3D (and yes, it has the same basic approach for this problem). The video goes on a bit more detail than the linked articles (it talks about some of the optimizations done in the game). \$\endgroup\$
    – Theraot
    Commented Jun 22, 2019 at 16:05
3
\$\begingroup\$

Typically, you wouldn't space your rays at even angles. This is the source of the distortion. See this answer for details: https://gamedev.stackexchange.com/a/156853

\$\endgroup\$
2
  • \$\begingroup\$ how did you even stumble on this 5 year old questino? \$\endgroup\$ Commented Jul 13, 2020 at 7:11
  • 2
    \$\begingroup\$ I was actually googling how to create a fish eye effect in a raytracer. \$\endgroup\$
    – Kody King
    Commented Jul 13, 2020 at 7:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .