This "fix" is hereby withdrawn. This fix did more harm than good and
is clearly wrong. However, there's still an odd issue that I don't
quite understand, but I suspect it's either an obscure corner case
that most other won't come across or I'm simply mis-understanding
something. The original problem I was having was a parent node (an
osg::MatrixTransform node) wasn't calculating a bounding sphere. The
hierarchy is:

osg::MatrixTransform
--osg::Geode
    --osgText::Text

I'm using the osg::MatrixTransform to position the drawable due to the
higher precision offered by osg::MatrixTransform. Thus the drawable
has a postion of 0,0,0. Also, the drawable has auto rotate enabled
which factors in here. When calculating the bounding sphere for a
osg::MatrixTransform object it ultimately calls TextBase::computeBound
which due to the auto rotate doesn't properly calculate a bounding
sphere. This invalid bounding sphere is passed up the food chain and a
valid bound isn't calculated. I fixed this on my end by assigning my
own ComputeBoundingSphereCallback. There's usually more than one way
to handle a given challenge in the OSG.

Anyway, here's a trivial example:

Note: set a breakpoint in textbase.cpp in the osg::BoundingBox
TextBase::computeBound() const function - you'll see that if
autorotate is enabled an invalid bounding sphere is calculated which
is ultimately passed to the manipulator. This results in the end-user
not being able to see any text. Disabling auto-rotate corrects the
issue.

int main()
{
  osgViewer::Viewer viewer;
  viewer.setCameraManipulator( new osgGA::TrackballManipulator() );
  viewer.addEventHandler(new osgViewer::WindowSizeHandler);
  viewer.addEventHandler(new osgViewer::StatsHandler);

  osg::ref_ptr<osgText::Text> text = new osgText::Text();
  osg::ref_ptr<osg::Geode> geode = new osg::Geode();
  osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform();
  osg::ref_ptr<osg::Group> root = new osg::Group();

  osg::Vec3d pos;
  osg::EllipsoidModel em;
  em.convertLatLongHeightToXYZ(osg::DegreesToRadians(38.0),
osg::DegreesToRadians(-96.0), 1000.0, pos[0], pos[1], pos[2]);
  mt->setMatrix(osg::Matrix::translate(pos));

  text->setText("hello world");
  text->setAutoRotateToScreen( true );

  geode->addDrawable(text.get());
  mt->addChild(geode.get());
  root->addChild(mt.get());

  viewer.setSceneData( root.get() );
  viewer.setThreadSafeReferenceCounting(true);
  viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);

  viewer.realize();

  while(viewer.done() == false)
  {
    viewer.frame();
  }

  return 0;
}


So, can someone take a look and tell me what's going on here?

On Fri, Aug 8, 2008 at 8:45 PM, sherman wilcox <[EMAIL PROTECTED]> wrote:
> in transform.cpp - BoundingSphere Transform::computeBound()  the first
> few lines of code look like:
>
> BoundingSphere Transform::computeBound() const
> {
>    BoundingSphere bsphere = Group::computeBound();
>    if (!bsphere.valid()) return bsphere;
>
>   ...
> }
>
> After  "if (!bsphere.valid()) return bsphere;" the code continues on
> to calculate a bounding sphere. However, there's a bug here (I think.)
> Shouldn't this line read:
>
>    if (bsphere.valid() == true) return bsphere;
>
> OR
>
>    if (bsphere.valid()) return bsphere;
>
> It doesn't seem to make sense to return an invalid bounding sphere if
> Group::computeBound() returns an invalid object.
>
> Corrected code is attached.
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to