freshfork / p5.EasyCam

A p5.js library for easy 3D camera control.
https://freshfork.github.io/p5.EasyCam
MIT License
138 stars 33 forks source link

Distance from point to camera #21

Closed jersonlatorre closed 2 years ago

jersonlatorre commented 2 years ago

Is there any way to calculate the distance from a point to the camera plain even if the camera is rotating?

jwdunn1 commented 2 years ago

The camera has a getPosition() method which returns the camera's position in the 3D space. Use the p5 method dist() to determine the distance between any points in space. I've updated this sketch to demonstrate. It finds the distance between the camera and the two end points of a line segment that runs through a cube. Then, in the HUD, depending on the mouse position, it displays the distance.

jersonlatorre commented 2 years ago

Thank you very much @jwdunn1 for your answer! That helps me a lot.