0

The Description

I want to focus my perspective camera on an object. The object can be of arbirary size and I'm not facing the object head on. The camera should focus on multiple parts of the object: the front, one side and the top.

The camera fov is always 90 degrees and the target position is the center of the object. The problem I'm currently facing is: How can I determine the position of the camera?

The interface I have to work with:

void setCameraPosition(Vector3 cameraPosition, Vector3 cameraTarget);

The part in my code that should calculate the position knows nothing about the camera except the fov which is always fixed at 90 degrees.


The following picture shows where I'm currently at (in a simpliefied 2d representation):

  • gray arrow = the camera which looks at the object
  • blue rectangle = some kind of bounding box around the object (just an idea)
  • black rectangle = the object itself
  • green markings = marks the sides of the object which the camera should look at. As we are in 2d, the camera looks only at 2 sides instead of 3 as it should in the real application

enter image description here

What I've looked at so far

  1. How to Fit Camera to Object However, the solution there assumes I'm facing the object head on, which I'm not.
  2. Camera Zoom To Fit Object This post does not help me as the camera position is already there and only a distance is calculated to place the object within the cameras frustrum.
ShadowDragon
  • 2,088
  • 4
  • 16
  • 31
  • 1
    you just add the desired `distance+camera_focal_length` of object/camera to object center in opposite direction to camera view direction. The distance is computed from object size (or OBB) and camera FOV and chose the bigger one in case of aspect ratio is not 1:1 or non spherical BBOX. in case you are constructing the matrix your self do not forget its inversed (in native GL matrix notations)!!! So you need object position and size or BBOX, camera FOVs , focal length (znear) and direction as input. – Spektre Aug 11 '21 at 07:26

0 Answers0