I've been experimenting with picking and have come across
some odd behaviour - just wondering if anyone else has found something
similar.

Basically, I've defined a picking behaviour class that selects
a list of all objects along a ray from the mouse position,
and changes the diffuse colour of all picked objects from white
to red:

//=====================================================
  public class MousePick extends PickMouseBehavior
  {
    Material redSurface = new Material();

    public MousePick(Canvas3D canvas, BranchGroup branch, Bounds bounds)
    {
      super(canvas, branch, bounds);
      setSchedulingBounds(bounds);
      pickCanvas.setMode(PickTool.GEOMETRY);
      setTolerance(0.0f);
      redSurface.setDiffuseColor(1.0f, 0.0f, 0.0f);
    }

    public void updateScene(int xPos, int yPos)
    {
        // randSpheres is an object that contains several random spheres

      randSpheres.resetColors();   // Resets all objects to white
      pickCanvas.setShapeLocation(xPos, yPos);
      PickShape pickShape = pickCanvas.getPickShape();
      PickResult[] results = pickCanvas.pickAll();
      if (results != null) {
                for (int i = 0; i < results.length; i++) {
                        Shape3D shape = 
(Shape3D)results[i].getNode(PickResult.SHAPE3D);
                        shape.getAppearance().setMaterial(redSurface);
                }
        }
    }
//=========================================

I then generated several Sphere objects of varying size and position,
and test the MousePick class by clicking on the spheres in various
places. Since the tolerance has been set to zero, a sphere should turn
red only if the ray from the mouse into the scene actually intersects
the sphere. In most places, this is true, but in some cases, a sphere
will turn red when it is definitely NOT cut by the ray.

If the mouse is clicked outside all the spheres, no sphere is ever
selected, but occasionally when clicking on one sphere, the selected sphere
and another one that is nowhere near the picked ray will turn red.
Thus it seems that the picking is always able to determine whether or not
the mouse is clicked over an object, but sometimes mistakenly
includes objects in the picked list that shouldn't be there.

Just in case there was something odd about the geometric primitives,
I tried the same experiment using a Cube class that I wrote from scratch
using QuadArrays, and the same thing happened.

Is this a bug in the picking behaviour classes, or am I doing something
wrong?

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to