My public class PickHighlightBehavior extends the deprecated class com.sun.j3d.utils.behaviors.picking.PickMouseBehavior. The class is based on http://primordial.cic.unb.br/lcmm/cursos/pmm99.1/a9/PickHighlightBehavior.html which appears to be written at Sun.
Here are two of the fields of PickHighlightBehavior and its constructor, the canvas is the Canvas3D object associated with the scene, while root is the BranchGroup corresponding to the root of the scene associated with canvas.
private com.sun.j3d.utils.picking.PickCanvas pickCanvas;
private ShapeGrammarWorld shapeGrammarWorld;
public PickHighlightBehavior(ShapeGrammarWorld shapeGrammarWorld,
Canvas3D canvas, BranchGroup root,
Bounds bounds) {
super(canvas, root, bounds);
this.shapeGrammarWorld = shapeGrammarWorld;
this.setSchedulingBounds(bounds);
root.addChild(this);
pickCanvas = new com.sun.j3d.utils.picking.PickCanvas(canvas, root);
}
When the class uses deprecated code in updateScene, it works correctly -- shape3D is not null when a shape in the scene is picked.:
public void updateScene(int xpos, int ypos) {
Shape3D shape3D;
shape3D = (Shape3D) pickScene.pickNode(pickScene.pickClosest(xpos, ypos,
PickObject.USE_BOUNDS),
PickObject.SHAPE3D);
System.out.println(shape3D);
// ommitted code that highlights and dehighlights the shape
}
.
In contrast, the following code does not contain any deprecated code and also does not work (pickResult is always null, even when I pick one of the faces of a shape in the scene):
public void updateScene(int xPos, int yPos) {
com.sun.j3d.utils.picking.PickResult pickResult =
pickCanvas.pickClosest();
PickShape pickShape = pickCanvas.getPickShape();
PickConeRay pickConeRay = (PickConeRay) pickShape;
System.out.println("Update a scene " + pickResult);
// ommitted code that highlights and dehighlights the shape
}
The result of running this code is that .
How can I do what I really want to do: find the exact intersection point of the PickConeRay and the shape (a flat box -- with one dimension 0) and use non-deprecated classes or methods.
Any help would be greatly appreciated.
Thanks,
Mark
Mark Tapia
Research Scientist
Department of Architecture
Massachusetts Institute of Technology
Phone: 1.617.253.1721 Fax: 1.617.253.8221
Website: http://architecture.mit.edu/house_n/web/people/principal.htm