views:

106

answers:

3

I'm working with a mapping application (worldwind) and trying to determine the minimum and maximum latitudes and longitudes that are currently displayed. I have access to the frustum, but I'm not sure how to account for the fact that the globe can have its heading and/or pitch changed. Any help on this problem would be appreciated.

thanks,

Jeff

+1  A: 

Actually the Frustrum isn't the most useful thing in this context. What you need to do is reverse the ModelView-Project transform.

If you can retrieve your projection (frustrum) and model-view matrices, then you can invert them. If you project a ray from your camera position along projection space, then you can use those inversions to find that ray in world space. From there, you can intersect that ray with your world to find the exact point where that ray hits the globe.

Do this for the four corners of the screen and then calculate your 2D bounding box based upon those intersection coordinates.

Frank Krueger
Thanks, Frank. I'll give this a try and report back with the results.
Jeff Storey
I've started looking into this - but what if the globe is zoomed out such that it doesn't take up the entire screen? How can I calculate the corner points then?
Jeff Storey
Send a ray through the center position also. If your globe is zoomed out so much, then isn't it logical that the bounding box should consume the entire hemisphere? Your ray intersection test will tell you if it hit the globe or not.
Frank Krueger
excellent point.
Jeff Storey
Frank, where it gets particularly ugly is when the globe is rotated clockwise/counterclockwise. Then there could be an issue where the pole is out of the viewing area but the corners of the screens do not intersect the earth. I still need to figure out how to handle that case.
Jeff Storey
What I ended up doing was the following. I test the 4 corner points of the screen and if any are not intersecting with the globe, i use the visible sector bounds. This may be a little off when some of the corner points actually intersect with the globe and some don't but I can live with that inaccuracy in those cases. Otherwise, I just took the corner points and computed their lat lon from the screen points. Seems to work. Thank you.
Jeff Storey
A: 

What exactly are you trying to calculate ? Corner points of your window or that of your globe. Remember a circle does not have corners (nor does a sphere). Have you seen the minimap tool in worldwind (WorldMapLayer) . It shows the currently visible extent as an overlay in the minimap, this can give you an idea to work out what exactly is being displayed.

Good to see worldwind questions flowing everywhere. We mustn't be doing a good enough job at the forums.

whatnick
The worldwind forums have been great (I've mostly talked with Pat Murris and he has been very helpful). I've looked at the minimap layer and instead of showing a + at the current location, I'd like to show a rectangle with the currently visible area. I know it will have some distortion unless I'm zoomed in very closely (which I plan to be, almost at a 2D map) and there will be issues with heading and pitch so I'm trying to figure out how to best handle those.
Jeff Storey
It does show a curve around the corss does it not ? See the shape of the curve change as you tilt. This is what you are trying to achieve.
whatnick
Nick, can we move this to a WW Forum? Or do you have an email I can contact you at? I'm not sure further discussion of this topic really fits into the stack overflow forum.
Jeff Storey
WW forum it is .. time to close this.
whatnick
Thanks. Also please see my accepted answer and a comment I just posted. This may not be an ideal solution but it seems to work for my purposes but if needed we can continue this discussion in the WW forums.
Jeff Storey
A: 

The corner cases (1) of my previous proposal are making the algorithm difficult for you (I've never had to zoom out from the globe and still don't understand why you still don't just use the hemisphere in that case), so here is another method that can work.

Take your projection frustrum as a 3D object and intersect it with the globe (as a 3D object). There are a variety CSG algorithms that can give you union, intersection, and difference. Use intersection. This will result in a 3D mesh of the pieces of the globe that intersect with the frustrum. The extents of that mesh are the extents of the bounding box. (Project along the major axis of the frustrum.)

This is horribly less efficient than my previous proposal. :-)

(1) Pun completely intended.

Frank Krueger
Frank. thanks again here. I posted a comment to your other answer. The issue of the hemisphere is only in some weird cases when both the pitch and heading of the globe have been moved such that part of the globe is clipped. But what I realized is that in that case I can't get an accurate rectangle anyway since only part of the rectangle would be over the globe anyway and the other part would be over empty space (this may not make sense entirely, it is much easier to illustrate with a picture).
Jeff Storey