A really great deal

Started by
2 comments, last by Eelco 19 years, 8 months ago
I have a really hard problem for all the math/OpenGL passionates. Let's suppose I have an OpenGL scene with several objects. How can I calculate the position/target/frustum/scale/... of my camera in the aim to see all the scene ? Hard ! (Maybe, we can not avoid dichotomy algorithms like : IF the box coating the scene is in the frustum I stop ELSE I back off my camera)
Advertisement
Well, it wouldn't be very hard to calculate the viewing angle would it, and from that I'm sure you could calculate a lot of other things.

All you would do is take the arc cosine of the dot product of the 2 vectors from the camera point to the outermost model vertices on the X axis and do the same for the Y axis and the Z axis, would you not? You would need to begin with a camera position for this, by the way.

Please, someone else double check me on this as I'm not experienced in these matters.
"Learn as though you would never be able to master it,
hold it as though you would be in fear of losing it" - Confucius
You should be able to trivially deduce the angular view of the camera, if this is not set when you create it. It's just a calibration step as red_sodium points out.

However, given this angular view, finding the exact distance along a view axis that incorporates ALL of the viewable object is slightly less trivial.

Compute the projection of the objects vertics into the view plane, with the plane centered at the rear most vertices that are visible along the view axis. Find the smallest circle that completely encompasses the projected object in this plane. Divide the diameter of this circle by the angular view of the camera and this gives you the distance from the view plane that the camera must be to see the object.

What is happening here is that the camera defines a cone in which objects are visible. You need to compute the projection of your object onto the base of the cone and the base should be just large enough to encompass that 2D projection of the object. Hence, for a fixed conic angle, the size of the base is linearly proportional to the height of the cone and so, if we fix the location of the base, then moving the camera way from the object (extending the height of the cone) extends the radius of the base. Make sense?

Cheers,

Timkin
your problem is underdefined. there are an infnite number of positions and orientations that statisfy your criteria, so there exist no unique solution to your problem.

youll need to come up with some other criteria in order to structurally solve this problem.

This topic is closed to new replies.

Advertisement