I’m trying to focus on a
Mesh object when it is clicked. I currently have it working except for one slight issue.
Consider the following example, with the scene set up as so, with the first (largest) sphere at the centre:
If I click the green sphere, focus successfully switches to it:
So all seems well.
However, consider the same scene setup, but the camera has been rotated (using
Clicking on the green sphere still shifts focus (even if my screenshot doesn’t make it obvious), but it is occluded by the objects in front of it:
How can I use the position of the object to also rotate the camera (not the objects) so the clicked item is always in view? So I can go from this:
I currently have code to test whether objects are blocking a given object from the camera (using raycasters) but I’m not sure how to use this to determine the angle to rotate the camera by.
Additionally, when the object is clicked, I’d like to zoom in as much as possible so the sphere takes up the majority of the screen, i.e., something like this:
But I’m not sure how to calculate the amount to zoom in, mathematically speaking.