diff --git a/examples/osgtext/osgtext.cpp b/examples/osgtext/osgtext.cpp index 3a7fb5ca0..43ae3794a 100644 --- a/examples/osgtext/osgtext.cpp +++ b/examples/osgtext/osgtext.cpp @@ -481,8 +481,10 @@ class UpdateTextOperation : public osg::Operation { public: - UpdateTextOperation(osg::Group* group): + UpdateTextOperation(const osg::Vec3& center, float diameter, osg::Group* group): Operation("UpdateTextOperation", true), + _center(center), + _diameter(diameter), _maxNumChildren(200), _maxNumTextPerGeode(10), _group(group) @@ -544,7 +546,7 @@ public: for(unsigned int i=0; i<_maxNumTextPerGeode; ++i) { - osg::Vec3 position(float(rand()) / float(RAND_MAX), float(rand()) / float(RAND_MAX), float(i)/float(_maxNumTextPerGeode)); + osg::Vec3 position(float(rand()) / float(RAND_MAX) - 0.5f, float(rand()) / float(RAND_MAX) - 0.5f, float(i)/float(_maxNumTextPerGeode) - 0.5f); std::string str; unsigned int _numCharacters = 5; @@ -555,10 +557,10 @@ public: osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); - text->setPosition(position); + text->setPosition(_center + position * _diameter); text->setFont("times.ttf"); text->setText(str); - text->setCharacterSize(0.025f); + text->setCharacterSize(0.025f * _diameter); text->setAxisAlignment(osgText::Text::SCREEN); geode->addDrawable(text); @@ -583,6 +585,8 @@ public: typedef std::list< osg::ref_ptr > AvailableList; + osg::Vec3 _center; + float _diameter; unsigned int _maxNumChildren; unsigned int _maxNumTextPerGeode; @@ -618,6 +622,18 @@ int main(int argc, char** argv) // create a group to add everything into. osg::Group* mainGroup = new osg::Group; + osg::Vec3 center(0.5f,0.5f,0.5f); + float diameter = 1.0f; + + osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); + if (loadedModel.valid()) + { + mainGroup->addChild(loadedModel.get()); + + center = loadedModel->getBound().center(); + diameter = loadedModel->getBound().radius() * 2.0f; + } + for(unsigned int i=0; iadd(updateOperation.get()); @@ -643,7 +659,7 @@ int main(int argc, char** argv) // add a unit cube for the text to appear within. osg::Geode* geode = new osg::Geode; geode->getOrCreateStateSet()->setAttribute(new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE)); - geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.5f,0.5f,0.5f),1.0))); + geode->addDrawable(new osg::ShapeDrawable(new osg::Box(center,diameter))); mainGroup->addChild(geode); } diff --git a/include/osgText/Font b/include/osgText/Font index 7ce189df3..ac7af3718 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -24,6 +24,7 @@ #include #include #include + #include #include @@ -34,7 +35,6 @@ namespace osgText { class Font; class Text; - /** Read a font from specified file. The filename may contain a path. * It will search for the font file in the following places in this order: * - In the current directory @@ -176,12 +176,11 @@ protected: typedef std::vector< osg::ref_ptr > StateSetList; typedef std::map< unsigned int, osg::ref_ptr > GlyphMap; - typedef std::pair< unsigned int, unsigned int > SizePair; - typedef std::map< SizePair, GlyphMap > SizeGlyphMap; + typedef std::map< FontSizePair, GlyphMap > FontSizeGlyphMap; osg::ref_ptr _texenv; osg::ref_ptr _stateset; - SizeGlyphMap _sizeGlyphMap; + FontSizeGlyphMap _sizeGlyphMap; GlyphTextureList _glyphTextureList; // current active size of font diff --git a/include/osgText/KerningType b/include/osgText/KerningType index 5f6d81b05..2377bdc32 100644 --- a/include/osgText/KerningType +++ b/include/osgText/KerningType @@ -16,11 +16,15 @@ namespace osgText { + +typedef std::pair< unsigned int, unsigned int > FontSizePair; + enum KerningType { KERNING_DEFAULT, //default locked to integer kerning values KERNING_UNFITTED, //use floating point value for kerning KERNING_NONE //no kerning }; + } #endif /*OSGTEXT_KERNINGTYPE*/ diff --git a/src/osgText/DefaultFont.cpp b/src/osgText/DefaultFont.cpp index 877cc2261..ac1645beb 100644 --- a/src/osgText/DefaultFont.cpp +++ b/src/osgText/DefaultFont.cpp @@ -52,14 +52,14 @@ Font::Glyph* DefaultFont::getGlyph(unsigned int charcode) { if (_sizeGlyphMap.empty()) return 0; - SizeGlyphMap::iterator itr = _sizeGlyphMap.find(SizePair(_width,_height)); + FontSizeGlyphMap::iterator itr = _sizeGlyphMap.find(FontSizePair(_width,_height)); if (itr==_sizeGlyphMap.end()) { // no font found of correct size, will need to find the nearest. itr = _sizeGlyphMap.begin(); int mindeviation = abs((int)_width-(int)itr->first.first)+ abs((int)_height-(int)itr->first.second); - SizeGlyphMap::iterator sitr=itr; + FontSizeGlyphMap::iterator sitr=itr; ++sitr; for(; sitr!=_sizeGlyphMap.end(); diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 349ff55d1..4a489d286 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -347,7 +347,7 @@ osg::Texture::FilterMode Font::getMagFilterHint() const Font::Glyph* Font::getGlyph(unsigned int charcode) { - SizeGlyphMap::iterator itr = _sizeGlyphMap.find(SizePair(_width,_height)); + FontSizeGlyphMap::iterator itr = _sizeGlyphMap.find(FontSizePair(_width,_height)); if (itr!=_sizeGlyphMap.end()) { GlyphMap& glyphmap = itr->second; @@ -417,7 +417,7 @@ bool Font::hasVertical() const void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph) { - _sizeGlyphMap[SizePair(width,height)][charcode]=glyph; + _sizeGlyphMap[FontSizePair(width,height)][charcode]=glyph; int posX=0,posY=0;