]> git.mxchange.org Git - flightgear.git/blob - src/ATC/AIEntity.cxx
#include <config.h> where needed for cygwin/gcc-3.2.
[flightgear.git] / src / ATC / AIEntity.cxx
1 // FGAIEntity - abstract base class an artificial intelligence entity
2 //
3 // Written by David Luff, started March 2002.
4 //
5 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 /*****************************************************************
22 *
23 * WARNING - Curt has some ideas about AI traffic so anything in here
24 * may get rewritten or scrapped.  Contact Curt curt@flightgear.org 
25 * before spending any time or effort on this code!!!
26 *
27 ******************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 #  include <config.h>
31 #endif
32
33 #include <Main/globals.hxx>
34 #include <Scenery/scenery.hxx>
35 //#include <simgear/constants.h>
36 #include <simgear/math/point3d.hxx>
37 #include <simgear/math/sg_geodesy.hxx>
38 #include <simgear/misc/sg_path.hxx>
39 #include <string>
40
41 #include "AIEntity.hxx"
42
43 FGAIEntity::~FGAIEntity() {
44 }
45
46 void FGAIEntity::Update(double dt) {
47 }
48
49 // Run the internal calculations
50 //void FGAIEntity::Update() {
51 void FGAIEntity::Transform() {
52     aip.setPosition(pos.lon(), pos.lat(), pos.elev() * SG_METER_TO_FEET);
53     aip.setOrientation(roll, pitch, hdg);
54     aip.update();    
55 }
56
57 /*
58 void FGAIEntity::Transform() {
59
60     // Translate moving object w.r.t eye
61     Point3D sc = globals->get_scenery()->get_center();
62     //cout << "sc0 = " << sc.x() << " sc1 = " << sc.y() << " sc2 = " << sc.z() << '\n';
63     //cout << "op0 = " << obj_pos.x() << " op1 = " << obj_pos.y() << " op2 = " << obj_pos.z() << '\n';
64
65     sgCoord shippos;
66     FastWorldCoordinate(&shippos, sc);
67     position->setTransform( &shippos );
68     //cout << "Transform called\n";
69 }
70 */
71
72 #if 0
73 // Taken from tileentry.cxx
74 void FGAIEntity::WorldCoordinate(sgCoord *obj_pos, Point3D center) {
75     // setup transforms
76     Point3D geod( pos.lon() * SGD_DEGREES_TO_RADIANS,
77                   pos.lat() * SGD_DEGREES_TO_RADIANS,
78                   pos.elev() );
79         
80     Point3D world_pos = sgGeodToCart( geod );
81     Point3D offset = world_pos - center;
82         
83     sgMat4 POS;
84     sgMakeTransMat4( POS, offset.x(), offset.y(), offset.z() );
85
86     sgVec3 obj_rt, obj_up;
87     sgSetVec3( obj_rt, 0.0, 1.0, 0.0); // Y axis
88     sgSetVec3( obj_up, 0.0, 0.0, 1.0); // Z axis
89
90     sgMat4 ROT_lon, ROT_lat, ROT_hdg;
91     sgMakeRotMat4( ROT_lon, lon, obj_up );
92     sgMakeRotMat4( ROT_lat, 90 - lat, obj_rt );
93     sgMakeRotMat4( ROT_hdg, hdg, obj_up );
94
95     sgMat4 TUX;
96     sgCopyMat4( TUX, ROT_hdg );
97     sgPostMultMat4( TUX, ROT_lat );
98     sgPostMultMat4( TUX, ROT_lon );
99     sgPostMultMat4( TUX, POS );
100
101     sgSetCoord( obj_pos, TUX );
102 }
103 #endif
104 /*
105 // Norman's 'fast hack' for above
106 void FGAIEntity::FastWorldCoordinate(sgCoord *obj_pos, Point3D center) {
107     double lon_rad = pos.lon() * SGD_DEGREES_TO_RADIANS;
108     double lat_rad = pos.lat() * SGD_DEGREES_TO_RADIANS;
109     double hdg_rad = hdg * SGD_DEGREES_TO_RADIANS;
110
111     // setup transforms
112     Point3D geod( lon_rad, lat_rad, pos.elev() );
113         
114     Point3D world_pos = sgGeodToCart( geod );
115     Point3D offset = world_pos - center;
116
117     sgMat4 mat;
118
119     SGfloat sin_lat = (SGfloat)sin( lat_rad );
120     SGfloat cos_lat = (SGfloat)cos( lat_rad );
121     SGfloat cos_lon = (SGfloat)cos( lon_rad );
122     SGfloat sin_lon = (SGfloat)sin( lon_rad );
123     SGfloat sin_hdg = (SGfloat)sin( hdg_rad ) ;
124     SGfloat cos_hdg = (SGfloat)cos( hdg_rad ) ;
125
126     mat[0][0] =  cos_hdg * (SGfloat)sin_lat * (SGfloat)cos_lon - sin_hdg * (SGfloat)sin_lon;
127     mat[0][1] =  cos_hdg * (SGfloat)sin_lat * (SGfloat)sin_lon + sin_hdg * (SGfloat)cos_lon;
128     mat[0][2] = -cos_hdg * (SGfloat)cos_lat;
129     mat[0][3] =  SG_ZERO;
130
131     mat[1][0] = -sin_hdg * (SGfloat)sin_lat * (SGfloat)cos_lon - cos_hdg * (SGfloat)sin_lon;
132     mat[1][1] = -sin_hdg * (SGfloat)sin_lat * (SGfloat)sin_lon + cos_hdg * (SGfloat)cos_lon;
133     mat[1][2] =  sin_hdg * (SGfloat)cos_lat;
134     mat[1][3] =  SG_ZERO;
135
136     mat[2][0] = (SGfloat)cos_lat * (SGfloat)cos_lon;
137     mat[2][1] = (SGfloat)cos_lat * (SGfloat)sin_lon;
138     mat[2][2] = (SGfloat)sin_lat;
139     mat[2][3] =  SG_ZERO;
140
141     mat[3][0] = offset.x();
142     mat[3][1] = offset.y();
143     mat[3][2] = offset.z();
144     mat[3][3] = SG_ONE ;
145
146     sgSetCoord( obj_pos, mat );
147 }
148 */