]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/AIEntity.cxx
Migrate FlightGear code to use "#include SG_GL*" defined in
[flightgear.git] / src / ATC / AIEntity.cxx
index 67ba889eba031cfb13316277ce6f63aaacec540e..d87b86dbfcc76225ad7695a8654096d272f186da 100644 (file)
 *
 ******************************************************************/
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
-//#include <simgear/constants.h>
+#include <simgear/constants.h>
 #include <simgear/math/point3d.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
 
 #include "AIEntity.hxx"
 
-extern ssgRoot* scene; // The global Flightgear scene graph
+FGAIEntity::FGAIEntity() {
+}
 
 FGAIEntity::~FGAIEntity() {
+       //cout << "FGAIEntity dtor called..." << endl;
+       _model->deRef();        // Ought to check valid?
+       //cout << "Removing model from scene graph..." << endl;
+       globals->get_scenery()->get_scene_graph()->removeKid(_aip.getSceneGraph());
+       //cout << "Done!" << endl;
 }
 
-// Run the internal calculations
-void FGAIEntity::Update() {
+void FGAIEntity::SetModel(ssgBranch* model) {
+       _model = model;
+       _model->ref();
+       _aip.init(_model);
+       _aip.setVisible(false);
+       globals->get_scenery()->get_scene_graph()->addKid(_aip.getSceneGraph());
 }
 
-void FGAIEntity::Transform() {
-
-    // Translate moving object w.r.t eye
-    Point3D sc = scenery.get_center();
-    //cout << "sc0 = " << sc.x() << " sc1 = " << sc.y() << " sc2 = " << sc.z() << '\n';
-    //cout << "op0 = " << obj_pos.x() << " op1 = " << obj_pos.y() << " op2 = " << obj_pos.z() << '\n';
-
-    sgCoord shippos;
-    FastWorldCoordinate(&shippos, sc);
-    position->setTransform( &shippos );
-    scene->addKid(position);
-    //cout << "Transform called\n";
+void FGAIEntity::Update(double dt) {
 }
 
-#if 0
-// Taken from tileentry.cxx
-void FGAIEntity::WorldCoordinate(sgCoord *obj_pos, Point3D center) {
-    // setup transforms
-    Point3D geod( lon * SGD_DEGREES_TO_RADIANS,
-                  lat * SGD_DEGREES_TO_RADIANS,
-                  elev );
-       
-    Point3D world_pos = sgGeodToCart( geod );
-    Point3D offset = world_pos - center;
-       
-    sgMat4 POS;
-    sgMakeTransMat4( POS, offset.x(), offset.y(), offset.z() );
-
-    sgVec3 obj_rt, obj_up;
-    sgSetVec3( obj_rt, 0.0, 1.0, 0.0); // Y axis
-    sgSetVec3( obj_up, 0.0, 0.0, 1.0); // Z axis
-
-    sgMat4 ROT_lon, ROT_lat, ROT_hdg;
-    sgMakeRotMat4( ROT_lon, lon, obj_up );
-    sgMakeRotMat4( ROT_lat, 90 - lat, obj_rt );
-    sgMakeRotMat4( ROT_hdg, hdg, obj_up );
-
-    sgMat4 TUX;
-    sgCopyMat4( TUX, ROT_hdg );
-    sgPostMultMat4( TUX, ROT_lat );
-    sgPostMultMat4( TUX, ROT_lon );
-    sgPostMultMat4( TUX, POS );
-
-    sgSetCoord( obj_pos, TUX );
+string FGAIEntity::GetCallsign() {
+       return("");
 }
-#endif
-
-// Norman's 'fast hack' for above
-void FGAIEntity::FastWorldCoordinate(sgCoord *obj_pos, Point3D center) {
-    double lon_rad = lon * SGD_DEGREES_TO_RADIANS;
-    double lat_rad = lat * SGD_DEGREES_TO_RADIANS;
-    double hdg_rad = hdg * SGD_DEGREES_TO_RADIANS;
-
-    // setup transforms
-    Point3D geod( lon_rad, lat_rad, elev );
-       
-    Point3D world_pos = sgGeodToCart( geod );
-    Point3D offset = world_pos - center;
-
-    sgMat4 mat;
-
-    SGfloat sin_lat = (SGfloat)sin( lat_rad );
-    SGfloat cos_lat = (SGfloat)cos( lat_rad );
-    SGfloat cos_lon = (SGfloat)cos( lon_rad );
-    SGfloat sin_lon = (SGfloat)sin( lon_rad );
-    SGfloat sin_hdg = (SGfloat)sin( hdg_rad ) ;
-    SGfloat cos_hdg = (SGfloat)cos( hdg_rad ) ;
-
-    mat[0][0] =  cos_hdg * (SGfloat)sin_lat * (SGfloat)cos_lon - sin_hdg * (SGfloat)sin_lon;
-    mat[0][1] =  cos_hdg * (SGfloat)sin_lat * (SGfloat)sin_lon + sin_hdg * (SGfloat)cos_lon;
-    mat[0][2] =        -cos_hdg * (SGfloat)cos_lat;
-    mat[0][3] =         SG_ZERO;
 
-    mat[1][0] = -sin_hdg * (SGfloat)sin_lat * (SGfloat)cos_lon - cos_hdg * (SGfloat)sin_lon;
-    mat[1][1] = -sin_hdg * (SGfloat)sin_lat * (SGfloat)sin_lon + cos_hdg * (SGfloat)cos_lon;
-    mat[1][2] =         sin_hdg * (SGfloat)cos_lat;
-    mat[1][3] =         SG_ZERO;
-
-    mat[2][0] = (SGfloat)cos_lat * (SGfloat)cos_lon;
-    mat[2][1] = (SGfloat)cos_lat * (SGfloat)sin_lon;
-    mat[2][2] =        (SGfloat)sin_lat;
-    mat[2][3] =  SG_ZERO;
-
-    mat[3][0] = offset.x();
-    mat[3][1] = offset.y();
-    mat[3][2] = offset.z();
-    mat[3][3] = SG_ONE ;
+void FGAIEntity::RegisterTransmission(int code) {
+}
 
-    sgSetCoord( obj_pos, mat );
+// Run the internal calculations
+//void FGAIEntity::Update() {
+void FGAIEntity::Transform() {
+    _aip.setPosition(_pos.lon(), _pos.lat(), _pos.elev() * SG_METER_TO_FEET);
+    _aip.setOrientation(_roll, _pitch, _hdg);
+    _aip.update( globals->get_scenery()->get_center() );    
 }