1
\$\begingroup\$

I am following this tutorial for a Wolfenstein 3D engine. https://lodev.org/cgtutor/raycasting.html

Here is the relevant image from the tutorial:

enter image description here

I cannot figure out how dividing by rayDirX or rayDirY causes the distance calculation to work. The explanation given is about halfway down the page, right above this text if you search for it: "Calculate distance projected on camera direction".

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Assume this link will break some time in the future, but that a future reader would still like to understand your question and learn from your experience. So please include in the body of your question itself the relevant details needed to understand the calculation you're asking about. Including this content in your question also improves the search hits, bringing more folks with relevant experience to this page. \$\endgroup\$
    – DMGregory
    Mar 22, 2020 at 17:52
  • \$\begingroup\$ I added an image, but I'll come back later and add more detail \$\endgroup\$ Mar 22, 2020 at 19:56
  • \$\begingroup\$ @DMGregory I think I am in over my head with this question, I am not sure how to distill it down to a complete and concise question. Am I able to delete questions? \$\endgroup\$ Mar 22, 2020 at 21:41
  • \$\begingroup\$ You can, but I don't recommend it. I'll take a read through the article a little later tonight and see if I can help you distill down a relevant excerpt. \$\endgroup\$
    – DMGregory
    Mar 22, 2020 at 21:42
  • \$\begingroup\$ I read the section right underneath where I got stuck more carefully. Earlier I read the extended explanation wrong. I thought the tutorial digressed and derived in detail how to do the computationally more expensive but easier to understand method. The tutorial actually explains in the greater detail how it arrived at calculation that I am after. I fail, but I'll keep this question up. If you don't figure it out, I'll try to circle back later with an explanation. \$\endgroup\$ Mar 22, 2020 at 21:52

1 Answer 1

1
\$\begingroup\$

I believe I figured it out. This picture shows what I am after. How does perpWallDist = yDist/rayDirY? Using ratios you can deduce that yDist/rayDirY = euclidiean/rayDir. Then you can say that perpWallDist/dir = euclidean/rayDir. RayDir is equal to 1, that is just how the engine is setup, that vector is normalized. Therefore, perWallDist = yDist/rayDirY.

I would have never have figured this out on my own, but this makes sense and I can explain it. If there are other methods to solve this problem I would love to read them :)

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Nice work solving your problem, and thanks for posting your understanding. \$\endgroup\$
    – DMGregory
    Mar 23, 2020 at 2:36

You must log in to answer this question.

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