Raytracing with terrain
From World Wind Wiki
Picking at terrain for NASA World Wind 1.4
by Patrick Murris <patmurris (at) videotron.ca> March 16, 2007
These sources are modifications to some WW classes to add a PickingRayIntersectionWithTerrain() method to the CameraBase class.
Included is PickAtTerrain.cs a test plugin that displays the lat/lon/alt under the mouse pointer.
Contents |
[edit] Camera.cs
- Added PickingRayIntersectionWithTerrain(): Same arguments as PickingRayIntersection() with the addition of the current world (needed to use the TerrainAccessor).
- Use ray casting with a sampling length of 100m.
- Use a new memory only method to get elevation from terrain (see below)
- More suited for close range picking (under 60km altitude)
- Needs some optimization and tuning but works well.
- Changed ComputeAbsoluteMatrices() - View matrix logic
- Use currentCameraElevation in the same way as the 'real' view matrix in ComputeViewMatrix(): WorldRadius + curCameraElevation instead of WorldRadius
- this._distance + curCameraElevation instead of
- this._distance - curCameraElevation
- Affects picking and view frustrum when ElevateCameraLookatPoint is true.
- Tests ok so far.
- Use currentCameraElevation in the same way as the 'real' view matrix in ComputeViewMatrix(): WorldRadius + curCameraElevation instead of WorldRadius
[edit] NltTerrainAccessor.cs
- Added GetCachedElevationAt() method to retreive elevations without triggering downloads in foreground. Uses memory data only.
- Will get the best available data from the terrain accessor cache.
- Will return float.NaN is no data found.
[edit] TerrainAccessor.cs
- Added virtual GetCachedElevationAt()
[edit] TerrainTileService.cs
- Made NumberLevels public
[edit] Known issues
- Terrain picking doesnt work well and can become very slow if used from far away - especially at startup when no elevation data is in the cache yet. Use the regular PickingRayIntersection() above 60km altitude.
- Ray casting sampling logic needs some optimization.