Hi Mathieu,
On 17/07/10 1:32 , Mathieu Scorpionis wrote:
> I try to manage with the model of an aircraft. I whish my 3d model to react
> to the
> mouse cursor when one of its sub-models is intersected by this cursor.
>
> This is the simplified architecture of the OSG file :
>...
> osg::Group *groupSceneRoot;
> osg::Group *ExteriorCab;
> osg::Group *ExteriorCab_OFFSET;
>...
> groupSceneRoot = mModel->asGroup();
> ExteriorCab = groupSceneRoot->getChild(0)->asGroup();
> ExteriorCab_OFFSET = ExteriorCab->getChild(0)->asGroup();
>...
First of all, you should adopt the habit of keeping osg::ref_ptr rather than
raw pointers
of OSG objects. They might be deleted which leaves you with a dangling,
invalid pointer.
> for (int i=0;i<8;i++)
> ListGeodeStateSet[index] = ListGeode[i]->getOrCreateStateSet();
>
> // What I want is to display only polygons if the cursor mouse picks a
> sub-model
> (here, one of the 8 geodes that decompose the whole aircraft):
>
> osg::PolygonMode *PolyModeObj[8];
> for (int i=0;i<8;i++)
> {
> PolyModeObj[i] = dynamic_cast< osg::PolygonMode* >
> ( ListGeodeStateSet[i]->getAttribute(
> osg::StateAttribute::POLYGONMODE ));
> if ( !PolyModeObj[i] )
> {
> PolyModeObj[i] = new osg::PolygonMode;
> ListGeodeStateSet[i]->setAttribute( PolyModeObj[i]);
> }
> }
I'd actually not worry about looking up (and storing) StateSets and PolygonModes
beforehand. It makes the core more complex and doesn't really gain you
anything. But
that's more a question of coding style. If you have/want to, use osg::ref_ptr,
see above.
> // In the pick callback, I check which geode was selected by the cursor:
> osgUtil::LineSegmentIntersector::Intersections::iterator hitr;
> if (Viewer->computeIntersections(x, y, intersections))
> {
> hitr = intersections.begin();
> osg::Geode *GeodeParent = hitr->drawable->getParent(0)->asGeode();
> for (int d=0;d<8;d++)
> {
> if (GeodeParent == ListGeode[d])
> {
> PolyModeObj[d]->setMode( osg::PolygonMode::FRONT_AND_BACK,
> osg::PolygonMode::LINE );
> break;
> }
> }
> }
>
> But... when the cursor selects the geode ExteriorCab_GEODE, the whole aircaft
> moves to
> polygon display (even wheels, tail and the rest...). Only the cabin should
> appear as polygons.
Most likely (depends on how the object is modelled) this is because the
'ExteriorCa-GEODE'
StateSet is shared with other Geodes. You can easily verify this by comparing
the
StateSet pointer values.
If you want to avoid that you need to give each Geode it's private (deep) copy
of the
StateSet. This however incurs a performance penalty, as now there are more
StateSets.
Hope this helps,
/ulrich
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org