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
}
}
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org