PDA

View Full Version : Controlling the camera to look at a specific item


fabrizio.giudici
09-11-2007, 06:28 AM
Hi guys.

I need to control the camera to render an Earth view centered on a specific pair of coordinates (in a first time it's ok for me to do this placing the camera exactly over that point, once I am able to do this I should be able to extend the code for dealing with different relative positions).

Also I need to do the opposite, that is to retrieve the coordinates of the point which is currently rendered at the center of the screen.

Can you please give me hints?

Thanks.

patmurris
09-11-2007, 07:12 AM
Here is how to 'iterate' the view position (from WWJApplet - click on world map):
The two Angle.ZERO are the target heading and pitch.

Position targetPos = event.getTopPickedObject().getPosition() ;

OrbitView view = (OrbitView)WWJApplet.this.wwd.getView();
Globe globe = WWJApplet.this.wwd.getModel().getGlobe() ;
// Use a PanToIterator
view.iterateOver(FlyToOrbitViewStateIter ator.createPanToIterator(
view, globe, new LatLon(targetPos.getLatitude(), targetPos.getLongitude()),
Angle.ZERO, Angle.ZERO, targetPos.getElevation()));

Chiss
09-12-2007, 02:44 AM
...and I can probably help for the coordinates in the middle of the screen :)

Get a hold of the DrawContext instance (to get the View instance), then getViewPort(). This will get you a Rectangle. rec.height/2 and rec.width/2 will give you the x/y coordinates of the middle, and then you go back to the View instance and use its computePositionFromScreenPoint(x,y). This works like a charm.

Good luck with BlueMarine, it is one heck of an app!

Hope this help,

Chiss!

patmurris
09-12-2007, 05:20 AM
Looking at AWT1Up and WWJApplet, i see the interface has evolved again. You may want to try this - not sure which version you have :

view.applyStateIterator(FlyToOrbitViewSt ateIterator.createPanToIterator(
view, globe, new LatLon(targetPos.getLatitude(), targetPos.getLongitude()),
Angle.ZERO, Angle.ZERO, targetPos.getElevation()));

linnuxxy
11-29-2007, 05:29 PM
It is working for me, although I have one problem:

When the WorldWindowGLCanvas loose the focus in-middle of the camera movement, the movement stop and never continue when the component get the focus again!

How can I make the camera continue its movement even when the WorldWindowGLCanvas loose the focus?