if (center != null) {
mousePosition[0] += center[0];
mousePosition[1] += center[1];
}
int capacity = 1 * 4 * objectCount; //Each object take in maximium : 4 * name stack depth
IntBuffer hitsBuffer = BufferUtil.newIntBuffer(capacity);
gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer);
gl.glRenderMode(GL.GL_SELECT);
gl.glInitNames();
gl.glPushName(0);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
glu.gluPickMatrix(mousePosition[0], mousePosition[1], pickRectangle[0], pickRectangle[1], graphDrawable.getViewport());
gl.glMultMatrixd(graphDrawable.getProjectionMatrix());
gl.glMatrixMode(GL.GL_MODELVIEW);
int hitName = 1;
ModelImpl[] array = new ModelImpl[objectCount];
for (Iterator<ModelImpl> itr = octree.getSelectedObjectIterator(modelClass.getClassId()); itr.hasNext();) {
ModelImpl obj = itr.next();
obj.setAutoSelect(false);
array[hitName - 1] = obj;
gl.glLoadName(hitName);
obj.display(gl, glu, vizModel);
hitName++;
}
//Restoring the original projection matrix
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glFlush();
//Returning to normal rendering mode
int nbRecords = gl.glRenderMode(GL.GL_RENDER);
//Get the hits and put the node under selection in the selectionArray
for (int j = 0; j < nbRecords; j++) {
int hit = hitsBuffer.get(j * 4 + 3) - 1; //-1 Because of the glPushName(0)
ModelImpl obj = array[hit];
obj.setAutoSelect(true);
}
}
}