So I have a scene of objects and a camera.
What I would like to do is calculate the position of the camera such that:
- All objects are fully contained in the viewport AND
- The camera is as close as possible to the objects.
So in more plain english, the effect I’m going for is that all objects in the scene can always be seen, and the camera is located as close as possible to the objects where this is still the case.
I realise that a number of constaints must be applied to the problem so that one unique solution (I.E. one unique position of the camera) can be calculated.
These constraints are:
- The camera will always look down the negative Z axis
- The X and Y coordinates of the camera position will be the center of the bounding box of the objects
- The projection matrix is created using glFrustum
I hope that the problem is clear and that I have listed all the constraints required for there to be one solution.
Does anyone have any idea of how I can solve this?