Camera viewing all objects

If I have a camera and a collection of 3D objects, how do I calculate the position of the camera so that I'll have all the objects visible in the camera's view

Thanks in advance.


Answer this question

Camera viewing all objects

  • Sharon F. Dooley

    Purely as a guess off the top of my head, you could use a form of flattening/projection to try and determine the cameras field of view.

    For example, if you flatten all objects onto the XY plane (that is, set all Z=0) and then compute the bounding area (in 2D/XY terms) you should be able to define the dimensions of a far clipping plane that would display all your objects.

    If you then set the camera as being a point "back" along the Z (looking at the XY plane) such that it is in front of all the objects you wish to view, you should be set.

    As ZMan said - chances are that the best solution will require some properties of the view/projection matrices and solving the equation to satisfy the given constraints. As such, you probably want to familiarise yourself with the mathematics behind transforms - in particular the projection transform.

    hth
    Jack



  • MrTibs

    I think one naive way is to compute a bounding sphere around all your objects then create a camera position that looks at the center of the sphere. Then you need to calculate the from position such that the radius of the sphere fits inside the view frustum. No I don't have the math handy :-)

    There's probably some very complicated optimal algorithms out there that will do a better fit than this.



  • Camera viewing all objects