2
\$\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\$
  • \$\begingroup\$ How are you calculating your projection? \$\endgroup\$ – Panda Pajama Mar 31 '15 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\$ – Reuben Crimp Mar 31 '15 at 9:48
5
\$\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\$
  • \$\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\$ – Reuben Crimp Mar 31 '15 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 Jun 22 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.