~ubuntu-branches/ubuntu/trusty/openscenegraph/trusty

« back to all changes in this revision

Viewing changes to OpenSceneGraph/examples/osgtext/osgtext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-07-29 04:34:38 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080729043438-no1h9h0dpsrlzp1y
* Non-maintainer upload.
* No longer try to detect (using /proc/cpuinfo when available) how many
  CPUs are available, fixing the FTBFS (due to -j0) on various platforms
  (Closes: #477353). The right way to do it is to support parallel=n in
  DEB_BUILD_OPTIONS (see Debian Policy §4.9.1), and adequate support has
  been implemented.
* Add patch to fix FTBFS due to the build system now refusing to handle
  whitespaces (Policy CMP0004 say the logs), thanks to Andreas Putzo who
  provided it (Closes: #482239):
   - debian/patches/fix-cmp0004-build-failure.dpatch
* Remove myself from Uploaders, as requested a while ago, done by Luk in
  his 2.2.0-2.1 NMU, which was never acknowledged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
481
481
{
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),
488
490
        _group(group)
544
546
 
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
            float x = float(rand()) / float(RAND_MAX) - 0.5f;
 
550
            float y = float(rand()) / float(RAND_MAX) - 0.5f;
 
551
            float z = float(i)      / float(_maxNumTextPerGeode) - 0.5f;
 
552
            osg::Vec3 position(x, y, z);
548
553
 
549
554
            std::string str;
550
555
            unsigned int _numCharacters = 5;
555
560
                        
556
561
            osgText::Text* text = new osgText::Text;
557
562
            text->setDataVariance(osg::Object::DYNAMIC);
558
 
            text->setPosition(position);
 
563
            text->setPosition(_center + position * _diameter);
559
564
            text->setFont("times.ttf");
560
565
            text->setText(str);
561
 
            text->setCharacterSize(0.025f);
 
566
            text->setCharacterSize(0.025f * _diameter);
562
567
            text->setAxisAlignment(osgText::Text::SCREEN);
563
568
            
564
569
            geode->addDrawable(text);
583
588
 
584
589
    typedef std::list< osg::ref_ptr<osg::Geode> > AvailableList;
585
590
 
 
591
    osg::Vec3                   _center;
 
592
    float                       _diameter;
586
593
    unsigned int                _maxNumChildren;
587
594
    unsigned int                _maxNumTextPerGeode;
588
595
    
618
625
        // create a group to add everything into.
619
626
        osg::Group* mainGroup = new osg::Group;
620
627
        
 
628
        osg::Vec3 center(0.5f,0.5f,0.5f);
 
629
        float diameter = 1.0f;
 
630
        
 
631
        osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
 
632
        if (loadedModel.valid())
 
633
        {
 
634
            mainGroup->addChild(loadedModel.get());
 
635
            
 
636
            center = loadedModel->getBound().center();
 
637
            diameter = loadedModel->getBound().radius() * 2.0f;
 
638
        }
 
639
        
621
640
        for(unsigned int i=0; i<numThreads; ++i)
622
641
        {
623
642
            osg::Group* textGroup = new osg::Group;
630
649
 
631
650
            // create the operation that will run in the background and
632
651
            // sync once per frame with the main viewer loop.
633
 
            updateOperation = new UpdateTextOperation(textGroup);
 
652
            updateOperation = new UpdateTextOperation(center, diameter, textGroup);
634
653
 
635
654
            // add the operation to the operation thread and start it.
636
655
            operationThread->add(updateOperation.get());
643
662
            // add a unit cube for the text to appear within.
644
663
            osg::Geode* geode = new osg::Geode;
645
664
            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)));
 
665
            geode->addDrawable(new osg::ShapeDrawable(new osg::Box(center,diameter)));
647
666
 
648
667
            mainGroup->addChild(geode);
649
668
        }