0
\$\begingroup\$

enter image description here

Eventually this problem will be 3D.

My player is looking forwards. There is an axis-aligned box on the screen (FOV is guaranteed to be 90, so boxes behind the player aren't considered.)

I want to get the coordinates of the point on box that is closest to the player's looking direction.

I.e., if the player turned towards the box, which point of the box would intersect with their line of vision first?

\$\endgroup\$
0
\$\begingroup\$

You could decompose that test into four separate tests:

For each edge AB, BC, CD, DA in the box ABCD, determine the distance to the ray. The closest of all four tests is your solution.

For the edge vs ray test, you could do segment-vs-segment, and just pretend the ray is a really long segment.

I found this 2D segment vs segment test that you can use for this.

Note that if multiple edges have distance 0 to the ray, you need to compute the actual intersections, and pick the one closest to the ray origin.

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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