Hi,

        This is all very nice, but there's an element that makes my problem particular
and harder to solve: all the objects are loaded from a VRML file using a VRML97
loader.  All the Shape3D's geometry objects don't have the ALLOW_INTERSECT
capability bit set (and it seems that I can't set it), so none will report a
pick using geometry.

        If I were creating the objects and adding them to the universe "manually", all
your solutions would be perfect.  Unfortunately... :)


> Great!  I had overlooked the Shape3D.intersect method.  This is the key!
> Once you have the picked Shape3D just intersect a ray generated from the
> mouse x,y with the shape, which gives you the distance.  Use the ray origin
> and vector scaled by this distance.  This makes it very easy...
> 
> Shape3D pick(Canvas3D canvas, BranchGroup rootBranchGroup, int x, int y,
> Point3d pickedPoint)
> {
>     PickObject po = new PickObject(canvas, rootBranchGroup);
>     SceneGraphPath sgp = po.pickClosest(x, y, PickObject.USE_GEOMETRY);
>     if(sgp!=null) {
>         PickRay ray = (PickRay)po.generatePickRay(x,y);
>         double distance[] = new double[1];
>         Vector3d rayvect = new Vector3d();
>         for( int i=sgp.nodeCount()-1 ; i>=0 ; i-- ) {
>             if(sgp.getNode(i) instanceof Shape3D) {
>                 Shape3D pickedShape = (Shape3D)sgp.getNode(i);
>                 if(pickedShape.intersect(sgp, ray, distance)) {
>                     ray.get(pickedPoint, rayvect);
>                     rayvect.scale(distance[0]);
>                     pickedPoint.add(rayvect);
>                     return pickedShape;
>                 }
>             }
>         }
>     }
>     return null;
> }
begin:vcard 
n:Bilodeau;Guillaume
tel;work:(613) 991-5037
x-mozilla-html:FALSE
org:National Research Council Canada;Visual Information Technology
adr:;;;;;;
version:2.1
email;internet:[EMAIL PROTECTED]
title:Software Engineer
x-mozilla-cpt:;-1
fn:Guillaume Bilodeau
end:vcard

Reply via email to