package eas.miscellaneous.java3D;
import javax.media.j3d.Bounds;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.picking.PickResult;
import com.sun.j3d.utils.picking.behaviors.PickMouseBehavior;
/**
* A very simple use of a picking behaviour. The program prints
* which of the objects is picked.
*
* @author Frank Klawonn
* Last change 07.07.2005
* @see InteractionTest
*/
@SuppressWarnings("all")
public class PickingTest extends PickMouseBehavior
{
public PickingTest(Canvas3D pCanvas, BranchGroup root, Bounds pBounds)
{
super(pCanvas,root,pBounds);
setSchedulingBounds(pBounds);
}
//Specification of the action to be carried out when an object is picked.
public void updateScene(int xpos, int ypos)
{
Primitive pickedShape = null;
pickCanvas.setShapeLocation(xpos,ypos);
PickResult pResult = pickCanvas.pickClosest();
if (pResult != null)
{
pickedShape = (Primitive) pResult.getNode(PickResult.PRIMITIVE);
}
if (pickedShape != null)
{
System.out.println("The object "+pickedShape.getUserData()+" has been selected.");
}
else
{
System.out.println("No object has been selected.");
}
}
}