Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 1298 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!