On 12/07/2012 12:27 PM, Paul Martz wrote:
(Sorry if this shows up twice; I originally posted it Tuesday but it has not echoed back to the list. Test emails seem to work, so trying again...)

Hi Jeremy -- Since you know the FOV in y (it's 45.0 degrees), you can compute the distance to "fit" a bounding sphere with the following code:

double computeInitialDistanceFromFOVY( const osg::BoundingSphere& bs, const double fovy )
{
    return( bs.radius() / sin( osg::DegreesToRadians( fovy * .5 ) ) );
}

That code comes from the matrix utility library (osgwMx) in the osgWorks project, but equivalent code exists in osgGA to compute home positions, which you could also use as a reference.
   -Paul


Cool, thanks!

Chris Hanson explained this to me off the lists, as well. It's actually REALLY simple trig, but for whatever reason I just haven't ever thought of 3D math as anything other than voodoo magic.

Now, of course, it makes perfect sense, and I honestly think I've acquired a whole new perspective at solving problems in graphics mathmatically. I even went and picked myself up a trig/calc book at B&N to worth through over the next few weeks.

On 12/4/2012 7:47 AM, Jeremy Moles wrote:
Hello everyone! I'm writing a bit of code using parts of OSG and pure OpenGLES2. This isn't exactly an OSG question, per se, but there are a lot of OpenGL
experts here and this is a great resource. :) Any help is appreciated!

In my particular scene, I do not maintain a matrix representing my "camera"; there is a global projection matrix and each Drawable maintains its own model matrix. For this reason, whether pedantically right or wrong, I say that my
camera always sits at 0, 0, 0 and looks into a frustum created using the
equivalent of gluPerspective(45, 1, 1, 100).

What I'm looking for is the trigonometric calculation that would allow me to determine either the Z value to translate my scene or the scale to apply to my
scene in order to fit the entire thing cleanly into my viewport.

I have both the osg::BoundingBox and osg::BoundingSphere of my scene, but since I'm not using a camera manipulator or view matrix directly, I can't simply
reference the code in CameraManipulator.cpp.

Furthermore: I have this working currentls in a VERY TERRIBLE way. :) What I do
is use reimplementations of gluProject and gluUnproject to caclulate
screen-to-world and world-to-screen coordinates. I then use those values to figure out how much to scale my scene by, but this feels so wrong (and bound to
a known window size) that I know there must be a better way.

Thanks!
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to