Sign in to follow this  
Quadrat

A really great deal

Recommended Posts

Quadrat    122
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)

Share this post


Link to post
Share on other sites
red_sodium    216
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.

Share this post


Link to post
Share on other sites
Timkin    864
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

Share this post


Link to post
Share on other sites
Eelco    301
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.

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