On Tue, 2008-10-14 at 21:25 +0800, yang zhiyuan wrote: > Hi: > I have solved the problem how to get one char's position inside a > osgText::Text; > The purpose is to move cursor when input text. > > Here is my code: > updateCursorPos(const std::string& string, int position) > { > osg::Vec3 cursor_position = m_inputText->getPosition(); > //get the font resolution > osgText::FontResolution fr; > fr.first = FONT_RES_X; > fr.second = FONT_RES_Y; > > //m_inputText is the osg::Text from which you want to get the last > char's position > const osgText::Font* font = m_inputText->getFont(); > osgText::Font* font1 = const_cast<osgText::Font*>(font); > //get total size of input parameter string > //string is the the std::string inside the m_inputText > unsigned int size = string.size(); > osgText::Font::Glyph* glyph = font1->getGlyph(fr,size-1); > osgText::Font::GlyphTexture* glyphTexture = glyph->getTexture(); > > const osgText::Text::GlyphQuads * glyph_quads = > m_inputText->getGlyphQuads( glyphTexture ); > if( glyph_quads ) > { > int coord_size = glyph_quads->getTransformedCoords(0).size(); > int input_text_size = string.size(); // # chars on line. > if( position > 0 ) > { > // Get position of character under cursor > // There are 4 coords per character, BottomLeft, TopLeft, > // BottomRight, TopRight. We want the BottomRight. > osg::Vec3 glyph_pos = > glyph_quads->getTransformedCoords(0)[ position * 4 - 2 ]; > cursor_position[0] = glyph_pos[0]; // Use only the X > position > } > } > > }
I'm going to try and adapt this to osgWidget::Input. Right now I use a much different method for calculating the cursor position of my Input object (which doesn't work), so perhaps this will help. I will, of course, post more info soon. :) On a different note--are you writing your own widget library? > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org