I am new to Java 3D and am having trouble with picking behaviors.  The
tutorial is not really clear to me and the examples on the web seem to use
deprecated methods.  I think I have the basic concept correct, but things
do not seem to be working out.

I have a branchgroup (not the top level group) that has a number of
children.  These children are all of one class that is derived from
Shape3D.  The geometry of the object is set to a PointArray with one
point.  In short, the branchgroup contains a number of points.

I pass the branchgroup and the canvas3D object to the following behavior:

public class Highlight extends Behavior {

   private Canvas3D mCanvas;
   private BranchGroup mPickGroup;
   private static ColoringAttributes mColoringAttributes;
   private static Appearance mHighlightAppearance;
   private int mX,mY;

    /** Creates a new instance of Highlight */
   public Highlight(Canvas3D cv3d, BranchGroup bg) {

        mCanvas = cv3d;
        mPickGroup = bg;
        mColoringAttributes = new ColoringAttributes();
        mColoringAttributes.setColor(1.0f, 0.0f, 0.0f);
        mHighlightAppearance = new Appearance();
        mHighlightAppearance.setColoringAttributes(mColoringAttributes);

    }

    /**
     * initialize the Behavior
     * set initial wakeup condition
     * called when behavior becomes live
     */
    public void initialize(){
        // set initial wakeup condition
        this.wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_MOVED));
        return;
    }


    protected void processAWTEvent(AWTEvent e) {
        MouseEvent evt = (MouseEvent)e;
        mX = evt.getX();
        mY = evt.getY();
        return;
    }

    // called by Java 3D when appropriate stimulus occurs
    public void processStimulus(Enumeration criteria){

        WakeupCondition cond;
        AWTEvent event;

        cond = (WakeupCondition)criteria.nextElement();
        event = ((WakeupOnAWTEvent)cond).getAWTEvent()[0];
        processAWTEvent(event);

        PickRay ray = createPickRay(mCanvas, mX, mY);
        SceneGraphPath path = null;
        path = mPickGroup.pickClosest(ray);
        if (path != null) {
            Shape3D s = (Shape3D)path.getObject();
            if (s != null) {
                s.setAppearance(mHighlightAppearance);
            }
        }
        this.wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_MOVED));
        return;


    }

    private PickRay createPickRay(Canvas3D canvas, int x, int y)   {
        Point3d eye_pos = new Point3d();
        Point3d mouse_pos = new Point3d();

        canvas.getCenterEyeInImagePlate(eye_pos);
        canvas.getPixelLocationInImagePlate(x, y, mouse_pos);

        Transform3D motion = new Transform3D();
        canvas.getImagePlateToVworld(motion);
        motion.transform(eye_pos);
        motion.transform(mouse_pos);

        Vector3d direction = new Vector3d(mouse_pos);
        direction.sub(eye_pos);

        return new PickRay(eye_pos, direction);
    }

}

It is initialized as such:

        Highlight mousemoveBehavior = new Highlight(cv, bgNodes);
        mousemoveBehavior.setSchedulingBounds(new BoundingSphere());
        bg.addChild(mousemoveBehavior);

Where bgNodes is the aforementioned branchgroup with all the points and bg
is the top-level branchgroup.

However, the Highlight behavior does not seem to detect any geometry.  If
I assign the behavior to the top-level branchgroup, it appears to detect
other geometry in the scene (although I have trouble following the
debugger output).

Can anyone help clarify how I should be doing this?

Regards,
Todd

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