]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIWingman.hxx
NavDisplay: fix update lag when switching range or centre.
[flightgear.git] / src / AIModel / AIWingman.hxx
1 // FGAIWingman - FGAIBllistic-derived class creates an AI Wingman
2 //
3 // Written by Vivian Meazza, started February 2008.
4 // - vivian.meazza at lineone.net
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20 #ifndef _FG_AIWINGMAN_HXX
21 #define _FG_AIWINGMAN_HXX
22
23 #include "AIBallistic.hxx"
24
25 #include "AIManager.hxx"
26 #include "AIBase.hxx"
27
28 #include <simgear/sg_inlines.h>
29 #include <simgear/math/SGMath.hxx>
30
31
32 class FGAIWingman : public FGAIBallistic {
33 public:
34     FGAIWingman();
35     virtual ~FGAIWingman();
36
37     virtual void readFromScenario(SGPropertyNode* scFileNode);
38
39     bool init(bool search_in_AI_path=false);
40     virtual void bind();
41     virtual void unbind();
42     virtual void reinit();
43     virtual void update (double dt);
44
45     virtual const char* getTypeString(void) const { return "wingman"; }
46
47 private:
48     void formateToAC(double dt);
49     void Break(double dt);
50     void Join(double dt);
51     void Run(double dt);
52
53     double getDistanceToOffset() const;
54     double getElevToOffset() const;
55
56     double calcAngle(double rangeM, SGGeod pos1, SGGeod pos2);
57     double calcDistanceM(SGGeod pos1, SGGeod pos2) const;
58
59     bool   _formate_to_ac;
60     bool   _break;
61     bool   _join;
62
63     double _break_angle; //degrees relative
64     double _coeff_hdg; //dimensionless coefficient
65     double _coeff_pch; //dimensionless coefficient
66     double _coeff_bnk; //dimensionless coefficient
67     double _coeff_spd; //dimensionless coefficient
68
69     SGPropertyNode_ptr user_WoW_node;
70
71     inline void setFormate(bool f);
72     inline void setTgtHdg(double hdg);
73     inline void setTgtSpd(double spd);
74     inline void setBrkHdg(double angle);
75     inline void setBrkAng(double angle);
76     inline void setCoeffHdg(double h);
77     inline void setCoeffPch(double p);
78     inline void setCoeffBnk(double r);
79     inline void setCoeffSpd(double s);
80
81     inline bool getFormate() const { return _formate_to_ac;}
82
83     inline double getTgtHdg() const { return tgt_heading;}
84     inline double getTgtSpd() const { return tgt_speed;}
85     inline double getBrkAng() const { return _break_angle;}
86
87     inline SGVec3d getCartInPos(SGGeod in_pos) const;
88
89 };
90
91 void FGAIWingman::setFormate(bool f) {
92     _formate_to_ac = f;
93 }
94
95 void FGAIWingman::setTgtHdg(double h) {
96     tgt_heading = h;
97 }
98
99 void FGAIWingman::setTgtSpd(double s) {
100     tgt_speed = s;
101 }
102
103 void FGAIWingman::setBrkHdg(double a){
104     tgt_heading = hdg + a ;
105     SG_NORMALIZE_RANGE(tgt_heading, 0.0, 360.0);
106 }
107
108 void FGAIWingman::setBrkAng(double a){
109     _break_angle = a ;
110     SG_NORMALIZE_RANGE(_break_angle, -180.0, 180.0);
111 }
112
113 void FGAIWingman::setCoeffHdg(double h){
114     _coeff_hdg = h;
115 }
116
117 void FGAIWingman::setCoeffPch(double p){
118     _coeff_pch = p;
119 }
120
121 void FGAIWingman::setCoeffBnk(double b){
122     _coeff_bnk = b;
123 }
124
125 void FGAIWingman::setCoeffSpd(double s){
126     _coeff_spd = s;
127 }
128
129 //bool FGAIWingman::getFormate() const {
130 //    return _formate_to_ac;
131 //}
132
133 //double FGAIWingman::getTgtHdg() const{
134 //    return tgt_heading;
135 //}
136
137 //double FGAIWingman::getTgtSpd() const{
138 //    return tgt_speed;
139 //}
140
141 //double FGAIWingman::getBrkAng() const{
142 //    return _break_angle;
143 //}
144
145 SGVec3d FGAIWingman::getCartInPos(SGGeod in_pos) const {
146     SGVec3d cartPos = SGVec3d::fromGeod(in_pos);
147     return cartPos;
148 }
149
150 #endif  // FG_AIWINGMAN_HXX