Show
Ignore:
Timestamp:
12/23/07 14:18:40 (7 years ago)
Author:
robert
Message:

Renamed osgText::Font::SizePair? to osgText::FontSizePair? in prep for use this more
widely within osgText/freetype plugin.

Added support for inserting loading models into --mt multithreaded implementation.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgtext/osgtext.cpp

    r7375 r7741  
    482482public: 
    483483 
    484     UpdateTextOperation(osg::Group* group):         
     484    UpdateTextOperation(const osg::Vec3& center, float diameter, osg::Group* group):         
    485485        Operation("UpdateTextOperation", true), 
     486        _center(center), 
     487        _diameter(diameter), 
    486488        _maxNumChildren(200), 
    487489        _maxNumTextPerGeode(10), 
     
    545547        for(unsigned int i=0; i<_maxNumTextPerGeode; ++i) 
    546548        { 
    547             osg::Vec3 position(float(rand()) / float(RAND_MAX), float(rand()) / float(RAND_MAX), float(i)/float(_maxNumTextPerGeode)); 
     549            osg::Vec3 position(float(rand()) / float(RAND_MAX) - 0.5f, float(rand()) / float(RAND_MAX) - 0.5f, float(i)/float(_maxNumTextPerGeode) - 0.5f); 
    548550 
    549551            std::string str; 
     
    556558            osgText::Text* text = new osgText::Text; 
    557559            text->setDataVariance(osg::Object::DYNAMIC); 
    558             text->setPosition(position); 
     560            text->setPosition(_center + position * _diameter); 
    559561            text->setFont("times.ttf"); 
    560562            text->setText(str); 
    561             text->setCharacterSize(0.025f); 
     563            text->setCharacterSize(0.025f * _diameter); 
    562564            text->setAxisAlignment(osgText::Text::SCREEN); 
    563565             
     
    584586    typedef std::list< osg::ref_ptr<osg::Geode> > AvailableList; 
    585587 
     588    osg::Vec3                   _center; 
     589    float                       _diameter; 
    586590    unsigned int                _maxNumChildren; 
    587591    unsigned int                _maxNumTextPerGeode; 
     
    619623        osg::Group* mainGroup = new osg::Group; 
    620624         
     625        osg::Vec3 center(0.5f,0.5f,0.5f); 
     626        float diameter = 1.0f; 
     627         
     628        osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 
     629        if (loadedModel.valid()) 
     630        { 
     631            mainGroup->addChild(loadedModel.get()); 
     632             
     633            center = loadedModel->getBound().center(); 
     634            diameter = loadedModel->getBound().radius() * 2.0f; 
     635        } 
     636         
    621637        for(unsigned int i=0; i<numThreads; ++i) 
    622638        { 
     
    631647            // create the operation that will run in the background and 
    632648            // sync once per frame with the main viewer loop. 
    633             updateOperation = new UpdateTextOperation(textGroup); 
     649            updateOperation = new UpdateTextOperation(center, diameter, textGroup); 
    634650 
    635651            // add the operation to the operation thread and start it. 
     
    644660            osg::Geode* geode = new osg::Geode; 
    645661            geode->getOrCreateStateSet()->setAttribute(new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE)); 
    646             geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.5f,0.5f,0.5f),1.0))); 
     662            geode->addDrawable(new osg::ShapeDrawable(new osg::Box(center,diameter))); 
    647663 
    648664            mainGroup->addChild(geode);