Hopefully someone can solve this. I've tried every variation of the equation and chatGPT can only get u so far.
I'm trying to determine the needed Z elevation of a 2D object in a 3D space with perspective projection, usually called "Z-buffer" or "Z-depth" calculation.
Basically i got an image thats far away or too close (doesnt matter) and i would like to set the zElevation of that 2D object to fill the screen/viewport, or "camera".
This is a simplified c3p:
drive.google.com/file/d/1HrSf4En9MY8CA1c9qAfPNrySDg-iX0ip/view
press/click to toggle between the (wrong) z distance calculation and the manually inputed one that i wish i could get the calculation to equal to
Im really hoping someone can edit this to make it work, Thanks in advance
reference to another topic that mentions some of this:
construct.net/en/forum/construct-3/general-discussion-7/height-pixels-163686
Heres a forum talking about it:
discourse.threejs.org/t/functions-to-calculate-the-visible-width-height-at-a-given-z-depth-from-a-perspective-camera/269
AND here is a JSFiddle that does EXACTLY what i want, but when ive tried to the same thing, i cant seem to...:
jsfiddle.net/tfoller/yt9vLo6j