Package eas.miscellaneous.java3D

Source Code of eas.miscellaneous.java3D.PickingTest

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.");
    }

  }

}
TOP

Related Classes of eas.miscellaneous.java3D.PickingTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.