From c70e7bda86630b290ded7d272548549eb68b534e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 19 Apr 2011 09:54:14 +0000 Subject: [PATCH] Improved the handling of unitialized bounding box --- src/osgText/TextBase.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/osgText/TextBase.cpp b/src/osgText/TextBase.cpp index 6affba6d5..183979168 100644 --- a/src/osgText/TextBase.cpp +++ b/src/osgText/TextBase.cpp @@ -276,27 +276,33 @@ osg::BoundingBox TextBase::computeBound() const { for(unsigned int i=0;i<_autoTransformCache.size();++i) { - if (_autoTransformCache[i]._traversalNumber<0 && (_characterSizeMode!=OBJECT_COORDS || _autoRotateToScreen)) + if (_autoTransformCache[i]._traversalNumber>=0) { - // _autoTransformCache is not valid so don't take it into accoumt when compute bounding volume. -#if 1 - // so fallback to estimating the bounding box size by assuming a scale of 1 - // but might cause problems due to small feature culling... - osg::Matrix matrix; - matrix.makeTranslate(_position); - bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix); - bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMax())*matrix); -#endif - } - else - { osg::Matrix& matrix = _autoTransformCache[i]._matrix; bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix); bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMax())*matrix); } } + + + if (!bbox.valid()) + { + // provide a fallback in cases where no bounding box has been been setup so far + if (_characterSizeMode!=OBJECT_COORDS || _autoRotateToScreen) + { + // default to a zero size. + bbox.set(_position, _position); + } + else + { + osg::Matrix matrix; + matrix.makeTranslate(_position); + bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix); + bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMax())*matrix); + } + } } - + return bbox; }