I have been trying to figure out a way to calculate distance from camera (perspective projection) to a 3D point.
Currently I have depth buffer containing orthographic distances (perpendicular) from camera's plane (red line on the picture) to the given point. But I'm having hard time coming up with a working solution calculating distance from the camera to that point.
So from that picture I'd like to calculate the length of the purple line. We know the rotation of the plane (red line on the picture), direction vector of purple line and length of the blue line.
In the following example I refer to purple line's direction vector as 'dv'.
In the situation when camera is pointing towards -y -axis (see picture) the length of the purple line can be calculated: blue/-dv.y - ie. Dividing the length of the blue line by the length of direction vector's y component.
I have read about quaternions and would like to use quaternions in a working solution (not neccessary) but I'm not certainly sure how to achieve that. Any help is greatly appreciated.