Ejemplo n.º 1
0
        public void endPicking(DrawContext dc)
        {
            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            gl.glPopAttrib();

            // Some nvidia Quadro cards have a bug in which the current color is not restored. Restore it to the
            // default here.
            gl.glColor3ub((byte)255, (byte)255, (byte)255);
        }
Ejemplo n.º 2
0
        /**
         * Detects the locations of the sector geometries in this list that intersect a specified screen point.
         * <p/>
         * Note: Prior to calling this method, {@link #beginRendering(gov.nasa.worldwind.render.DrawContext)} must be
         * called.
         *
         * @param dc        the current draw context.
         * @param pickPoint the screen point to test.
         */
        public void pick(DrawContext dc, java.awt.Point pickPoint)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new IllegalStateException(message);
            }

            if (pickPoint == null)
            {
                return;
            }

            this.pickSupport.clearPickList();
            this.pickSupport.beginPicking(dc);

            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            gl.glShadeModel(GL2.GL_FLAT);

            try
            {
                // render each sector in unique color
                this.beginRendering(dc);
                foreach (SectorGeometry sector in this)
                {
                    Color color = dc.getUniquePickColor();
                    gl.glColor3ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue());
                    sector.render(dc);
                    // lat/lon/elevation not used in this case
                    this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true);
                }

                PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint);
                if (pickedSector == null || pickedSector.getObject() == null)
                {
                    return; // no sector picked
                }
                this.beginSectorGeometryPicking(dc);
                SectorGeometry sector = (SectorGeometry)pickedSector.getObject();
                sector.pick(dc, pickPoint);
            }
            finally
            {
                this.endSectorGeometryPicking(dc);
                this.endRendering(dc);
                gl.glShadeModel(GL2.GL_SMOOTH); // restore to default explicitly to avoid more expensive pushAttrib

                this.pickSupport.endPicking(dc);
                this.pickSupport.clearPickList();
            }
        }
        /**
         * Causes the SurfaceObject to draw itself in a unique pick color, and add itself as a pickable object to the
         * specified pickSupport.
         *
         * @param dc          the current DrawContext.
         * @param pickSupport the PickSupport to add the SurfaceObject to.
         */
        protected void pickOrderedRenderable(DrawContext dc, PickSupport pickSupport)
        {
            // Register a unique pick color with the PickSupport. We define the pickable object to be the caller specified
            // delegate owner, or this object if the delegate owner is null. We define the picked position to be the
            // terrain's picked position to maintain backwards compatibility with previous implementations of SurfaceObject.
            Color pickColor = dc.getUniquePickColor();

            pickSupport.addPickableObject(this.createPickedObject(dc, pickColor));

            // Draw an individual representation of this object in a unique pick color. This representation is created
            // during the preRender pass in makeOrderedPreRenderable().
            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            gl.glColor3ub((byte)pickColor.getRed(), (byte)pickColor.getGreen(), (byte)pickColor.getBlue());
            this.drawPickRepresentation(dc);
        }
Ejemplo n.º 4
0
        /**
         * Detects the locations of the sector geometries in this list that intersect any of the points in a specified list
         * of screen points.
         * <p/>
         * Note: Prior to calling this method, {@link #beginRendering(gov.nasa.worldwind.render.DrawContext)} must be
         * called.
         *
         * @param dc         the current draw context.
         * @param pickPoints the points to test.
         *
         * @return an array of picked objects that intersect one or more of the specified screen points.
         */
        public List <PickedObject> pick(DrawContext dc, List <Point> pickPoints)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new IllegalStateException(message);
            }

            if (pickPoints == null || pickPoints.Count < 1)
            {
                return(null);
            }

            this.pickSupport.clearPickList();
            this.pickSupport.beginPicking(dc);

            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            gl.glShadeModel(GL2.GL_FLAT);

            try
            {
                // render each sector in a unique color
                this.beginRendering(dc);
                foreach (SectorGeometry sector in this)
                {
                    Color color = dc.getUniquePickColor();
                    gl.glColor3ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue());
                    sector.render(dc);
                    // lat/lon/elevation not used in this case
                    this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true);
                }

                // Determine the sectors underneath the pick points. Assemble a pick-points per sector map.
                // Several pick points might intersect the same sector.
                this.pickSectors.Clear();
                foreach (Point pickPoint in pickPoints)
                {
                    PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint);
                    if (pickedSector == null || pickedSector.getObject() == null)
                    {
                        continue;
                    }

                    SectorGeometry sector = (SectorGeometry)pickedSector.getObject();
                    List <Point>   sectorPickPoints;
                    if (!this.pickSectors.ContainsKey(sector))
                    {
                        sectorPickPoints = new List <Point>();
                        this.pickSectors.Add(sector, sectorPickPoints);
                    }
                    else
                    {
                        this.pickSectors.TryGetValue(sector, out sectorPickPoints);
                    }
                    sectorPickPoints.Add(pickPoint);
                }

                if (this.pickSectors.Count < 1)
                {
                    return(null);
                }

                // Now have each sector determine the pick position for each intersecting pick point.
                this.beginSectorGeometryPicking(dc);
                List <PickedObject> pickedObjects = new List <PickedObject>();
                foreach (KeyValuePair <SectorGeometry, List <Point> > sector in this.pickSectors)
                {
                    List <Point>   sectorPickPoints = sector.Value;
                    PickedObject[] pos = sector.Key.pick(dc, sectorPickPoints);
                    if (pos == null)
                    {
                        continue;
                    }

                    foreach (PickedObject po in pos)
                    {
                        if (po != null)
                        {
                            pickedObjects.Add(po);
                        }
                    }
                }

                return(pickedObjects);
            }
            finally
            {
                this.endSectorGeometryPicking(dc);
                this.endRendering(dc);
                gl.glShadeModel(GL2.GL_SMOOTH); // restore to default explicitly to avoid more expensive pushAttrib

                this.pickSupport.endPicking(dc);
                this.pickSupport.clearPickList();
            }
        }