Hi,
I have failed to draw a line between a osg::Text and a 3D model,like image
below
So far,I have managed modify osg::Text to draw a linking line ,like draw a
bounding box .
One end of the line is linked to the text,but I do not know how to link another
end to a moving 3D model.
I figure must do something to compute the world matrix of the 3D model
,then convert it to the local matrix of the osg::Text,then draw another end of
the line to the local matrix.
here is what I have done,and the result is not good.
1. ////////////////a class to get the text Wolrd To Local
class GetWolrdToLocalVisitor:public osg::NodeVisitor
{
public :
GetWolrdToLocalVisitor():
osg::NodeVisitor(NodeVisitor::TRAVERSE_PARENTS),done(false)
{
wcMatrix = new osg::Matrixd();
}
virtual void apply(osg::Node& node)
{
if(!done)
{
if (0 == node.getNumParents())
{
wcMatrix->set(osg::computeWorldToLocal(this->getNodePath()));
done = true;
}
traverse(node);
}
}
virtual void apply(osg::Geode& node)
{
apply((osg::Node&)node);
traverse(node);
}
osg::Matrixd* giveUpDaMat()
{
return wcMatrix;
}
private:
bool done;
osg::Matrix* wcMatrix;
};
osg::Matrixd* getTextWorldToLocalCoords(osg::Geode* node)
{
osg::ref_ptr< GetWolrdToLocalVisitor> nwl = new GetWolrdToLocalVisitor();
if (node && nwl)
{
node->accept(*nwl);
// osg::notify(osg::NOTICE)<<"GetLocalToWolrdVisitor:
node->accept(*nwl);"<<std::endl;
return nwl->giveUpDaMat();
}else
{
return NULL;
}
}
2.
////////////// 3DModelWorld is the 3D model position, _geode is the
parent of a osg::text
osg::Vec3d local = (*getTextWorldToLocalCoords(_geode))* 3DModelWorld;
Thank you!
Cheers,
Lv
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61951#61951
Attachments:
http://forum.openscenegraph.org//files/dsc_719.jpg
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org