| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGGroundCallback.h |
| 4 | Author: Mathias Froehlich |
| 5 | Date started: 05/21/04 |
| 6 | |
| 7 | ------ Copyright (C) 2004 Mathias Froehlich ([email protected]) ------- |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify it under |
| 10 | the terms of the GNU Lesser General Public License as published by the Free |
| 11 | Software Foundation; either version 2 of the License, or (at your option) any |
| 12 | later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 17 | details. |
| 18 | |
| 19 | You should have received a copy of the GNU Lesser General Public License along |
| 20 | with this program; if not, write to the Free Software Foundation, Inc., 59 |
| 21 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | |
| 23 | Further information about the GNU Lesser General Public License can also be |
| 24 | found on the world wide web at http://www.gnu.org. |
| 25 | |
| 26 | HISTORY |
| 27 | ------------------------------------------------------------------------------- |
| 28 | 05/21/00 MF Created |
| 29 | |
| 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 31 | SENTRY |
| 32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 33 | |
| 34 | #ifndef FGGROUNDCALLBACK_H |
| 35 | #define FGGROUNDCALLBACK_H |
| 36 | |
| 37 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 38 | INCLUDES |
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 40 | |
| 41 | namespace JSBSim { |
| 42 | |
| 43 | class FGLocation; |
| 44 | class FGColumnVector3; |
| 45 | |
| 46 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 47 | CLASS DOCUMENTATION |
| 48 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 49 | |
| 50 | /** This class provides callback slots to get ground specific data. |
| 51 | |
| 52 | The default implementation returns values for a |
| 53 | ball formed earth with an adjustable terrain elevation. |
| 54 | |
| 55 | @author Mathias Froehlich |
| 56 | */ |
| 57 | |
| 58 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 59 | CLASS DECLARATION |
| 60 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 61 | |
| 62 | class JSBSIM_API FGGroundCallback |
| 63 | { |
| 64 | public: |
| 65 | |
| 66 | FGGroundCallback() : time(0.0) {} |
| 67 | virtual ~FGGroundCallback() {} |
| 68 | |
| 69 | /** Compute the altitude above ground. |
| 70 | The altitude depends on time t and location l. |
| 71 | @param t simulation time |
| 72 | @param l location |
| 73 | @param contact Contact point location below the location l |
| 74 | @param normal Normal vector at the contact point |
| 75 | @param v Linear velocity at the contact point |
| 76 | @param w Angular velocity at the contact point |
| 77 | @return altitude above ground |
| 78 | */ |
| 79 | virtual double GetAGLevel(double t, const FGLocation& location, |
| 80 | FGLocation& contact, |
| 81 | FGColumnVector3& normal, FGColumnVector3& v, |
| 82 | FGColumnVector3& w) const = 0; |
| 83 | |
| 84 | /** Compute the altitude above ground. |
| 85 | The altitude depends on location l. |
| 86 | @param l location |
| 87 | @param contact Contact point location below the location l |
| 88 | @param normal Normal vector at the contact point |
| 89 | @param v Linear velocity at the contact point |
| 90 | @param w Angular velocity at the contact point |
| 91 | @return altitude above ground |
| 92 | */ |
| 93 | virtual double GetAGLevel(const FGLocation& location, FGLocation& contact, |
| 94 | FGColumnVector3& normal, FGColumnVector3& v, |
| 95 | FGColumnVector3& w) const |
| 96 | { return GetAGLevel(time, location, contact, normal, v, w); } |
| 97 | |
| 98 | /** Set the terrain elevation. |
| 99 | Only needs to be implemented if JSBSim should be allowed |
| 100 | to modify the local terrain radius (see the default implementation) |
| 101 | */ |
| 102 | virtual void SetTerrainElevation(double h) {} |
| 103 | |
| 104 | /** Set the planet semimajor and semiminor axes. |
| 105 | Only needs to be implemented if JSBSim should be allowed to modify |
| 106 | the planet dimensions. |
| 107 | */ |
| 108 | virtual void SetEllipse(double semimajor, double semiminor) {} |
| 109 | |
| 110 | /** Set the simulation time. |
| 111 | The elapsed time can be used by the ground callbck to assess the planet |
| 112 | rotation or the movement of objects. |
| 113 | @param _time elapsed time in seconds since the simulation started. |
| 114 | */ |
| 115 | void SetTime(double _time) { time = _time; } |
| 116 | |
| 117 | protected: |
| 118 | double time; |
| 119 | }; |
| 120 | |
| 121 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 122 | // The default sphere earth implementation: |
| 123 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 124 | |
| 125 | class JSBSIM_API FGDefaultGroundCallback : public FGGroundCallback |
| 126 | { |
| 127 | public: |
| 128 | explicit FGDefaultGroundCallback(double semiMajor, double semiMinor) : |
| 129 | a(semiMajor), b(semiMinor) {} |
| 130 | |
| 131 | double GetAGLevel(double t, const FGLocation& location, |
| 132 | FGLocation& contact, |
| 133 | FGColumnVector3& normal, FGColumnVector3& v, |
| 134 | FGColumnVector3& w) const override; |
| 135 | |
| 136 | void SetTerrainElevation(double h) override |
| 137 | { mTerrainElevation = h; } |
| 138 | |
| 139 | void SetEllipse(double semimajor, double semiminor) override |
| 140 | { a = semimajor; b = semiminor; } |
| 141 | |
| 142 | private: |
| 143 | double a, b; |
| 144 | double mTerrainElevation = 0.0; |
| 145 | }; |
| 146 | |
| 147 | } |
| 148 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 149 | #endif |