Hi,

there is a picking mechanism included in OpenSG, which intersects a
ray with some geometry. The returned information include the Node that
was hit, the polygon within the node, the exact location on that
polygon, and so on. We have a method within our framework that looks
like this


void getObjectAt(int x, int y, OSG::NodePtr &node,
                                      OSG::Pnt3f &hitPoint, OSG::Vec3f
&hitNormal,
                                      OSG::Int32 &hitTriangleIndex)
{

   Line line;

   PerspectiveCameraPtr camera = scene->getCamera();
   NodePtr root = scene->getObjectsRoot();
   ViewportPtr vp = getViewport();

   camera->calcViewRay(line, x, y, *vp);

   IntersectAction *action = IntersectAction::create(line);

   action->apply(root);

   if (action->didHit())
   {
      // cerr << "SGQGLManagedWidgetP::selectObjectAt info: hit
something" << endl;
      node = action->getHitObject();
      hitPoint = action->getHitPoint();
      hitNormal = action->getHitNormal();
      hitTriangleIndex = action->getHitTriangle();
   }
   else
   {
      // cerr << "SGQGLManagedWidgetP::selectObjectAt info: hit
nothing" << endl;
      node = NodePtr(0);
      hitPoint = Pnt3f(0.0f, 0.0f, 0.0f);
      hitNormal = Vec3f(0.0f, 1.0f, 0.0f);
      hitTriangleIndex = 0;
   }

   delete action;
}

Maybe you want to look into the IntersectAction to see if there is
some other info you are interested in. I found that the normals are
not always computed the way I expected, so I wrote a little funtion
that computes the normal of the hitPoint based on the index of the hit
Polygon. If you need something like that, let me know.

Cheers,
Daniel
















On 14/03/2008, Christoph John <[EMAIL PROTECTED]> wrote:
> Hello,
>  I am quite new to opensg and I am searching for a way to obtain a polygon on 
> which a user has clicked.
>  Is there a kind of color picking or something similar already integrated 
> into opensg and where do I find it?
>  Thanks for your help
>
>  Cheers
>   Christoph
>  --
>  Psssst! Schon vom neuen GMX MultiMessenger gehört?
>  Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
>
>  -------------------------------------------------------------------------
>  This SF.net email is sponsored by: Microsoft
>  Defy all challenges. Microsoft(R) Visual Studio 2008.
>  http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>  _______________________________________________
>  Opensg-users mailing list
>  [email protected]
>  https://lists.sourceforge.net/lists/listinfo/opensg-users
>


-- 
Daniel Wickeroth
Moltkestraße 88
50674 Köln

Home  0221 3569325
Work  0221 478 86502
Mobil 0176 700 40 252

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to