At 12:24 PM 11/23/99 -0500, David Charles Hirschfield wrote:
>I'm trying to do picking without extending PickMouseBehavior, but I
>haven't been able to get it to work.
>
>What I want to end up with is a method like:
>
>PickAt(x,y)

By a weird coincidence, I just finished getting this to work.

1. Go through your scene graph and (almost certainly) make almost
   everything non-pickable.
2. When you subclass PickMouseBehavior, you have to do some work in the
   constructor to set the bounds and so on.
3. Don't forget to put the subclassed PickMouseBehavior object in the
   scene graph.

Then it just seems to work.  Here's my subclassed behavior, I've only got
as far as figuring out that I got the right shape, haven't done anything
with it yet.

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.picking.*;

public class Picker extends PickMouseBehavior
{
  public Picker(BranchGroup root, Canvas3D canvas, Bounds bounds)
  {
    super(canvas, root, bounds);
    this.setSchedulingBounds(bounds);
  }

  public void updateScene(int xPos, int yPos)
  {
    System.err.print("pick at x="+xPos+", y="+yPos+" ...");
    SceneGraphPath sgPath;
    Shape3D shape;

    sgPath = pickScene.pickClosest(xPos, yPos);
    if (sgPath == null)
    {
      System.err.println("nothing there (sg)");
      return;
    }

    shape = (Shape3D) pickScene.pickNode(sgPath, PickObject.SHAPE3D);
    if (shape == null)
    {
      System.err.println("nothing there (shape)");
      return;
    }

    System.err.println(shape);
  }
}

===========================================================================
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