What is the distance of the camera from the (x, y, 0) plane in P3D?

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: height*9/20*pow(3).

Anyone who’s interested in P3D, you’re welcome \o/

1 Like

@Tsskyx – Thank you for sharing this exploration!

If I am understanding you right, you are describing the frustum:

A frustum is a geometric form: a pyramid with its top cut off. With the viewer’s eye at the imaginary top of the pyramid, the six planes of the frustum act as clipping planes when rendering a 3D view. Thus, any form inside the clipping planes is rendered and visible; anything outside those planes is not visible.

Setting the frustum has the effect of changing the perspective with which the scene is rendered. This can be achieved more simply in many cases by using perspective() .

Yes, that’s it. The only trouble is, the official reference is usually too vague, and as a result, people like me tend to get confused. I’d be great if the reference could be written so that not only people who are just starting out with Processing, but also those which are using Processing as an introductory programming language, could understand it. Because, you know, although people like Daniel Shiffman make an excellent job at talking to beginners, they do not usually cover every topic :stuck_out_tongue:

True. I didn’t actually discover frustum and perspective until I had been using Processing for years, and even then I have limited exposure to it. It is a process, and the learning never ends, really… I think the main “intermediate” habit is to regularly jump from the reference to the JavaDoc. Then the intermediate / advanced habit is to then jump to the source code on github.

Things become more documented as people suggest more documentation be added – so if you have specific ideas about how to improve the reference pages or provide examples that would have been more helpful to you, you should suggest or contribute them on processing-docs https://github.com/processing/processing-docs