2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
;
11 * @version $Id: BasicSceneController.java 1792 2007-05-08 21:28:37Z tgaskins $
13 public class BasicSceneController
extends WWObjectImpl
implements SceneController
17 private FrameController frameController
;
18 private double verticalExaggeration
= 1d
;
19 private DrawContext dc
= new DrawContextImpl();
20 private gov
.nasa
.worldwind
.PickedObjectList lastPickedObjects
;
22 // These are for tracking performance
23 private long frame
= 0;
24 private long timebase
= System
.currentTimeMillis();
25 private double framesPerSecond
;
26 private double frameTime
;
29 public BasicSceneController()
31 // Establish a default frame controller and view.
32 this.setFrameController((FrameController
) WorldWind
.createConfigurationComponent(
33 AVKey
.FRAME_CONTROLLER_CLASS_NAME
));
35 this.setVerticalExaggeration(Configuration
.getDoubleValue(AVKey
.VERTICAL_EXAGGERATION
, 1d
));
38 public FrameController
getFrameController()
40 return this.frameController
;
43 public Model
getModel()
54 * @param frameController the frame controller
55 * @throws IllegalArgumentException if <code>frameController</code> is null
57 public void setFrameController(FrameController frameController
)
59 if (frameController
== null)
61 String msg
= WorldWind
.retrieveErrMsg("nullValue.FrameControllerIsNull");
62 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
63 throw new IllegalArgumentException(msg
);
65 FrameController oldFrameControler
= this.frameController
;
66 this.frameController
= frameController
;
67 this.firePropertyChange(AVKey
.FRAME_CONTROLLER
, oldFrameControler
, frameController
);
70 public void setModel(Model model
)
72 if (this.model
!= null)
73 this.model
.removePropertyChangeListener(this);
75 model
.addPropertyChangeListener(this);
77 Model oldModel
= this.model
;
79 this.firePropertyChange(AVKey
.MODEL
, oldModel
, model
);
82 public void setView(View view
)
84 if (this.view
!= null)
85 this.view
.removePropertyChangeListener(this);
87 view
.addPropertyChangeListener(this);
89 View oldView
= this.view
;
92 this.firePropertyChange(AVKey
.VIEW
, oldView
, view
);
95 public void setVerticalExaggeration(double verticalExaggeration
)
97 Double oldVE
= this.verticalExaggeration
;
98 this.verticalExaggeration
= verticalExaggeration
;
99 this.firePropertyChange(AVKey
.VERTICAL_EXAGGERATION
, oldVE
, verticalExaggeration
);
102 public double getVerticalExaggeration()
104 return this.verticalExaggeration
;
107 public void repaint()
109 this.frameTime
= System
.currentTimeMillis();
111 this.dc
.initialize(javax
.media
.opengl
.GLContext
.getCurrent());
112 this.dc
.setModel(this.model
);
113 this.dc
.setView(this.view
);
114 this.dc
.setVerticalExaggeration(this.verticalExaggeration
);
116 if (this.dc
.getGLContext() == null)
118 String message
= WorldWind
.retrieveErrMsg("BasicSceneController.GLContextNullStartRedisplay");
119 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
120 throw new IllegalStateException(message
);
123 FrameController fc
= this.getFrameController();
126 String message
= WorldWind
.retrieveErrMsg("BasicSceneController.NoFrameControllerStartRepaint");
127 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
128 throw new IllegalStateException(message
);
133 fc
.initializeFrame(this.dc
);
134 fc
.drawFrame(this.dc
);
138 String message
= WorldWind
.retrieveErrMsg("BasicSceneController.ExceptionDuringRendering");
139 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
, e
);
143 fc
.finalizeFrame(this.dc
);
146 long time
= System
.currentTimeMillis();
147 this.frameTime
= System
.currentTimeMillis() - this.frameTime
;
148 if (time
- this.timebase
> 5000)
150 this.framesPerSecond
= frame
* 1000d
/ (time
- timebase
);
151 this.timebase
= time
;
153 // System.out.printf("average frame rate is %f\n", this.framesPerSecond);
158 public PickedObjectList
pick(java
.awt
.Point pickPoint
)
160 if (pickPoint
== null)
162 String msg
= WorldWind
.retrieveErrMsg("nullValue.PickPoint");
163 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
164 throw new IllegalArgumentException(msg
);
167 if (this.dc
.getSurfaceGeometry() == null || this.dc
.getVisibleSector() == null)
169 this.lastPickedObjects
= null;
173 // PickingMode should be enabled before the initialize() method
174 this.dc
.enablePickingMode();
175 this.dc
.initialize(javax
.media
.opengl
.GLContext
.getCurrent());
176 this.dc
.setModel(this.model
);
177 this.dc
.setView(view
);
178 this.dc
.setVerticalExaggeration(this.verticalExaggeration
);
180 if (this.dc
.getGLContext() == null)
182 String message
= WorldWind
.retrieveErrMsg("BasicSceneController.GLContextNullStartPick");
183 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
184 throw new IllegalStateException(message
);
187 FrameController fc
= this.getFrameController();
190 String message
= WorldWind
.retrieveErrMsg("BasicSceneController.NoFrameControllerStartPick");
191 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
192 throw new IllegalStateException(message
);
197 fc
.initializePicking(this.dc
);
198 fc
.pick(this.dc
, pickPoint
);
202 String message
= WorldWind
.retrieveErrMsg("BasicSceneController.ExceptionDuringPick");
203 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
, e
);
207 fc
.finalizePicking(this.dc
);
208 this.dc
.disablePickingMode();
211 return this.lastPickedObjects
= new PickedObjectList(this.dc
.getPickedObjects());
214 public PickedObjectList
getPickedObjectList()
216 return this.lastPickedObjects
;
219 public double getFramesPerSecond()
221 return framesPerSecond
;
224 public double getFrameTime()