From fc0c2a76c1484b8f31b951f85f90932f37673ea5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 26 Jun 2014 10:53:16 +0000 Subject: [PATCH] From Farshid Lashkari, "I noticed that Text3D objects would change there z alignment depending on the alignment mode. I'm not sure if this was intentional or just a simple mistake. My expectation was that the front of the object would always stay aligned to the 0 z-plane, regardless of the alignment mode. I've attached an updated version that retains a consistent z-alignment." "I just now noticed another issue with Text3D objects. It was not properly computing the bounding box when non-axis aligned rotations were being applied. In this case all corners of the bounding box need to be transformed in order to get the correct containing box. I've attached the updated file." "The incorrect bounding box problem also applies to regular Text objects. I've attached the fix for that as well as the original Text3D fix." git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/branches/OpenSceneGraph-3.2@14295 16af8721-9629-0410-8352-f15c8da7e697 --- src/osgText/Text3D.cpp | 28 +++++++++++++++++----------- src/osgText/TextBase.cpp | 26 ++++++++++++++++---------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/osgText/Text3D.cpp b/src/osgText/Text3D.cpp index ecd64aea1..8017aa416 100644 --- a/src/osgText/Text3D.cpp +++ b/src/osgText/Text3D.cpp @@ -418,8 +418,14 @@ osg::BoundingBox Text3D::computeBound() const for(unsigned int i=0;i<_autoTransformCache.size();++i) { 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); + bbox.expandBy(_textBB.corner(0)*matrix); + bbox.expandBy(_textBB.corner(1)*matrix); + bbox.expandBy(_textBB.corner(2)*matrix); + bbox.expandBy(_textBB.corner(3)*matrix); + bbox.expandBy(_textBB.corner(4)*matrix); + bbox.expandBy(_textBB.corner(5)*matrix); + bbox.expandBy(_textBB.corner(6)*matrix); + bbox.expandBy(_textBB.corner(7)*matrix); } } @@ -432,17 +438,17 @@ void Text3D::computePositions(unsigned int contextID) const switch(_alignment) { - case LEFT_TOP: _offset.set(_textBB.xMin(),_textBB.yMax(),_textBB.zMin()); break; - case LEFT_CENTER: _offset.set(_textBB.xMin(),(_textBB.yMax()+_textBB.yMin())*0.5f,_textBB.zMin()); break; - case LEFT_BOTTOM: _offset.set(_textBB.xMin(),_textBB.yMin(),_textBB.zMin()); break; + case LEFT_TOP: _offset.set(_textBB.xMin(),_textBB.yMax(),0.0f); break; + case LEFT_CENTER: _offset.set(_textBB.xMin(),(_textBB.yMax()+_textBB.yMin())*0.5f,0.0f); break; + case LEFT_BOTTOM: _offset.set(_textBB.xMin(),_textBB.yMin(),0.0f); break; - case CENTER_TOP: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,_textBB.yMax(),_textBB.zMin()); break; - case CENTER_CENTER: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,(_textBB.yMax()+_textBB.yMin())*0.5f,_textBB.zMin()); break; - case CENTER_BOTTOM: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,_textBB.yMin(),_textBB.zMin()); break; + case CENTER_TOP: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,_textBB.yMax(),0.0f); break; + case CENTER_CENTER: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,(_textBB.yMax()+_textBB.yMin())*0.5f,0.0f); break; + case CENTER_BOTTOM: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,_textBB.yMin(),0.0f); break; - case RIGHT_TOP: _offset.set(_textBB.xMax(),_textBB.yMax(),_textBB.zMin()); break; - case RIGHT_CENTER: _offset.set(_textBB.xMax(),(_textBB.yMax()+_textBB.yMin())*0.5f,_textBB.zMin()); break; - case RIGHT_BOTTOM: _offset.set(_textBB.xMax(),_textBB.yMin(),_textBB.zMin()); break; + case RIGHT_TOP: _offset.set(_textBB.xMax(),_textBB.yMax(),0.0f); break; + case RIGHT_CENTER: _offset.set(_textBB.xMax(),(_textBB.yMax()+_textBB.yMin())*0.5f,0.0f); break; + case RIGHT_BOTTOM: _offset.set(_textBB.xMax(),_textBB.yMin(),0.0f); break; case LEFT_BASE_LINE: _offset.set(0.0f,0.0f,0.0f); break; case CENTER_BASE_LINE: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,0.0f,0.0f); break; diff --git a/src/osgText/TextBase.cpp b/src/osgText/TextBase.cpp index 16382067a..04748a107 100644 --- a/src/osgText/TextBase.cpp +++ b/src/osgText/TextBase.cpp @@ -279,8 +279,14 @@ osg::BoundingBox TextBase::computeBound() const if (_autoTransformCache[i]._traversalNumber>=0) { 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); + bbox.expandBy(_textBB.corner(0)*matrix); + bbox.expandBy(_textBB.corner(1)*matrix); + bbox.expandBy(_textBB.corner(2)*matrix); + bbox.expandBy(_textBB.corner(3)*matrix); + bbox.expandBy(_textBB.corner(4)*matrix); + bbox.expandBy(_textBB.corner(5)*matrix); + bbox.expandBy(_textBB.corner(6)*matrix); + bbox.expandBy(_textBB.corner(7)*matrix); } } @@ -305,14 +311,14 @@ osg::BoundingBox TextBase::computeBound() const matrix.makeTranslate(-_offset); matrix.postMultRotate(_rotation); matrix.postMultTranslate(_position); - bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix); - bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*matrix); - bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix); - bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*matrix); - bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMax())*matrix); - bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMax())*matrix); - bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMax())*matrix); - bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMax())*matrix); + bbox.expandBy(_textBB.corner(0)*matrix); + bbox.expandBy(_textBB.corner(1)*matrix); + bbox.expandBy(_textBB.corner(2)*matrix); + bbox.expandBy(_textBB.corner(3)*matrix); + bbox.expandBy(_textBB.corner(4)*matrix); + bbox.expandBy(_textBB.corner(5)*matrix); + bbox.expandBy(_textBB.corner(6)*matrix); + bbox.expandBy(_textBB.corner(7)*matrix); } } }