Class SpatialPicking

java.lang.Object
com.eco.bio7.spatial.SpatialPicking

public class SpatialPicking extends Object
Picks the object under the mouse in the 3D view (the selection mode of OpenGL): the objects are drawn between startPicking and endPicking with a name (glPushName / glPopName), getSelection returns the name of the nearest object at the mouse position.
pick.startPicking(gl, glu, getPressEvent());
gl.glPushName(100);
glut.glutSolidSphere(20, 10, 10);
gl.glPopName();
pick.endPicking(gl);
int id = pick.getSelection(); // 100 or -1
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a picking with a buffer of 1000 values and a picking area of 5 pixels.
    SpatialPicking(int buffSize, int pickArea)
    Creates a picking.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    endPicking(com.jogamp.opengl.GL2 gl)
    Ends the picking: the drawing is normal again, the name of the nearest object at the mouse position is the selection (-1 if no object was hit).
    int
    Returns the name of the nearest object at the mouse position of the last picking.
    void
    startPicking(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.newt.event.MouseEvent evt)
    Starts the picking at the position of a mouse event: the following objects are not drawn but tested at the mouse position (until endPicking).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpatialPicking

      public SpatialPicking()
      Creates a picking with a buffer of 1000 values and a picking area of 5 pixels.
    • SpatialPicking

      public SpatialPicking(int buffSize, int pickArea)
      Creates a picking.
      Parameters:
      buffSize - the size of the buffer of the hits (values, four for a hit with one name)
      pickArea - the size of the picking area around the mouse (pixels)
  • Method Details

    • startPicking

      public void startPicking(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.newt.event.MouseEvent evt)
      Starts the picking at the position of a mouse event: the following objects are not drawn but tested at the mouse position (until endPicking).
      Parameters:
      gl - the GL context
      glu - the GLU context
      evt - the mouse event (pixels of the 3D view from the top left)
    • endPicking

      public void endPicking(com.jogamp.opengl.GL2 gl)
      Ends the picking: the drawing is normal again, the name of the nearest object at the mouse position is the selection (-1 if no object was hit).
      Parameters:
      gl - the GL context
    • getSelection

      public int getSelection()
      Returns the name of the nearest object at the mouse position of the last picking.
      Returns:
      the name (see glPushName) or -1 if no object was hit