Picking an object with the mouse

Hi all,

got a “little” problem here. I want to be able to pick an object by clicking on it with the mouse. I tried to use the gluPickMatrix method which I looked up in the OpenGLReference manual (http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_RM/sgi_html/ch06.html#id5557442)
. There’s an example which does not help me very much!

Here’s my code (using the example):
public void select(int mouseX, int mouseY)
{
this.gl.glSelectBuffer(5,this.pickingBuffer);
this.gl.glMatrixMode(GL.GL_PROJECTION); // Selects The Projection Matrix
this.gl.glLoadIdentity();
this.glu.gluPickMatrix( mouseX, (viewport[3]-mouseY), 1.0f, 1.0f, viewport);
//Apply The ortho Matrix
this.gl.glOrtho(-clipSize,+clipSize,-clipSize,+clipSize,-clipSize100,+clipSize100);
this.gl.glMatrixMode(GL.GL_MODELVIEW); // Select The Modelview Matrix
}

This select method is called when the mouse is clicked. The viewport variable is initialized in the display method of my GLEventListener by calling gl.glGetIntegerv (GL.GL_VIEWPORT, viewport), which is called before calling the select method. So I guess the viewport variable is initialized properly.
Don’t I have to call gl.glRenderMode(GL.GL_SELECT) somewhere? If yes, where do I have to call it and why isn’t it called in the example?

??? ??? ??? ??? ??? ???

Can somebody please help me?

Thanks

Search the forum with “pick”, there are sample codes.

Search for ‘PickObject’ Not ‘pick’.

Thanks!

Ok, now sometimes hits = -1 !!!
What does this mean?

Here’s my code for picking:
if (this.pick)
{
int selectBuf[] = new int[BUFSIZE];
int hits;
this.gl.glGetIntegerv(GL.GL_VIEWPORT,this.viewport);

              this.gl.glSelectBuffer(BUFSIZE,selectBuf);
              //Puts OpenGL In Selection Mode. Nothing Will Be Drawn.  Object ID's and Extents Are Stored In The Buffer. 
              this.gl.glRenderMode(GL.GL_SELECT); 

              this.gl.glInitNames();   // Initializes The Name Stack 
              this.gl.glPushName(0);   // Push 0 (At Least One Entry) Onto The Stack

              this.gl.glMatrixMode(GL.GL_PROJECTION);    // Selects The Projection Matrix
              this.gl.glPushMatrix();         // Push The Projection Matrix
              this.gl.glLoadIdentity();      // Resets The Matrix
        
              //This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is. 
              this.glu.gluPickMatrix( this.mouseX,  (viewport[3]-this.mouseY), 5.0, 5.0, viewport);
        
              //Apply The ortho Matrix  
              this.gl.glOrtho(-clipSize,+clipSize,-clipSize,+clipSize,-clipSize*100,+clipSize*100);
              this.id = 0;
              drawTargets();
        
              this.gl.glPopMatrix(); 
              this.gl.glFlush();
              
              hits = gl.glRenderMode(GL.GL_RENDER);
              
              System.out.println("HITS = " + hits);

I’m at work at the moment, so I can;t look at my code. But, if I remember correctly, I get -1 values when the ray I cast does not hit any of areas which have an object ID. Is this the case or are your -1 values just random and you receive them when your clicking on one of your intended objects?

The situation is as follows:

I get hits when I don’t expect the get one, and sometimes I get -1 hits! I tried integrate the code which I found in the forum whel I looked for ‘PickObject’.
Don’t have any idea what I’m doing wrong!

Here’s my code for the 3d-scene:

see next post :slight_smile:

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.LinkedList;
import java.util.Vector;

import net.display.framework.data.Target;
import net.display.framework.data.TargetContainer;
import net.java.games.jogl.GL;
import net.java.games.jogl.GLCanvas;
import net.java.games.jogl.GLDrawable;
import net.java.games.jogl.GLEventListener;
import net.java.games.jogl.GLU;
import net.java.games.jogl.GLUquadric;
import net.java.games.jogl.util.GLUT;

/**

  • @author Marco Stuber
    */
    public class OpenGLDrawer implements GLEventListener,MouseMotionListener,MouseListener
    {
    private LinkedList targetContainerList; //Contains all targetContainers
    private TargetContainer targetContainer;

    //OpenGL-Variablen
    //private ApplicationFrame applFrame; //wird benötigt um festzustellen ob die Displays gelöscht werden sollen
    private GLDrawable drawable; //Komponente die ein Ereignis ausgelöst hat
    private GLUquadric sphere; //Refenrenz auf ein 3dim. Objekt
    private GL gl;
    private GLU glu;
    private GLCanvas canvas;
    private GLUT glut;
    private int err;

    //diplay controlling
    private double mouseX;
    private double mouseY;
    private double mouseZ;
    private double[] worldX = new double[1];
    private double[] worldY = new double[1];
    private double[] worldZ = new double[1];
    private double[] centerX = new double[1];
    private double[] centerY = new double[1];
    private double[] centerZ = new double[1];
    private double model_view[] = new double[16];
    private double projection[] = new double[16];
    private int viewport[] = new int[4];
    private boolean locateCenterFlag = true;
    private double scaleFactor = 1.0;
    private double transparencyFactor = 1.0;
    private double clipSize = 2.5;
    private int xVector;
    private int yVector;
    private int zVector;
    private int transX;
    private int transY;
    private double[] sceneCenterPoint = new double[3];
    private double[] camPos = new double[3];

    private Target target;
    private double range,azimuth,elevation;
    private double[] color;
    private int ttl;

    //display settings
    double maxRange;
    private float hwRatio;
    private int width;
    private int height;

    //interaction
    private static final int BUFSIZE = 512;
    private int[] pickingBuffer = new int[BUFSIZE];
    private boolean pick;
    private int hits;
    private int board[][] = new int[3][3];
    private int id = 0;

    /**
    * Default Constructor
    */
    public OpenGLDrawer()
    {
    targetContainerList = new LinkedList();
    setCamPos(0,0,10.0);
    }

    public GLDrawable getDrawable()
    {
    return this.drawable;
    }

    public void setPick(boolean b)
    {
    this.pick = b;
    }

    /**
    * With this method zooming is realised.
    * @param factor <0 -> zoom in, >0 -> zoom out
    /
    public void zoom(int factor)
    {
    int d = factor;
    this.clipSize += clipSize
    0.1*factor;
    //this.gl.glGetIntegerv(GL.GL_VIEWPORT,this.viewport);
    }

    /**
    * Adds a targetContainer to the OpenGLDrawer.
    * @param targetContainer
    */
    public void addTargetContainer(TargetContainer targetContainer)
    {
    this.targetContainerList.add(targetContainer);
    }

    public void setMaxRange(double range)
    {
    this.maxRange = range;
    }

    public void setClipSize(boolean dec)
    {
    if (dec == true)
    {
    this.clipSize += clipSize0.1;
    }
    else
    {
    this.clipSize -= clipSize
    0.1;
    }
    }

    public void setTransparencyFactor()
    {
    this.transparencyFactor += -0.05;
    }

    /**
    * With this method the vectors are defined along which the centerpoint has to be translated.
    * @param xVector vector in x-direction
    * @param yVector vector in y-direction
    */

    public void setTranslationVectors(int xVector, int yVector)
    {
    this.xVector = xVector;
    this.yVector = yVector;
    }

    /**
    * Clears the vectors which where defined by the last drag.
    */
    public void clearTranslationVectors()
    {
    this.xVector = 0;
    this.yVector = 0;
    }

    /**
    * With this method can be defined if the actual centerpoint should be loacated or not.
    * @param bool true if centerpoint should be located, false if not
    */
    public void setLocateCenterFlag(boolean bool)
    {
    this.locateCenterFlag = bool;
    }

    /**
    * With this method it can be defined where the center of the display has to be located.
    * @param x x-coordinate of the centerpoint
    * @param y y-coordinate of the centerpoint
    * @param z z-coordinate of the centerpoint
    */
    public synchronized void setSceneCenterPoint(double x, double y, double z)
    {
    this.sceneCenterPoint[0]= x;
    this.sceneCenterPoint[1]= y;
    this.sceneCenterPoint[2]= z;
    }

    public double[] getSceneCenterPoint()
    {
    return this.sceneCenterPoint;
    }

    /**
    * With this method the position of the camera can be defined.
    * @param x x-coordinate of the cameraposition
    * @param y y-coordinate of the cameraposition
    * @param z z-coordinate of the cameraposition
    */
    public synchronized void setCamPos(double x, double y, double z)
    {
    this.camPos[0] = x;
    this.camPos[1] = y;
    this.camPos[2] = z;
    }

  /**
   * Returns the actual position of the camera.
   * @return Array containing the x-, y- and z-coordinate if the cameraposition
   */
  public double[] getCamPos()
  {
        return this.camPos;
  }

  /**
   * Locates the actual centerpoint and stores it in centerX, centerY and centerZ.
   */
  public void locateCenterPoint()
  {
        this.glu = this.drawable.getGLU();
        glu.gluProject(this.worldX[0],this.worldY[0],this.worldZ[0],model_view,projection,viewport,this.centerX,this.centerY,this.centerZ);
  }

  public void setMousePosition(int x, int y)
  {
        this.mouseX = x;
        this.mouseY = y;
  }

  private void drawTargets()
  {
        if(!(this.targetContainerList.isEmpty()))      //container available
        {
              for(int j=0;j<this.targetContainerList.size();j++)      //display content of every targetcontainer
              {
                    this.targetContainer = (TargetContainer) this.targetContainerList.get(j);
                    for (int targetNr=0;targetNr<this.targetContainer.getContainerSize();targetNr++)      //display every target contained in the targetcontainer
                    {
                          this.target = (Target)this.targetContainer.getData(targetNr);
                          this.range = target.getRange()/maxRange;
                          this.azimuth = 360-target.getAzimut()/(65535/360);
                          this.color = target.getColor();
                          this.elevation = target.getElevationnumber();
                          target.setTimeToLive(target.getTimeToLive()-1);
                          this.ttl = target.getTimeToLive();
                          gl.glLoadIdentity();
                          gl.glTranslated(sceneCenterPoint[0],sceneCenterPoint[1],sceneCenterPoint[2]);
                          gl.glRotated(this.azimuth, 0, 0, 1.0);
                          gl.glTranslated(this.range, 0.0,elevation);
                          this.color[3] = this.color[3]-this.color[3]/ttl;

                          gl.glLoadName(this.id);
                          this.id++;
                          gl.glBegin(GL.GL_QUADS);
                          //gl.glColor3dv(color);

                          gl.glColor4d(0.0,0.0,1.0,color[3]);
                          gl.glVertex3d(-0.005*clipSize,+0.015*clipSize,-0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.015*clipSize,-0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.015*clipSize,-0.005*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.015*clipSize,-0.005*clipSize);

                          gl.glVertex3d(-0.005*clipSize,+0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.015*clipSize,+0.005*clipSize);

                          gl.glVertex3d(-0.005*clipSize,+0.015*clipSize,-0.005*clipSize);
                          gl.glVertex3d(-0.005*clipSize,+0.015*clipSize,0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.015*clipSize,-0.005*clipSize);

                          gl.glVertex3d(-0.005*clipSize,-0.015*clipSize,-0.005*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.015*clipSize,0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.015*clipSize,-0.005*clipSize);

                          gl.glVertex3d(-0.005*clipSize,+0.015*clipSize,-0.005*clipSize);
                          gl.glVertex3d(-0.005*clipSize,+0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.015*clipSize,-0.005*clipSize);

                          gl.glVertex3d(+0.005*clipSize,+0.015*clipSize,-0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.015*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.015*clipSize,-0.005*clipSize);

                          //**************************************

                          gl.glColor4d(0.0,1.0,0.0,color[3]);
                          gl.glVertex3d(-0.015*clipSize,+0.005*clipSize,-0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,+0.005*clipSize,-0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,-0.005*clipSize,-0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,-0.005*clipSize,-0.005*clipSize);

                          gl.glVertex3d(-0.015*clipSize,+0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,+0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,-0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,-0.005*clipSize,+0.005*clipSize);

                          gl.glVertex3d(-0.015*clipSize,+0.005*clipSize,-0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,+0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,-0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,-0.005*clipSize,-0.005*clipSize);

                          gl.glVertex3d(+0.015*clipSize,+0.005*clipSize,-0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,+0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,-0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,-0.005*clipSize,-0.005*clipSize);

                          gl.glVertex3d(-0.015*clipSize,+0.005*clipSize,-0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,+0.005*clipSize,0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,+0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,+0.005*clipSize,-0.005*clipSize);

                          gl.glVertex3d(-0.015*clipSize,-0.005*clipSize,-0.005*clipSize);
                          gl.glVertex3d(-0.015*clipSize,-0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,+0.005*clipSize,+0.005*clipSize);
                          gl.glVertex3d(+0.015*clipSize,+0.005*clipSize,-0.005*clipSize);

                          //**************************************

                          gl.glColor4d(1.0,0.0,0.0,color[3]);
                          gl.glVertex3d(-0.005*clipSize,+0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.005*clipSize,-0.015*clipSize);

                          gl.glVertex3d(-0.005*clipSize,+0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.005*clipSize,+0.015*clipSize);

                          gl.glVertex3d(-0.005*clipSize,+0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(-0.005*clipSize,+0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.005*clipSize,-0.015*clipSize);

                          gl.glVertex3d(+0.005*clipSize,+0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.005*clipSize,-0.015*clipSize);

                          gl.glVertex3d(-0.005*clipSize,+0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,+0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(-0.005*clipSize,+0.005*clipSize,+0.015*clipSize);

                          gl.glVertex3d(-0.005*clipSize,-0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.005*clipSize,-0.015*clipSize);
                          gl.glVertex3d(+0.005*clipSize,-0.005*clipSize,+0.015*clipSize);
                          gl.glVertex3d(-0.005*clipSize,-0.005*clipSize,+0.015*clipSize);
                          gl.glEnd();
                          gl.glFlush();

                          if (this.ttl < 500)
                          {
                                this.targetContainer.removeData(target);
                          }
                    }
              }
        }
  }

  private void processHits()
  {
  }

  public void select()
  {
        if (this.pick)
        {
              int selectBuf[] = new int[BUFSIZE];
              this.gl.glGetIntegerv(GL.GL_VIEWPORT,this.viewport);

              this.gl.glSelectBuffer(BUFSIZE,selectBuf);
              //Puts OpenGL In Selection Mode. Nothing Will Be Drawn.  Object ID's and Extents Are Stored In The Buffer.
              this.gl.glRenderMode(GL.GL_SELECT);

              this.gl.glInitNames();   // Initializes The Name Stack
              this.gl.glPushName(0);   // Push 0 (At Least One Entry) Onto The Stack

              this.gl.glMatrixMode(GL.GL_PROJECTION);    // Selects The Projection Matrix
              this.gl.glPushMatrix();         // Push The Projection Matrix
              this.gl.glLoadIdentity();      // Resets The Matrix

              //This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is.
              this.glu.gluPickMatrix( this.mouseX,  (viewport[3]-this.mouseY), 5.0, 5.0, viewport);

              //Apply The ortho Matrix
              this.gl.glOrtho(-clipSize,+clipSize,-clipSize,+clipSize,-clipSize*100,+clipSize*100);
              this.id = 0;
              drawTargets();

              this.gl.glPopMatrix();
              this.gl.glFlush();

              hits = gl.glRenderMode(GL.GL_RENDER);

              System.out.println("HITS = " + hits);
        }
        setPick(false);
  }
 private void drawSphere(double azimuth,double range,double elevation,double[] color,int ttl)
  {
        gl.glLoadIdentity();
        gl.glTranslated(sceneCenterPoint[0],sceneCenterPoint[1],sceneCenterPoint[2]);
        gl.glRotated(azimuth, 0, 0, 1.0);
        gl.glTranslated(range, 0.0,elevation);

        gl.glNewList(10,GL.GL_COMPILE);  //Beginn der Listendefinition

              glu.gluQuadricTexture(sphere,false);     //auf Texturnutzung nicht vorbereiten!

              glu.gluQuadricOrientation(sphere,GLU.GLU_OUTSIDE);  //Normalenausrichtung nach Aussen

              glu.gluQuadricDrawStyle(sphere,GLU.GLU_FILL);   //Darstellungsart, ausgefüllt darst.

              glu.gluQuadricNormals(sphere,GLU.GLU_FLAT);      //Normalen für jede FLäche berechnen
              gl.glPolygonMode(GL.GL_FRONT,GL.GL_FILL);//Vorderflächendarst.
              gl.glShadeModel(GL.GL_SMOOTH);          //Schattierungsmodus
              color[3] = color[3]-color[3]/ttl;
              gl.glColor4d(color[0],color[1],color[2],color[3]);
              glu.gluSphere(sphere, clipSize/40, 15, 15);

        gl.glEndList();  //Ende der Listendefinition

        gl.glCallList(10);
        gl.glFlush();
  }

  private void drawCOSystem()
  {
        //glu.gluUnProject()
        //rangelines
        for (double i=0;i<360;i+=10)
        {
              gl.glLoadIdentity();
              gl.glTranslated(sceneCenterPoint[0],sceneCenterPoint[1],sceneCenterPoint[2]);
              gl.glRotated(i,0.0,0.0,1.0);
              gl.glBegin(GL.GL_LINES);
              gl.glColor4d(0.0,0.0,1.0,transparencyFactor);
              gl.glVertex3d(0.0,0.0,0.0);
              gl.glVertex3d(1.0,0.0,0.0);
              gl.glEnd();
        }

        //cartesian co-system
        gl.glLoadIdentity();
        gl.glTranslated(sceneCenterPoint[0],sceneCenterPoint[1],sceneCenterPoint[2]);
        gl.glBegin(GL.GL_LINES);       //Def.-Beginn der Linien
        // X-Achse
        gl.glColor4d(1.0,1.0,0.0,transparencyFactor);  //Farbe Weiß
        gl.glVertex3d(0.0, 0.0, 0.0);   //Vom Ursprung
        gl.glVertex3d(1.2,0.0,0.0);   //zu X=+1.0
        // Y-Achse
        gl.glVertex3d(0.0, 0.0, 0.0);   //Vom Ursprung
        gl.glVertex3d(0.0, 1.2, 0.0);   //zu Y=+1.0
        // Z-Achse
        gl.glVertex3d(0.0, 0.0, 0.0);   //Vom Ursprung
        gl.glVertex3d(0.0, 0.0, 1.0);   //zu Z=+1.0
        gl.glEnd();                     //Ende Def. der Linie

        //label for the x-axis
        for(float i=0;i<=1.0;i+=0.2)
        {
              gl.glLoadIdentity();
              gl.glTranslated(sceneCenterPoint[0],sceneCenterPoint[1],sceneCenterPoint[2]);
              gl.glRasterPos3d(i,0.0,0.0);
              gl.glColor4d(1.0,0.0,1.0,1.0);
              glut.glutBitmapString(gl, GLUT.BITMAP_TIMES_ROMAN_10,String.valueOf((int)(i*maxRange)));
        }

        //rangecircles
        for (double j=0;j<=1;j+=0.2)
        {
              for(double i=0;i<360;i+=(0.5*clipSize))
              {
                    gl.glLoadIdentity();
                    gl.glTranslated(sceneCenterPoint[0],sceneCenterPoint[1],sceneCenterPoint[2]);
                    gl.glRotated(i,0.0,0.0,1.0);
                    gl.glBegin(GL.GL_POINTS);
                    gl.glColor4d(1.0,0.0,0.0,transparencyFactor);
                    gl.glVertex3d(j,0.0,0.0);
                    gl.glEnd();
              }
        }

        //degree lines
        for (int i=0;i<360;i++)
        {

              gl.glLoadIdentity();
              gl.glTranslated(sceneCenterPoint[0],sceneCenterPoint[1],sceneCenterPoint[2]);
              gl.glRotated(i,0.0,0.0,1.0);
              if(i%10==0)
              {
                    gl.glBegin(GL.GL_LINES);
                    gl.glColor4d(0.0,1.0,1.0,transparencyFactor);
                    gl.glVertex3d(1.0,0.0,0.0);
                    gl.glVertex3d(1.3,0.0,0.0);
                    gl.glEnd();

                    gl.glLoadIdentity();
                    gl.glTranslated(sceneCenterPoint[0],sceneCenterPoint[1],sceneCenterPoint[2]);
                    gl.glRotated(360-i,0.0,0.0,1.0);
                    gl.glRasterPos3d(1.3,0.0,0.0);
                    glut.glutBitmapString(gl, GLUT.BITMAP_TIMES_ROMAN_10,String.valueOf(i));
              }
              else
              {
                    gl.glBegin(GL.GL_LINES);
                    gl.glColor4d(0.0,1.0,1.0,transparencyFactor);
                    gl.glVertex3d(1.0,0.0,0.0);
                    gl.glVertex3d(1.1,0.0,0.0);
                    gl.glEnd();
              }
        }
  }

  private void drawZoomCross()
  {
        double angle = 90;
        for (int i=0;i<=4;i++)
        {
              gl.glLoadIdentity();
              gl.glTranslated(0,0,0);
              gl.glRotated(angle,0.0,0.0,1.0);

              gl.glBegin(GL.GL_LINES);
              gl.glColor4d(1.0,0.5,0.0,transparencyFactor);
              gl.glVertex3d(0.0,0.0,0.0);
              gl.glVertex3d(0.25*clipSize,0.0,0.0);
              gl.glEnd();

              angle +=90;
        }
  }

/++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/

  public void display(GLDrawable drawable)
  {
        gl.glGetDoublev ( GL.GL_MODELVIEW_MATRIX, model_view );
        gl.glGetDoublev (GL.GL_PROJECTION_MATRIX, projection);
        gl.glGetIntegerv (GL.GL_VIEWPORT, viewport);

        if (locateCenterFlag)
        {
              locateCenterPoint();
              this.xVector = 0;
              this.yVector = 0;
        }
        else
        {
              glu.gluUnProject(this.centerX[0]+this.xVector,this.centerY[0]+this.yVector,this.centerZ[0]+this.zVector,model_view,projection,viewport,worldX,worldY,worldZ);
              setSceneCenterPoint(worldY[0]*(-1),worldX[0]*(-1),0.0); //No idea why x and y have to be inverted
        }


        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrtho(-clipSize,+clipSize,-clipSize,+clipSize,-clipSize*100,+clipSize*100);
        glu.gluLookAt(camPos[0],camPos[1],camPos[2],0.0,0.0,0.0,0.0,1.0,0.0);      //Kamera irgendwo auf Z-Achse über (<clipsize) Ursprung
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();

        this.id = 0;
        drawTargets();
        this.gl.glFlush();
        drawCOSystem();
        this.gl.glFlush();
        drawZoomCross();
        this.gl.glFlush();

        if(this.pick)
        {
              select();
        }
        this.gl.glFlush();

// try
// {
// Thread.sleep(10);
// }
// catch (InterruptedException e)
// {
// e.printStackTrace();
// }
}

  public void displayChanged(GLDrawable gLDrawable, boolean param, boolean param2)
  {
  }

  public void init(GLDrawable drawable)
  {
        this.drawable = drawable;
        gl = this.drawable.getGL();
        glu = this.drawable.getGLU();  //OpenGL utility library enthält Werte für GLU_FILL usw.
        glut = new GLUT();
        sphere = glu.gluNewQuadric();     //GLU-Körper anfordern -> obj zeigt jetzt auf diesen Körper

        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();

        gl.glShadeModel(GL.GL_SMOOTH);              // Enable Smooth Shading
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background
        gl.glClearDepth(1.0f);                      // Depth Buffer Setup
        gl.glEnable(GL.GL_DEPTH_TEST);                                          // Enables Depth Testing
        gl.glDepthFunc(GL.GL_LEQUAL);                                                // The Type Of Depth Testing To Do
        gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);      // Really Nice Perspective Calculations
        gl.glEnable(GL.GL_BLEND);
        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

        FPSAnimator fpsAnimator = new FPSAnimator(this.drawable,10,null);
        fpsAnimator.start();
  }

public void reshape(GLDrawable drawable, int left, int right, int width, int height)
{
this.height = height;
this.width = width;

        this.hwRatio = (float) width / (float) height;

// //meins
// if (hwRatio <= 1.0) //höhe > breite
// {
// gl.glViewport(0, 0, (int)((width/hwRatio)), height);
// }
// else //höhe < breite
// {
// gl.glViewport(0, 0, width, (int)(height*hwRatio));
// }

        //Buch
        if (hwRatio <= 1.0)  //höhe > breite
        {
              gl.glViewport(0,(int)(height*(1.0-hwRatio)*2.0),width,(int) (height*hwRatio));
        }
        else  //höhe < breite
        {
              gl.glViewport((int)(width*(1.0-(1.0/hwRatio))/2.0), 0,(int) (width/hwRatio), height);
        }

//
// gl.glViewport(0, 0, width, height);

        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrtho(-clipSize,+clipSize,-clipSize,+clipSize,-clipSize*100,+clipSize*100);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
        gl.glEnable(GL.GL_BLEND);
  }

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

     private Vector xTrace = new Vector();
    private Vector yTrace = new Vector();
    private int xDirectionVector;
    private int yDirectionVector;
    private CameraMotionThread camThread;
      /* (non-Javadoc)
     * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
     */
    public void mouseDragged(MouseEvent e)
    {
          setLocateCenterFlag(false);      //make sure that the centerpoint isn't calculated during dragging

          xTrace.add(Integer.toString(e.getX()));
          yTrace.add(Integer.toString(e.getY()));
          xVector = Integer.parseInt((String) xTrace.lastElement())-Integer.parseInt((String) xTrace.firstElement());
          yVector = Integer.parseInt((String) yTrace.lastElement())-Integer.parseInt((String) yTrace.firstElement());

          this.xDirectionVector = this.xVector;
          this.yDirectionVector = this.yVector;
          if(!(e.isControlDown()))setTranslationVectors(xVector,yVector);
          if (e.isControlDown())
          {
                setLocateCenterFlag(true);
                this.camThread = new CameraMotionThread(e,this.xDirectionVector,this.yDirectionVector,this);
                this.camThread.start();
          }
    }

    /* (non-Javadoc)
     * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
     */
    public void mouseMoved(MouseEvent e)
    {
    }

    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
     */
    public void mouseClicked(MouseEvent e)
    {
    }

    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
     */
    public void mouseEntered(MouseEvent e)
    {
    }

    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
     */
    public void mouseExited(MouseEvent e)
    {
    }

    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
     */
    public void mousePressed(MouseEvent e)
    {
          setLocateCenterFlag(false);
          setMousePosition(e.getX(),e.getY());
          select();
          GLCanvas canvas = (GLCanvas)e.getSource();
          canvas.repaint();

          setPick(true);

    }

    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
     */
    public void mouseReleased(MouseEvent e)
    {
          setLocateCenterFlag(true);
          clearTraces();
          if(e.isControlDown())
          {
                this.camThread.interrupt();
          }
    }

    /**
     * Clears the traces of past drags
     */
    private void clearTraces()
    {
          this.xTrace.clear();
          this.yTrace.clear();
    }

}

Sorry, I know that this is much stuff… but I can’t imagine what I’m doing wrong!

I just have too less experience with OpenGL!!! :frowning:

Thank you very much for trying to help me!!!
I appreciate your efforts!!!

Greeting Samson

The next two days I don’t have access to the Internet…
so I can reply answers on sunday! Thx…