Object Placement with Terrain

classic Classic list List threaded Threaded
5 messages Options
jwils jwils
Reply | Threaded
Open this post in threaded view
|

Object Placement with Terrain

Hello,

I'm currently trying to place objects onto osgEarth with elevation data loaded in.  I have a lat/lon point where I'd like to place the object, and I am converting that to an xyz point on the earth using the EllipsoidModel routines, then I am shooting a LineSegmentIntersector through that point to find the intersection with the terrain (using the USE_EYE_POINT_FOR_LOD_LEVEL_SELECTION LOD selection mode).  I am getting an intersection appropriately, but I find that, even after things have stabilized with loading in maps/terrain, my objects aren't necessarily on the terrain; they are sometimes slightly above it and sometimes slightly below it (which is the really bad case).  Has anyone had success using this method, or know what kind of problems might be faced with this method?  Is there a better way to do what I'm trying to do?  I read an older post that mentioned using ReadFileCallback, but I wasn't too sure on how to proceed with that.  Thanks for your help!
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: Object Placement with Terrain

Hi,

When are you updating the location of your objects, just once after the map is loaded?  The issue with USE_EYE_POINT_FOR_LOD_LEVEL_SELECTION_LOD is that it only works on LODS that are currently loaded into memory.  So, if you are zoomed out from the scene, try to update your objects, then zoom in, the locations will be off.  You could use a ReadCallback like the osgSim::LineOfSight class does which will force the loading of PagedLODs that haven't been loaded yet.  The issue with that method is that it can take a long time to download and process tiles just to do intersections.

The idea that was mentioned with the ReadCallback was to inspect the incoming file, and if it is a terrain tile and your object would be affected by it, adjust the location of your object by performing an intersection with the scene graph.

Another way to accomplish this same task would be to just attach an update or cull callback to the object and once every X frames or Y seconds recompute the location of the object in the scene graph.

Hope that helps,

Jason

On Wed, Jul 15, 2009 at 12:39 PM, jwils (via Nabble) <[hidden email]> wrote:
Hello,

I'm currently trying to place objects onto osgEarth with elevation data loaded in.  I have a lat/lon point where I'd like to place the object, and I am converting that to an xyz point on the earth using the EllipsoidModel routines, then I am shooting a LineSegmentIntersector through that point to find the intersection with the terrain (using the USE_EYE_POINT_FOR_LOD_LEVEL_SELECTION LOD selection mode).  I am getting an intersection appropriately, but I find that, even after things have stabilized with loading in maps/terrain, my objects aren't necessarily on the terrain; they are sometimes slightly above it and sometimes slightly below it (which is the really bad case).  Has anyone had success using this method, or know what kind of problems might be faced with this method?  Is there a better way to do what I'm trying to do?  I read an older post that mentioned using ReadFileCallback, but I wasn't too sure on how to proceed with that.  Thanks for your help!


View message @ http://n2.nabble.com/Object-Placement-with-Terrain-tp3264395p3264395.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.


jwils jwils
Reply | Threaded
Open this post in threaded view
|

Re: Object Placement with Terrain

Thanks very much for your quick reply, Jason.  I'm updating the location of the objects continuously through running the app (temporarily, I've setup a thread that just keeps reshooting the LineSegmentIntersector for the object every second), so I would have thought I would catch new LODs as they get paged in.  I may try the update callback just to try a different angle, thanks again!

Hi,

When are you updating the location of your objects, just once after the map is loaded?  The issue with USE_EYE_POINT_FOR_LOD_LEVEL_SELECTION_LOD is that it only works on LODS that are currently loaded into memory.  So, if you are zoomed out from the scene, try to update your objects, then zoom in, the locations will be off.  You could use a ReadCallback like the osgSim::LineOfSight class does which will force the loading of PagedLODs that haven't been loaded yet.  The issue with that method is that it can take a long time to download and process tiles just to do intersections.

The idea that was mentioned with the ReadCallback was to inspect the incoming file, and if it is a terrain tile and your object would be affected by it, adjust the location of your object by performing an intersection with the scene graph.

Another way to accomplish this same task would be to just attach an update or cull callback to the object and once every X frames or Y seconds recompute the location of the object in the scene graph.

Hope that helps,

Jason
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Object Placement with Terrain

Jwils,

How exactly are you creating your intersection vector? A common error is to use EllipsoidModel functions to get a geocentric XYZ, and then to use (0,0,0) as the other endpoint. This will only be accurate for a spherical globe (and not for WGS84).
Glenn Waldron / Pelican Mapping
jwils jwils
Reply | Threaded
Open this post in threaded view
|

Re: Object Placement with Terrain

And I have made the common error!  Thanks Glenn, it now works like a charm.  Instead of (0,0,0), I used the x,y,z from the local up vector as the start point (as the end point, I'm multiplying the local up vector by a large scalar to make it fall outside of the earth, so both points now lie along the local up vector).  Great catch, thanks again!