]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/AIEntity.cxx
Emergency fix for AI model loading - non existance of the piper model as in the lates...
[flightgear.git] / src / ATC / AIEntity.cxx
index 837c02c3a6fd0aee71bbcf37226137f15d4d9b56..9dccebea01911ec734d2d84c3c6fa884eb23634f 100644 (file)
@@ -21,7 +21,7 @@
 /*****************************************************************
 *
 * WARNING - Curt has some ideas about AI traffic so anything in here
-* may get rewritten or scrapped.  Contact Curt curt@flightgear.org 
+* may get rewritten or scrapped.  Contact Curt http://www.flightgear.org/~curt 
 * before spending any time or effort on this code!!!
 *
 ******************************************************************/
@@ -32,7 +32,7 @@
 
 #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"
 
-FGAIEntity::~FGAIEntity() {
+FGAIEntity::FGAIEntity() {
 }
 
-void FGAIEntity::Update(double dt) {
+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::Transform() {
-    aip.setPosition(pos.lon(), pos.lat(), pos.elev() * SG_METER_TO_FEET);
-    aip.setOrientation(roll, pitch, hdg);
-    aip.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 = globals->get_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 );
-    //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( pos.lon() * SGD_DEGREES_TO_RADIANS,
-                  pos.lat() * SGD_DEGREES_TO_RADIANS,
-                  pos.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 = pos.lon() * SGD_DEGREES_TO_RADIANS;
-    double lat_rad = pos.lat() * SGD_DEGREES_TO_RADIANS;
-    double hdg_rad = hdg * SGD_DEGREES_TO_RADIANS;
-
-    // setup transforms
-    Point3D geod( lon_rad, lat_rad, pos.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() );    
 }
-*/