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 04-16-2009, 02:29 PM   #1
zaknixon
Member
 
Join Date: Mar 2008
Posts: 91
zaknixon is on a distinguished road
Default [Solved] Swapping Globes messes up OrbitBehavior

I have an small application that I want to use to swap between flat and round globes. I start off with the default round earth, and I can move the globe with the mouse as usual. When I click a key, it swaps to the flat globe, but my mouse actions are gone. I am using bits and pieces from the FlatWorld example, so I have been through that example exhaustively to figure this out.

Are there any ideas on why the orbit behavior being stopped/removed when swapping flat/round globes ?

BTW: I am utilizing the same enableFlatGlobe(boolean) in the FlatWorldPanel.java file, so the concept of swapping is already solved.

Thank you for any help.

Zak

Last edited by patmurris; 04-23-2009 at 09:55 PM. Reason: Solved
zaknixon is offline   Reply With Quote
Old 04-16-2009, 03:27 PM   #2
zaknixon
Member
 
Join Date: Mar 2008
Posts: 91
zaknixon is on a distinguished road
Default

I comment out the setView(..) lines in enableFlatGlobe(bool) method, and the globes still move, albeit not correctly since I am not swapping the orbit behavior based on the globe type. So, from what I can tell, it is an issue with setView(..) and I don't know how I can figure it out...

Any ideas on what I can try next ?

Thanks.

Here is the code I am trying:

(If you comment out the setView methods, you will see the MouseMovements will still work)

Code:
public class Test {

	private static boolean isRound = true;
	private static WorldWindowGLCanvas canvas;
    private static Globe roundGlobe;
    private static FlatGlobe flatGlobe;
	
	public static void main(String[] args) throws GLException, IOException{
		
		try{
		
    	Model displayModel = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);
    	canvas = new WorldWindowGLCanvas();
    	canvas.setModel(displayModel);
    	
    	Globe g = displayModel.getGlobe();
		
		if (g instanceof FlatGlobe)
        {
            flatGlobe = (FlatGlobe)g;
            roundGlobe = new Earth();
        }
        else if(g instanceof Earth)
        {
            flatGlobe = new EarthFlat();
            roundGlobe = canvas.getModel().getGlobe();
        }

    	JFrame frame = new JFrame();
		frame.getContentPane().add(canvas);
		frame.setVisible(true);
		
		canvas.addKeyListener(new KeyListener(){

			public void keyPressed(KeyEvent arg0) {

			}

			public void keyReleased(KeyEvent arg0) {

			}

			public void keyTyped(KeyEvent arg0) {
				isRound = !isRound;
				enableFlatGlobe(isRound);	
			}
			
		});
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	private static String getProjection()
    {
        return FlatGlobe.PROJECTION_LAT_LON;
    }
    
    public static boolean isFlatGlobe()
    {
        return canvas.getModel().getGlobe() instanceof FlatGlobe;
    }
    
	public static void enableFlatGlobe(boolean flat)
    {
        if(isFlatGlobe() == flat)
            return;

        if(!flat)
        {
            // Switch to round globe
            canvas.getModel().setGlobe(roundGlobe) ;
            // Switch to orbit view and update with current position
            FlatOrbitView flatOrbitView = (FlatOrbitView)canvas.getView();
            BasicOrbitView orbitView = new BasicOrbitView();
            orbitView.setCenterPosition(flatOrbitView.getCenterPosition());
            orbitView.setZoom(flatOrbitView.getZoom( ));
            orbitView.setHeading(flatOrbitView.getHeading());
            orbitView.setPitch(flatOrbitView.getPitch());
            canvas.setView(orbitView);
            // Change sky layer
            LayerList layers = canvas.getModel().getLayers();
            for(int i = 0; i < layers.size(); i++)
            {
                if(layers.get(i) instanceof SkyColorLayer)
                    layers.set(i, new SkyGradientLayer());
            }
        }
        else
        {
            // Switch to flat globe
        	canvas.getModel().setGlobe(flatGlobe);
            flatGlobe.setProjection(getProjection());
            // Switch to flat view and update with current position
            BasicOrbitView orbitView = (BasicOrbitView)canvas.getView();
            FlatOrbitView flatOrbitView = new FlatOrbitView();
            flatOrbitView.setCenterPosition(orbitView.getCenterPosition());
            flatOrbitView.setZoom(orbitView.getZoom( ));
            flatOrbitView.setHeading(orbitView.getHeading());
            flatOrbitView.setPitch(orbitView.getPitch());
            canvas.setView(flatOrbitView);
            
            // Change sky layer
            LayerList layers = canvas.getModel().getLayers();
            for(int i = 0; i < layers.size(); i++)
            {
                if(layers.get(i) instanceof SkyGradientLayer)
                    layers.set(i, new SkyColorLayer());
            }
        }
        
        canvas.redraw();
    }
	
	public static JFrame createContainer(final GlobeCanvas canvas){
		JFrame frame = new JFrame();

		frame.getContentPane().add(canvas);
		frame.setVisible(true);
		
		canvas.addKeyListener(new KeyListener(){

			public void keyPressed(KeyEvent arg0) {

			}

			public void keyReleased(KeyEvent arg0) {

			}

			public void keyTyped(KeyEvent arg0) {

				isRound = !isRound;	
				canvas.enableFlatGlobe(isRound);
				
			}
			
		});
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		return frame;
	}


}
zaknixon is offline   Reply With Quote
Old 04-16-2009, 04:14 PM   #3
patmurris
WWJ Consultant
 
patmurris's Avatar
 
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
patmurris is an unknown quantity at this point
Default

You example code works as expected for me, i see no issues right away...
__________________
My World Wind Java Blog & WW.net Plugins page
patmurris is offline   Reply With Quote
Old 04-16-2009, 05:53 PM   #4
zaknixon
Member
 
Join Date: Mar 2008
Posts: 91
zaknixon is on a distinguished road
Default

I am running it on a Macbook Pro, so I wonder if that is the problem....I will try it out on a PC and post the results.
zaknixon is offline   Reply With Quote
Old 04-16-2009, 05:57 PM   #5
zaknixon
Member
 
Join Date: Mar 2008
Posts: 91
zaknixon is on a distinguished road
Default

Strange thing is that I can run the FlatWorld example on my Macbook Pro and it works beautifully, but executing that code doesn't work. Personally, I don't see any major differences between the two.
zaknixon is offline   Reply With Quote
Old 04-23-2009, 04:03 PM   #6
zaknixon
Member
 
Join Date: Mar 2008
Posts: 91
zaknixon is on a distinguished road
Default [Fixed]

This was fixed by using the latest version of WW 0.6.
zaknixon is offline   Reply With Quote
Old 04-23-2009, 09:54 PM   #7
patmurris
WWJ Consultant
 
patmurris's Avatar
 
Join Date: Jun 2005
Location: Saint-Paul de Vence, Alpes Maritimes, France
Posts: 3,412
patmurris is an unknown quantity at this point
Default

I thought you where already using 0.6... Yes switching from flat to round was a problem before.
__________________
My World Wind Java Blog & WW.net Plugins page
patmurris is offline   Reply With Quote
Old 04-23-2009, 09:56 PM   #8
zaknixon
Member
 
Join Date: Mar 2008
Posts: 91
zaknixon is on a distinguished road
Default

Well, I thought I was too, but I dropped a fresh version of 0.6 in my build path and it worked instantly.
zaknixon is offline   Reply With Quote
Reply


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
Virtual Globes Special Issue - Computers & Geosciences TomServo Announcements & News 3 02-07-2009 06:31 AM


All times are GMT +1. The time now is 02:07 PM.


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