PDA

View Full Version : ? Curved surface - overlay a surface on a sphere ?

Z-Knight
01-12-2009, 09:46 AM
Given a 3D earth and a vehicle flying overhead I want to draw the ground coverage zone that the vehicle is currently over. I want to represent this by a filled, colored circle.

I sort of want this kind of view:

http://www.gano.name/shawn/JSatTrak/images/JSatTrack_3d_shot.jpg

The above image is not exactly the solution...the colored regions are really 3D cones and not projected on the surface. In my case, I have the latitude/longitude coordinates of the circle on the surface so I can draw the circle representing the boundary but I want to also fill in the circle with some transparent color so it sorts of looks like the image above...does anyone have suggestions?

Effectively I sort of want to do what glutSolidSphere() does but only for a small section of surface, instead of an entire sphere. The worst case solution would be to figure out a triangulator for a curved surface section and draw the triangles each myself but if anyone has a better solution or suggestion, I'll take it. Thanks.

dletozeun
01-12-2009, 10:42 AM
I am not sure to understand your problem here... is it that you don't know how to generate yellow or red surfaces and fill them in with a translucent color?

Z-Knight
01-12-2009, 10:55 AM
no...I know how to do it, but I need the surfaces to be curved.

Basically imagine taking an ball and you draw a circle on the ball and fill it in with some color. So you've basically put a thin film of ink on the surface of the ball...I want to do the same with some polygon (right now just a colored circle for which I have the coordinates of the boundary of the circle. The ball is curved and so if I just drew a normal filled in circle, the filled in part would be inside the ball...ie you wouldn't see it, so you have to curve it up to be slightly above the surface of the ball.

Does that make sense?

MaxH
01-12-2009, 11:54 AM
What's wrong with the cones? They look good to me.

A quick and dirty cheat is to make one poly from the circle vertices you already have. The poly will cut through the earth's surface, UNLESS you turn off depth buffering before drawing the filled circle. The problem with this approach is that it won't look right when the circles are on the horizon.

Otherwise you're going to have to tessellate your original circle (as you mention). It's not that hard. I've done similar things in about 50 lines of code.

dletozeun
01-12-2009, 12:06 PM
no...I know how to do it, but I need the surfaces to be curved.

Ok, so that was what I was asking for. :) My question must been badly formulated.

The 1st idea I have is considering a point x on the earth, I assume that x is in the field of view of a satellite if:

|x - satellite_position| <= Rmax

Where Rmax, is the satellite range.

You can express points on the earth in spherical coordinates with the earth center as origin and with a vertical axis toward the satellite. With physicians conventions (theta is colatitude), you have to know the theta_max value from which the point x is out of range:

http://img513.imageshack.us/img513/4377/earthat5.th.png (http://img513.imageshack.us/my.php?image=earthat5.png)

You can compute theta_max transforming point x spherical coordinates to cartesian coordinates. Then calculate the difference between x and the satellite position and compare with Rmax.
This is easy since you have just one unknown variable: theta_max.

Then you can generate red surface points taking theta values in the range [0 theta_max] and Phi values in the range [0 2Pi] with a custom step for theta and Phi values, depending of how many slices and rings you want.

Z-Knight
01-12-2009, 03:04 PM
This is one solution for the "simple" case of a circular projection...I understand it. It requires that I basically do the triangulation (for example, Delaunay Triangulation) of the region (ie slices/rings) and use primitive calls to fill in polygons or triangles as I go...great for a circle case.

In the case of an irregular shapes it gets harder...for example, say I had the boundaries of the countries and I wanted to fill in the boundary of the united states with the color white then this would be a much tougher solution because I would have to use triangulation to figure out the triangles in the region and then I would have to figure out the radius at the triangle vertices so that they would be properly raised above the sphere boundary.

Sigh...I think I'm making this harder than is done in real life...I figure the example I just gave (coloring in a country boundary) has been done by others, I can't be the only one trying this.

Thanks for all of the help.

dletozeun
01-12-2009, 03:15 PM
If I understand you, you want that the ground coverage area shape fits countries borders?? You are asking to much here and is that useful indeed? Anyway you should explain clearly from the beginning what you want to do, that was not, the idea you exposed in your first post and we would not suggest you solutions that doesn't answer your real problem!

Z-Knight
01-12-2009, 03:44 PM
well it sort of was...I was just trying to be as simplistic as possible. I figured it would be easier to understand if I used a circle for the object and I was hoping the attached image explained better than I could in words.

