Experimental terrain engine

From FlightGear wiki
Revision as of 13:59, 9 October 2016 by Psadro gm (talk | contribs) (Goals and Design of a new terrain engine for FlightGear)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: This project is currently under active development. And we're looking for volunteers interested in contributing.
So if you'd like to help in one way or another, please get in touch or just help improve the article in the meantime!
Useful Skills:
GDAL, C++, Developing using CMake


Contributors: too few

Mentors: psadro_gm (get in touch to learn more)
It's possible that this article hasn't been updated in a while, so to catch up with the latest developments, you are advised not to start working on anything directly related to this without first coordinating your ideas with fellow FlightGear contributors using the FlightGear developers mailing list or the FlightGear forums.

This article describes content/features that may not yet be available in the latest stable version of FlightGear (2020.3).
You may need to install some extra components, use the latest development (Git) version or even rebuild FlightGear from source, possibly from a custom topic branch using special build settings: .

This feature is scheduled for FlightGear 4.x. 10}% completed

If you'd like to learn more about getting your own ideas into FlightGear, check out Implementing new features for FlightGear.

Goals

The new experimental terrain engine main goals are:

  1. a shader based landclass engine utilizing raster encoded fileds to identify landclass, and smoothnexx of transitions between them
  2. a regular mesh that can be generated on the fly from standard gdal raster images
  3. utilize the OpenSceneGraph Database Pager for handling multiple levels of detail.

Currently, the work is being done on a topic branch. topics/new-scenery - located here simgear and here flightgear

Design Decisions

  1. modular terrain engine.

The user should be able to select the legacy terrain engine ( tile cache based ), or the new engine based on a property. In the flightgear/Scenery source, the Scenery object instantiates the selected terrain engine. The terrain object is a abstract base class, and new terrain engines derive from this class.

The following APIs are defined for all SGSubsystems

    // Implementation of SGSubsystem. - called from Scenery
    virtual void init ( osg::Group* terrain ) = 0;
    virtual void reinit() = 0;
    virtual void shutdown () = 0;
    virtual void bind () = 0;
    virtual void unbind () = 0;
    virtual void update (double dt) = 0;

These APIs are called from various other flightgear modules, like the FDM. They are used to query altitude and materials at given locations

    /// Compute the elevation of the scenery at geodetic latitude lat,
    /// geodetic longitude lon and not higher than max_alt.
    /// If the exact flag is set to true, the scenery center is moved to
    /// gain a higher accuracy of that query. The center is restored past
    /// that to the original value.
    /// The altitude hit is returned in the alt argument.
    /// The method returns true if the scenery is available for the given
    /// lat/lon pair. If there is no scenery for that point, the altitude
    /// value is undefined. 
    /// All values are meant to be in meters or degrees.
    virtual bool get_elevation_m(const SGGeod& geod, double& alt,
                                 const simgear::BVHMaterial** material,
                                 const osg::Node* butNotFrom = 0) = 0;

    /// Compute the elevation of the scenery below the cartesian point pos.
    /// you the returned scenery altitude is not higher than the position
    /// pos plus an offset given with max_altoff.
    /// If the exact flag is set to true, the scenery center is moved to
    /// gain a higher accuracy of that query. The center is restored past
    /// that to the original value.
    /// The altitude hit is returned in the alt argument.
    /// The method returns true if the scenery is available for the given
    /// lat/lon pair. If there is no scenery for that point, the altitude
    /// value is undefined.
    /// All values are meant to be in meters.
    virtual bool get_cart_elevation_m(const SGVec3d& pos, double max_altoff,
                                      double& elevation,
                                      const simgear::BVHMaterial** material,
                                      const osg::Node* butNotFrom = 0) = 0;

    /// Compute the nearest intersection point of the line starting from 
    /// start going in direction dir with the terrain.
    /// The input and output values should be in cartesian coordinates in the
    /// usual earth centered wgs84 coordinate system. Units are meters.
    /// On success, true is returned.
    virtual bool get_cart_ground_intersection(const SGVec3d& start, const SGVec3d& dir,
                                              SGVec3d& nearestHit,
                                              const osg::Node* butNotFrom = 0) = 0;

These APIs are called to determine the state of the scenery, or to schedule new scenery Scheduling new scenery from flightgear may or may not be necessary - depending on the engine.

    /// Returns true if scenery is available for the given lat, lon position
    /// within a range of range_m.
    /// lat and lon are expected to be in degrees.
    virtual bool scenery_available(const SGGeod& position, double range_m) = 0;

    // tile mgr api
    virtual bool schedule_scenery(const SGGeod& position, double range_m, double duration=0.0) = 0;

Finally, the effect engine notifies the terrain engine when the material library has changed. This occurs when moving from one regional texture definition to another. NOTE: how this can be done without being under flightgear control is TBD. We would need to setup the database pager with this info on terrain initialization.

    // tile is in a different regional texture definition.
    virtual void materialLibChanged() = 0;