[osg-users] osgText::Text rotation

Dirk Uys dirkcuys at gmail.com
Wed Mar 11 07:18:49 PDT 2009


I'm new to OSG, but not so new to scene graphs in general.

I'm trying to make some changes to osgGIS to suit my needs. I wish to
change the BuildLabelsFilter to rotate labels so that they face away
from the terrain. Here is a short piece of code to show what I've done


    osg::Vec3d up( input->getExtent().getSRS()->getUpVector(point) );
    osg::Quat rotation;
    rotation.makeRotate( up, osg::Vec3d(0, 0, 1) );

    // build the drawable:
    osgText::Text* t = new osgText::Text();
    t->setAutoRotateToScreen( false );
    t->setCharacterSizeMode( osgText::Text::SCREEN_COORDS );
    t->setAlignment( osgText::Text::CENTER_CENTER );
    t->setText( text.c_str() );
    t->setColor( color );
    t->setCharacterSize( (float)font_size );
    t->setPosition( point );
    t->setBackdropType( osgText::Text::OUTLINE );
    t->setBackdropColor( osg::Vec4(0,0,0,1) );


But the results are not correct (see screenshot).

If I add a line from point to (point + rotation*Vec3d(0, 0, 1)), the
line gets rotated correctly and coincides with the up vector.

I also tried using
but in this case the text completely disappears.

If I change rotation.makeRotate( up, osg::Vec3d(0, 0, 1) ); to
rotation.makeRotate( 0.0, osg::X_AXIS, osg::inDegrees(80.0),
osg::Y_AXIS, 0.0, osg::Z_AXIS );
It looks like the text are rotated by 80 degrees around the Y axes and
then projected onto the XY plane?

Rotating around the Z axis seems to be working fine

I looked at the osgtext example and the setAxisAlignment() works as expected.

Am I understanding the use of osgText::Text::rotate() incorrectly, or
is there something else I'm doing wrong?

I'm using OSG 2.8.0 and OSGGIS from the svn repository - last updated
to rev 179.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: screen_shot_0.jpg
Type: image/jpeg
Size: 47080 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090311/d1c3d267/attachment-0003.jpg>

More information about the osg-users mailing list