My ultimate goal is to be able to map a 2D polygon onto a 3D surface. I want to be able to do multiple things with this...first is I want to show the circular ground coverage of a vehicle flying overhead - hence the circle. I would also want to be able to draw a ground station coverage zone that represents what a ground station on the surface can see - given that there are buildings/mountains etc that could obstruct its view - in which case the ground coverage zone would be an irregular circle with cutouts in it and that's not too much different that the irregular shapes of countries.

In all of these cases I have the coordinates (latitude/longitude) of the boundary - be it the circle boundary or the boundary of some irregular shape. I can draw the boundary that connects these coordinates and I would see the shape but I want to be able to now use a fill inside the region of the boundary. Say a solid or transparent fill - whatever, it doesn't matter as long as I can fill it.

So the question is how do I fill in this region while making sure that the area is curved so that it touches the surface of the planet and doesn't cut into it....basically, I need to figure out how to curve the area inside the boundary that I have and then use triangulation to calculate the triangles that make up that curve. This solution seems kind of hard and if I have to do this a lot because the vehicle moves or something changed, it seems like this would be very expensive to do repetitive triangulation and drawing of the surface.

This is supremely easy to do in Java2D - for obvious reasons, but when you go into 3D you have to be able to curve the surface up so that it looks like it is on top of the ground.

Thanks for taking the time to decipher my messages. :)

Z-Knight
01-12-2009, 03:54 PM
Clearly one option is to draw on the texture that I wrap around the earth, but I have moving vehicles and that would require me changing the texture each time the vehicle moves and that seems very costly do keep doing.

dletozeun
01-12-2009, 04:12 PM
It seems very complicated to realize this effect building the shape geometry... Maybe it is not applicable in your case but, I suggest you to use an an algorithm similar to shadow mapping combined with a shader that renders every objects on earth and earth itself in the coverage area.
The idea is, basing on the shadow map, to see what earth/object rendered fragment are visible or not from the satellite. If you are familiar with shadow mapping, you should see what I mean. This way, if you detect that some part of the earth or objects on this one is inside coverage area, you can blend its texture with the area color inside a fragment shader.

Z-Knight
01-12-2009, 04:19 PM
I'm not familiar with shadow mapping, but I think that is a possible direction...thanks for the idea.

MaxH
01-13-2009, 12:17 PM
As I mentioned before the case of a circular region on the earth's surface can be done with about 50 lines of codes. You have to generate vertices, tris, and quads internal to the circle you start with. Put all vertices exactly on the earth's surface. This will result in polys which cut through the earth's surface, which is taken care off by turning off the Z-buffer, drawing the polys, then turning it on again to draw orbits, satellites, etc. Generate your circular region with its center where the X axis intersects the earth's surface. Then use glRotate's to position the region at the correct lat and lon. You'll find it to be easier than it sounds. This is how I generated the circular boundaries and filled in regions in the included figure (the 2 northern-most circles are filled in with light, white, transparent, polys).

http://imagebin.ca/view/w729vb.html

Z-Knight
01-13-2009, 12:29 PM
Nice MaxH, that's is exactly what I need to do then...thanks for the info. I never thought about Z-buffer stuff...I'm pretty sure that's because I don't know that much OpenGL. I'll see what I can come up with. Very interesting solution.

This will definitely solve one of my needs, after that I just might need a little more code to make irregular regions work the same way.

Z-Knight
01-13-2009, 02:55 PM
btw, for the simple case of a filled in circle, I should just be able to use a gluDisk(), right? I really don't need to create the tris/quads/etc since gluDisk() will do it for me.

I'm going to try this now. thanks.

Z-Knight
01-13-2009, 03:24 PM
One question...how do I prevent the object from being seen when I rotate the earth away from the view...say I have a disk over the united states, but I rotate the earth and the US is behind and I'm looking at China...as it stands,I can still see the disk in the scene and through the earth. Do I need to enable back face culling?

MaxH
01-13-2009, 03:30 PM
btw, for the simple case of a filled in circle, I should just be able to use a gluDisk(), right? I really don't need to create the tris/quads/etc since gluDisk() will do it for me. It should work to some extent. Not sure if it will look right when a circular region is on the horizon. But it's worth a try.

MaxH
01-13-2009, 03:33 PM
...how do I prevent the object from being seen when I rotate the earth away from the view...say I have a disk over the united states, but I rotate the earth and the US is behind and I'm looking at China...as it stands,I can still see the disk in the scene and through the earth. Do I need to enable back face culling? Yes. Back face culling. Is gluDisk working well enough for your purposes?

Z-Knight
01-13-2009, 03:38 PM
Sort of...I probably need to figure out the order of drawing or maybe I'm seeing that horizon issue you just mentioned.

