Changeset 7741 for OpenSceneGraph/trunk/examples/osgtext/osgtext.cpp
- Timestamp:
- 12/23/07 14:18:40 (5 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/examples/osgtext/osgtext.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgtext/osgtext.cpp
r7375 r7741 482 482 public: 483 483 484 UpdateTextOperation( osg::Group* group):484 UpdateTextOperation(const osg::Vec3& center, float diameter, osg::Group* group): 485 485 Operation("UpdateTextOperation", true), 486 _center(center), 487 _diameter(diameter), 486 488 _maxNumChildren(200), 487 489 _maxNumTextPerGeode(10), … … 545 547 for(unsigned int i=0; i<_maxNumTextPerGeode; ++i) 546 548 { 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); 548 550 549 551 std::string str; … … 556 558 osgText::Text* text = new osgText::Text; 557 559 text->setDataVariance(osg::Object::DYNAMIC); 558 text->setPosition( position);560 text->setPosition(_center + position * _diameter); 559 561 text->setFont("times.ttf"); 560 562 text->setText(str); 561 text->setCharacterSize(0.025f );563 text->setCharacterSize(0.025f * _diameter); 562 564 text->setAxisAlignment(osgText::Text::SCREEN); 563 565 … … 584 586 typedef std::list< osg::ref_ptr<osg::Geode> > AvailableList; 585 587 588 osg::Vec3 _center; 589 float _diameter; 586 590 unsigned int _maxNumChildren; 587 591 unsigned int _maxNumTextPerGeode; … … 619 623 osg::Group* mainGroup = new osg::Group; 620 624 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 621 637 for(unsigned int i=0; i<numThreads; ++i) 622 638 { … … 631 647 // create the operation that will run in the background and 632 648 // sync once per frame with the main viewer loop. 633 updateOperation = new UpdateTextOperation( textGroup);649 updateOperation = new UpdateTextOperation(center, diameter, textGroup); 634 650 635 651 // add the operation to the operation thread and start it. … … 644 660 osg::Geode* geode = new osg::Geode; 645 661 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))); 647 663 648 664 mainGroup->addChild(geode);
