View Single Post
  #2  
Old 10-02-2009, 11:54 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Is your custom node using raw OpenGL command to render? If so, then collisions won't work because OpenSceneGraph will not know anything about the mesh of your object. There are two ways to handle this:

1) Use the built-in osg::Geometry class to render your object

2) Implement the following osg::Drawable methods in your custom drawable class:
Code:
virtual bool supports(osg::PrimitiveFunctor&) const;
virtual void accept(osg::PrimitiveFunctor& pf) const;
These methods allow you to pass information about your mesh to OpenSceneGraph, which will allow it to participate in collision/intersection/pick tests. Here is a very simple example showing how to implement this for a simple quad:
Code:
virtual bool supports(osg::PrimitiveFunctor&) const { return true; }

virtual void accept(osg::PrimitiveFunctor& pf) const
{
    pf.begin(GL_QUADS);
    pf.vertex(-1,1,0);
    pf.vertex(1,1,0);
    pf.vertex(1,-1,0);
    pf.vertex(-1,-1,0);
    pf.end()
}
Reply With Quote