See the following 3 pics...the solution is crude right now:

This first image is a direct view of the "disk" using gluDisk()
http://i394.photobucket.com/albums/pp23/Z-Knight-Z/01.jpg

This second image is when I rotate my view and are almost seeing the disk edge on...I don't see the earth tip well (the part "above" the disk) well...it seems a bit transparent but that could be some issue with a blending flag...not sure yet.
http://i394.photobucket.com/albums/pp23/Z-Knight-Z/02.jpg

This third image is the earth rotated almost 180 degrees...so the disk is on the other side but it is being seen. Again, I might need to mess with my culling/blending flags more, etc. I
http://i394.photobucket.com/albums/pp23/Z-Knight-Z/03.jpg

dletozeun
01-13-2009, 03:51 PM
Where are the screenshots?
You mean that with back face culling enabled, the disc is visible when looking in front of and behind it? You must have been messed up something while setting face culling...
Try to simplify your code, to focus only on the rendering of this disc, you will probably find the solution.

Z-Knight
01-13-2009, 04:24 PM
dletozeun, You don't see the images in my post? hmm...I see them, weird.

http://i394.photobucket.com/albums/pp23/Z-Knight-Z/01.jpg
http://i394.photobucket.com/albums/pp23/Z-Knight-Z/02.jpg
http://i394.photobucket.com/albums/pp23/Z-Knight-Z/03.jpg

I think I probably did mess up the face culling...I need to dig in a bit more because I have other 3D shapes for which I wrote special classes and I'm reusing the disk class for my current test. I'm afraid I may have set some blending option that is causing the issue.

Thanks for all of the help...this is a real cool solution.

MaxH, I sent you a PM because I was curious about how you did the text, etc...if you get a chance I would appreciate any info. Thanks again.

Z-Knight
01-13-2009, 04:32 PM
btw, for the simple case of a filled in circle, I should just be able to use a gluDisk(), right? I really don't need to create the tris/quads/etc since gluDisk() will do it for me. It should work to some extent. Not sure if it will look right when a circular region is on the horizon. But it's worth a try.

btw, does yours work correctly when the circular region is on the horizon? I'm guessing we are talking about the same issue...the issue that you can see in picture #2 that I attached. In that case, you are seeing the disk from the side, and since the disk is not curved the part of the earth that sticks above disk is visible. Had you been looking straight down at it you would think that that piece of earth was covered by the disk but in the side view you see that it is not.

Clearly, if this is what you are experiencing also, then this solution would not work for the extreme case of say coloring half the earth one color. i.e. say you wanted to highlight the upper hemisphere and so you drew a disk through the center of the earth and when you turned of the depth test and viewed the earth from above you would see what you expect. But when you now viewed the earth from the side (ie towards the equator) you would only see the edge of the disk and both the top and bottom hemispheres would not be colored.

Sigh, that kind of sucks. I say that is an "extreme" case but not really...not for space visualization it is not. The reason is that some satellites have very high orbits and as such their ground coverage may in fact be the entire hemisphere of the earth and in that case this solution would not be optimal.

Well, at least I have some more options. This is kind of fun, if not frustrating. :)

MaxH
01-13-2009, 04:45 PM
Those links to your 3 images do not work for me. I get a message like: "You can't get there from here."

Z-Knight
01-13-2009, 04:46 PM
let me try those pics another way.

I've updated the pics and links to photobucket links...hope they work now.

MaxH
01-13-2009, 04:52 PM
.. does yours work correctly when the circular region is on the horizon?
My coverage regions work correctly on the horizon because I subdivide the regions into much smaller polygons all of which have vertices on the earth's surface.

Z-Knight
01-13-2009, 04:54 PM
ahh...good one. That makes good sense.

MaxH
01-13-2009, 04:55 PM
NOW - I can see the images where you use gluDisk to render the coverage reasons. That's not gonna do it. You have to subdivide your circles into smaller polygons.

Z-Knight
01-13-2009, 04:57 PM
yeah, sorry...too quick on the cut/paste of the links and I screwed it up. Now they are correct so yes you can see my issue. Time to figure out the subdivisions.

MaxH
01-13-2009, 05:09 PM
Z-Knight:

Do you want those country labels showing on the back side of the earth? If not, you can Z-buffer them out. To summarize:

1) Enable depth testing to draw the earth and country labels,
2) Disable depth testing to draw the coverage regions (with backface culling),
3) Enable depth testing to draw satellites, orbits, etc.

Step #2 can also be used to 'paint' sensor coverage swaths, groundtracks, etc., on the earth's surface. An example is at the link below ...

http://imagebin.ca/view/lEwXVW.html