PDA

View Full Version : How can I calculate a view that displays my entire model?



tabor25
01-02-2002, 06:08 AM
Hello,
in the faq section i found an article describing how to calculate a view that displays the whole scene by using an orthographic projection. I must calculate this view for a perspective projection. How can i calculate the correct distance between the camera (eye-point) and the scene-centerpoint (reference-point), so that applying gluLookAt with the desired parameters leads in a view to the complete scene?

NicholasFrancis
01-02-2002, 06:51 AM
I THINK it goes something like this:




fov = cameras field-of-view in radians
r = radius of model
c = r / sin (fov/2)
dist = sqrt (r * r + c* c)


I havent had time to check it (just did some scribbling on the back of an envelope), but try it out http://www.opengl.org/discussion_boards/ubb/wink.gif

tabor25
01-03-2002, 02:20 AM
Hello Nicholas,

thank you very much, it works fine ;-)

Best regards

Michael Schuster

NicholasFrancis
01-03-2002, 03:16 AM
Originally posted by tabor25:
Hello Nicholas,

thank you very much, it works fine ;-)

Best regards

Michael Schuster
Glad to hear it.

FYI: The method used is to get the cross product of the up & forward vectors. The cross of two vectors is a vector that is perpendicular to the plane defined by the other two vectors. If you're intrested, I can mail you an LGPL 3D math library in C++ I took it from the CrystalSpace engine. Nothing special, but works nicely. If you want it, mail me at nicholasfrancis@mac.com