Good morning Ilia,
Thanks for your detailed response even though this is out of support scope!
Let me explain what I meant by this:
involve more computations than I'd like it to
Using ProjectPointOnLine() the calculations by the script are as follows:
Transform 3D points to 2D screen space using WS().
Calculate my desired new point in screen space.
Transform the new point to 3D world space by projecting the new point onto the 3D line using ProjectPointOnLine().
Transform the new point back from 3D world space to 2D screen space using WS().
Do more things using these correct 2D coordinates of the new point.
The issue of this topic is addressed by step 3 but to further work properly with the point in 2D space I also need step 4. I in fact do not only need the 2D coordinates but the z component as well. I feel like there must be a mathematical formula to get the correct Z value without transforming all three vector components back and forth in steps 3 and 4. So the issue I have with the "hacky" solution is purely to reduce the amount of performed calculations to a bare minimum which to be completely honest is just a means to satisfy this itch of mine to optimize as much as possible. It's part of what makes programming fun to me. 🙂
Also it would really be interesting to grasp the mathematical concept behind this. As someone who taught himself 3D programming by reading a bunch of game dev tutorials 15 years ago this is super interesting. But enough rambling.
Regarding your question:
Why can't you first do your computations in screen space and only then use the ProjectPointOnLine() function?
In my example the script I'm currently working on takes the new point as a base and creates some more points around that which are not on the line so I can't use ProjectPointOnLine() for those. For that the new point must have the correct coordinates already so I can derive the other new points correctly, otherwise their position in the world will be skewed as well.
The frustum concept is something I'll have to take some time to fully understand how I can utilize that. Thanks for the hint.
Have a nice weekend,
Daniel