+namespace simgear {
+class BVHMaterial;
+}
+
+/**
+ * A little helper class to update the track if
+ * the position has changed. In the constructor,
+ * create a copy of the current position and store
+ * references to the position object and the track
+ * variable to update.
+ * The destructor, called at TrackComputer's end of
+ * life/visibility, computes the track if the
+ * position has changed.
+ */
+class TrackComputer {
+public:
+ inline TrackComputer( double & track, const SGGeod & position ) :
+ _track( track ),
+ _position( position ),
+ _prevPosition( position ) {
+ }
+
+ inline ~TrackComputer() {
+ if( _prevPosition == _position ) return;
+ _track = SGGeodesy::courseDeg( _prevPosition, _position );
+ }
+private:
+ double & _track;
+ const SGGeod & _position;
+ const SGGeod _prevPosition;
+};
+