With a little more fiddling this seems to work.
Not sure if it leaks yet though...
void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea)
{
osgUtil::LineSegmentIntersector::Intersections intersections;
float x = ea.getX();
float y = ea.getY();
if (view->computeIntersections(x,y,intersections))
{
for(osgUtil::LineSegmentIntersector::Intersections::iterator
hitr = intersections.begin(); hitr != intersections.end(); ++hitr)
{
if (hitr->drawable.valid())
{
osgText::Text* theText =
dynamic_cast<osgText::Text*>(hitr->drawable.get());
if(theText)
{
std::string cpptext =
theText->getText().createUTF8EncodedString();
const char *c = cpptext.c_str();
printf("Text choosen:%s\n",c);
}
}
}
}
}
On 2010-12-07, at 8:32 PM, Barry wrote:
> Hello All
>
> Hopefully a simple question.
> How do I get the text out of a picked drawable?
>
> I need to reduce it to a simple char* string to pass it onto another
> programming language for processing.
>
> The following picker compiles except for the line:
>
> osg::ref_ptr<osgText::Text> theText =
> hitr->drawable.get();
> of course?
>
> Any idea what the correct syntax is for the cast?
>
> Or is there a simpler way to accomplish this?
>
> Thanks in advance for any advice.
>
>
> void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter&
> ea)
> {
> osgUtil::LineSegmentIntersector::Intersections intersections;
>
> float x = ea.getX();
> float y = ea.getY();
> if (view->computeIntersections(x,y,intersections))
> {
> for(osgUtil::LineSegmentIntersector::Intersections::iterator
> hitr = intersections.begin(); hitr != intersections.end(); ++hitr)
> {
> if (hitr->drawable.valid())
> {
> std::cout << "Object \"" <<
> hitr->drawable->className() << "\"" << std::endl;
>
> osg::ref_ptr<osgText::Text> theText =
> hitr->drawable.get();
>
> if(theText)
> {
> osgText::String value =
> theText->getText();
> std::string cpptext =
> value.createUTF8EncodedString();
> const char *c = cpptext.c_str();
> printf("Text choosen:%s\n",c);
> }
>
> }
> }
> }
> }
>
> Barry Evans
>
> Reality is that which, when you stop believing in it, doesn't go away.
> --Philip K. Dick
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Making the impossible very difficult,
OpenGALEN.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org