Try this:

    osg::Matrix cell2map = env->getInputSRS()->getInverseReferenceFrame();
    osg::Vec3d feature_center = point * cell2map;
    feature_center.normalize();
    osg::Vec3d cell_center = osg::Vec3d(0,0,1) * cell2map;
    cell_center.normalize();
    osg::Quat q;
    q.makeRotate( cell_center, feature_center );


Glenn Waldron : Pelican Mapping : http://pelicanmapping.com :
+1.703.652.4791


On Wed, Mar 11, 2009 at 10:07 AM, Dirk Uys <dirkc...@gmail.com> wrote:

> Hi
>
> 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
>
> <code>
>
>    osg::Vec3d up( input->getExtent().getSRS()->getUpVector(point) );
>    up.normalize();
>    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->setRotation(rotation);
>    t->setPosition( point );
>    t->setBackdropType( osgText::Text::OUTLINE );
>    t->setBackdropColor( osg::Vec4(0,0,0,1) );
>
> </code>
>
> 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
>   t->setAxisAlignment(osgText::Text::YZ_PLANE);
> 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.
>
> Regards
> Dirk
>
> _______________________________________________
> 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

Reply via email to