Sign in to follow this  

Given yaw/pitch/FOV, calculate camera position to fit everything as exact as possible?

Recommended Posts

Hello all, the idea seems very simple:


While looking at the center of a given object/scene/mesh/cloudofpoints and a rotation that the camera needs to have, calculate the distance from the center to perfectly fit the object/scene/mesh/cloudofpoints on the screen.


However, this idea is appearantly really though to implement properly:

The object/scene/mesh/cloudofpoints can be of any width/height/length.

The screen can be of any width/height.

The camera is perspective, meaning that FOV somehow also plays a role in the equation.

The center might not necessarily be the center anymore when the camera has moved, as things can "stick out"


I got all the data you could possibly ever want/need:

-All the vertices in the scene, in world space

-Screen width/height

-FOV of camera

-All current camera matrices, that is view/projection

-Desired yaw/pitch of the new camera position


Things I managed to do:

Axis-Aligned object/scene/mesh/cloudofpoints bounding-box (blue)

Desired camera angle-aligned object/scene/mesh/cloudofpoints bounding-box (red)

Desired camera angle-aligned object/scene/mesh/cloudofpoints bounding-box aligned to world-axis (yellow)

The size of the object/scene/mesh/cloudofpoints when translated to your current camera position (green)

Failed attempt to apply a projection matrix to the yellow box  so that the sides would be sloped (cyan)


Screenshots of the bounding boxes when I want the camera to be rotated to the top/front/left of the object/scene/mesh/cloudofpoints:


I figured I wanted bounding boxes for the job because then it's easy to fill the formulas I found here:



Are any of my box approaches in the right direction?

Am I forgetting something insanely important?

Is it even possible to do?

Can I make sure the cyan box gets sloped depending on FOV?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this