]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.cxx
11b17dc412c190632d08d11c7cf888dcecd42887
[flightgear.git] / src / AIModel / AIBase.cxx
1 // FGAIBase - abstract base class for AI objects
2 // Written by David Culp, started Nov 2003, based on
3 // David Luff's FGAIEntity class.
4 // - davidculp2@comcast.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., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include <plib/sg.h>
26 #include <plib/ssg.h>
27 #include <Main/globals.hxx>
28 #include <Scenery/scenery.hxx>
29 #include <simgear/math/point3d.hxx>
30 #include <simgear/misc/sg_path.hxx>
31 #include <simgear/scene/model/location.hxx>
32 #include <simgear/scene/model/model.hxx>
33 #include <simgear/debug/logstream.hxx>
34 #include <string>
35
36 #include "AIBase.hxx"
37
38 FGAIBase::~FGAIBase() {
39 }
40
41 void FGAIBase::update(double dt) {
42 }
43
44
45 void FGAIBase::Transform() {
46     aip.setPosition(pos.lon(), pos.lat(), pos.elev() * SG_METER_TO_FEET);
47     aip.setOrientation(roll, pitch, hdg);
48     aip.update( globals->get_scenery()->get_center() );    
49 }
50
51
52 bool FGAIBase::init() {
53    ssgBranch *model = sgLoad3DModel( globals->get_fg_root(),
54                                      model_path.c_str(),
55                                      globals->get_props(),
56                                      globals->get_sim_time_sec() );
57    if (model) {
58      aip.init( model );
59      aip.setVisible(true);
60      globals->get_scenery()->get_scene_graph()->addKid(aip.getSceneGraph());
61    } else {
62      SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load aircraft model.");
63    } 
64
65    tgt_roll = tgt_pitch = tgt_yaw = tgt_vs = vs = roll = pitch = 0.0;
66    setDie(false);
67 }
68
69
70 void FGAIBase::setPath( const char* model ) {
71   model_path.append(model);
72 }
73
74 void FGAIBase::setSpeed( double speed_KTAS ) {
75   speed = tgt_speed = speed_KTAS;
76 }
77
78 void FGAIBase::setAltitude( double altitude_ft ) {
79   altitude = tgt_altitude = altitude_ft;
80   pos.setelev(altitude * 0.3048);
81 }
82
83 void FGAIBase::setLongitude( double longitude ) {
84   pos.setlon(longitude);
85 }
86
87 void FGAIBase::setLatitude( double latitude ) {
88   pos.setlat(latitude);
89 }
90
91 void FGAIBase::setHeading( double heading ) {
92   hdg = tgt_heading = heading;
93 }
94
95 void FGAIBase::setDie( bool die ) {
96   delete_me = die;
97 }
98