World Wind Forums

Go Back   World Wind Forums > WorldWind JAVA forums > Development Help

Development Help Help for building applications or diagnosing problems with WWJ

Reply
 
Thread Tools Display Modes
Old 08-24-2012, 06:41 PM   #1
heidtmare
Senior Member
 
heidtmare's Avatar
 
Join Date: Feb 2008
Location: Melbourne, FL, USA
Posts: 678
heidtmare is on a distinguished road
Arrow DropTargetDropEvent: Point => Position

I've implemented a DropTargetListener with the following:
PHP Code:
@Override
    
public void drop(DropTargetDropEvent dtde) {
        if (
dtde.isDataFlavorSupported(RenderableProvider.DATA_FLAVOR)) {
            try {
                
Object transData dtde.getTransferable().getTransferData(RenderableProvider.DATA_FLAVOR);
                if (
transData instanceof RenderableProvider) {
                    
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

                    
RenderableProvider rp = (RenderableProviderdtde.getTransferable().getTransferData(RenderableProvider.DATA_FLAVOR);

                    
//get the layer
                    
String ln rp.getLayerName();
                    
RenderableLayer layer = (RenderableLayerwwm.getLayers().getLayerByName(ln);
                    if (
layer == null) {
                        
layer = new RenderableLayer();
                        
layer.setName(ln);
                        
wwm.getLayers().add(layer);
                    }

                    
//calculate position
                    
Globe globe wwm.getWorldWindow().getModel().getGlobe();
                    
Point p dtde.getLocation();
                    
Position pos globe.computePositionFromPoint(new Vec4(p.getX(), p.getY()));
                    
LOGGER.log(Level.INFO"Position: {0}"pos);

                    
//add the renderable
                    
Renderable r rp.getRenderable(pos);
                    if (
!= null) {
                        
layer.addRenderable(r);
                    }
                }
            } catch (
UnsupportedFlavorException ufe) {
                
Exceptions.printStackTrace(ufe);
                
dtde.rejectDrop();
                
dtde.dropComplete(true);
            } catch (
IOException ioe) {
                
Exceptions.printStackTrace(ioe);
                
dtde.rejectDrop();
                
dtde.dropComplete(false);
            }
        } else {
            
LOGGER.warning("Unsupported Data Flavor");
            
dtde.rejectDrop();
            
dtde.dropComplete(false);
        }
    }

It works if my goal is to have all my Renderables show up at the north pole... which it is not.


PHP Code:
Point p dtde.getLocation();
Position pos globe.computePositionFromPoint(new Vec4(p.getX(), p.getY()));
LOGGER.log(Level.INFO"Position: {0}"pos); 
This always gives me a position close to the pole.
So I'm assuming there is an absolute vs relative issue here.
Is there a magical way to convert between java.awt.Point and gov.nasa.worldwind.geom.Position?
heidtmare is offline   Reply With Quote
Old 08-24-2012, 08:32 PM   #2
dcollins
WWJ Dev. Team
 
Join Date: May 2007
Posts: 449
dcollins is on a distinguished road
Default

heidtmare,

This looks like a simple oversight: the method Globe.computePositionFromPoint transforms a model-coordinate Cartesian point to spherical coordinates. Since you are specifying screen-coordinate values which happen to be small relative to model-coordiante values, the code above essentially transforms points near the center of the earth to their corresponding spherical value.

Please try replacing usage of Globe.computePointFromPosition with View.computePositionFromScreenPoint, and let us know if that resolves the issue. Note that View.computePositionFromScreenPoint returns null if the point is off the globe.

Thanks,
Dave
dcollins is offline   Reply With Quote
Old 08-25-2012, 05:11 AM   #3
workingDog
Member
 
Join Date: Mar 2008
Posts: 84
workingDog is on a distinguished road
Default

I did the same DropTarget thing a while back using this:

Line lineRay = wwm.getWorldWindow().getView().computeRa yFromScreenPoint(p.x, p.y);
Position dropPosition = wwm.getWorldWindow().getView().getGlobe( ).getIntersectionPosition(lineRay);
workingDog is offline   Reply With Quote
Old 08-25-2012, 07:31 PM   #4
dcollins
WWJ Dev. Team
 
Join Date: May 2007
Posts: 449
dcollins is on a distinguished road
Default

workingDog,

Please note that View.computePositionFromScreenPoint does exactly what you outline in your post. It would be worth using this method instead of your own, unless you have other logic that what you've shown above.

Thanks,
Dave
dcollins is offline   Reply With Quote
Old 08-25-2012, 09:05 PM   #5
heidtmare
Senior Member
 
heidtmare's Avatar
 
Join Date: Feb 2008
Location: Melbourne, FL, USA
Posts: 678
heidtmare is on a distinguished road
Default

yep, i knew i was doing something silly... thanks guys.
__________________
Member
 
Join Date: Mar 2008
Posts: 84
workingDog is on a distinguished road
Default

yes, much better to use View.computePositionFromScreenPoint

thanks
workingDog is offline   Reply With Quote
Reply

Tags
resolved


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get screen point from position tmuic Development Help 4 02-14-2012 05:14 PM
View eye position help needed SpecterTerrasbane Development Help 0 08-19-2011 05:17 PM
Getting globe position on a mouse click in a 3D projection borsightjohn Development Help 12 12-15-2009 01:41 AM
[Solved] Polyline Position does not match Point Position Morris Development Help 4 07-03-2009 01:36 AM
Get screen point for click position in select event naql Development Help 3 08-04-2008 05:58 PM


All times are GMT +1. The time now is 04:12 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.