Hi,

I ran into an issue with osg::TextBase.cpp not computing the bounding box 
correctly.  The problem manifested whenever you used user rotations of 
non-multiple-of-90 degree angles.

I’ve attached a program demonstrating the problem and a patch against the 3.0.1 
release that fixed the issue.

John.

Attachment: TextBase.cpp.patch
Description: Binary data

#include <osg/Geode>
#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgText/Text>
#include <osg/PolygonMode>
#include <osg/BlendFunc>

struct BBDrawer : osg::NodeCallback
{
    inline BBDrawer(osg::Group* root) {
        _geom = 
osg::createTexturedQuadGeometry(osg::Vec3(0,0,0),osg::Vec3(1,0,0),osg::Vec3(0,1,0));
        _geom->setUseDisplayList(false);
        _geom->setUseVertexBufferObjects(false);
        _geom->getOrCreateStateSet()->setAttributeAndModes(new 
osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE));
        osg::Geode* geode = new osg::Geode;
        geode->addDrawable(_geom);
        root->addChild(geode);
    }

    virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
    {
        osg::Geode* geode = dynamic_cast<osg::Geode*>(node); if (!geode) return;
        osg::BoundingBox bb = geode->getBoundingBox(); if (!bb.valid()) return;
        osg::Matrix g2w = osg::computeLocalToWorld(nv->getNodePath());
        osg::Vec3 corner    =  bb.corner(0x0)*g2w;
        osg::Vec3 widthVec  = (bb.corner(0x1)*g2w - corner);
        osg::Vec3 heightVec = (bb.corner(0x2)*g2w - corner);
        osg::Vec3Array* coords = 
static_cast<osg::Vec3Array*>(_geom->getVertexArray());
        (*coords)[0] = corner+heightVec;
        (*coords)[1] = corner;
        (*coords)[2] = corner+widthVec;
        (*coords)[3] = corner+widthVec+heightVec;
        _geom->setVertexArray(coords);
        _geom->dirtyBound();
    }

    osg::ref_ptr<osg::Geometry> _geom;
};

void main(int argc, char*argv[])
{
    osgText::Font* font = osgText::readFontFile("fonts/arial.ttf");

    osg::Group* root = new osg::Group;

    osg::Geode* normalG = new osg::Geode;
    osgText::Text* normal = new osgText::Text;
    
normal->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT);
    normal->setAxisAlignment(osgText::Text::USER_DEFINED_ROTATION);
    normal->setRotation(osg::Quat(osg::DegreesToRadians(45.f),osg::Z_AXIS));
    normal->setFont(font);
    normal->setFontResolution(32,32);
    normal->setCharacterSize(1.f);
    normal->setText("normal");
    normal->setName("normal");
    normal->setDrawMode(osgText::Text::TEXT);

    normalG->setName("normal");
    normalG->addDrawable(normal);
    normalG->setUpdateCallback(new BBDrawer(root));
    root->addChild(normalG);

    osgGA::TrackballManipulator* manip = new osgGA::TrackballManipulator;
    manip->setHomePosition(osg::Vec3(0,0,30),osg::Vec3(0,0,0),osg::Vec3(0,0,1));

    osgViewer::Viewer viewer;
    viewer.setUpViewInWindow(16,32,640,480);
    viewer.setCameraManipulator(manip);
    viewer.setSceneData(root);
    viewer.run();
}
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to