protected void resolvePickRect(DrawContext dc) { if (dc.pickedObjects.count() == 0) { return; // no eligible objects; avoid expensive calls to glReadPixels } // Read the unique fragment colors in the pick rectangle. Set<Color> pickColors = dc.readPixelColors(dc.pickViewport.x, dc.pickViewport.y, dc.pickViewport.width, dc.pickViewport.height); for (Color pickColor : pickColors) { // Convert the fragment color to a picked object ID. This returns zero if the color cannot indicate a picked // object ID. int topObjectId = PickedObject.uniqueColorToIdentifier(pickColor); if (topObjectId != 0) { PickedObject topObject = dc.pickedObjects.pickedObjectWithId(topObjectId); if (topObject != null) { topObject.markOnTop(); } } } // Remove all picked objects not marked as on top. dc.pickedObjects.keepTopObjects(); } }
protected void resolvePick(DrawContext dc) { if (dc.pickedObjects.count() == 0) { return; // no eligible objects; avoid expensive calls to glReadPixels } // Read the fragment color at the pick point. this.pickColor = dc.readPixelColor((int) Math.round(dc.pickPoint.x), (int) Math.round(dc.pickPoint.y), this.pickColor); // Convert the fragment color to a picked object ID. This returns zero if the color cannot indicate a picked // object ID, in which case no objects have been drawn at the pick point. int topObjectId = PickedObject.uniqueColorToIdentifier(this.pickColor); if (topObjectId != 0) { PickedObject terrainObject = dc.pickedObjects.terrainPickedObject(); PickedObject topObject = dc.pickedObjects.pickedObjectWithId(topObjectId); if (topObject != null) { topObject.markOnTop(); dc.pickedObjects.clearPickedObjects(); dc.pickedObjects.offerPickedObject(topObject); dc.pickedObjects.offerPickedObject(terrainObject); // handles null objects and duplicate objects } else { dc.pickedObjects.clearPickedObjects(); // no eligible objects drawn at the pick point } } else { dc.pickedObjects.clearPickedObjects(); // no objects drawn at the pick point } }