I’m making this simple 1st-person 3D environment and for that I need to know the distance of the camera (the 1st person) from the objects rendered on the screen.
Alternatively, is there a way to move the camera so that drawing 3D objects at (0, 0, 0) places them precisely on the camera? (and if so, what distance must I move the camera for this?)
I’ve also tried messing with the camera() function, but I didn’t really understand what it did.
EDIT: After decoding the mysterious
(height/2)/(tan(pi/6)) value in the default preset for the camera() function, I’ve noticed it is just the height of an equilateral triangle, meaning the camera has an angular span of 120° and is
sqrt(3)/2*height pixels away from the drawn plane.
However, objects disappear a bit prematurely when zooming towards the camera, the camera cannot zoom infinitely closely on a given object. After finding out that at precisely the size of
height/10, a box() shape hits the top and bottom of the screen simultaneously while passing through the camera, I’ve realized this is the camera’s “lens size”, or however you call this phenomena. In essence, a small equilateral triangle of a side length of
height/10 is cut off from the main triangle and whatever shape we’re left with has a length of
sqrt(3)*9/20*height, which comes out as 842 on my screen, which is also the same value at which a point() disappears behind the camera, which solves the mystery of the number 842 for me.
This is therefore the distance of the camera from the main plane, the 9/10 of the height of an equilateral triangle of a side length equal to the screen height (unless your screen is taller than it is wide, in which case, the width), or in the common tongue:
Anyone who’s interested in P3D, you’re welcome \o/