3131#include < cover/input/input.h>
3232#include " cover/input/deviceDiscovery.h"
3333#include < cstring>
34+ #include < geodata/GeoData.h>
3435#include < osg/Math>
3536#include < osg/Matrix>
3637#include < osg/MatrixTransform>
3738#include < osg/Vec3f>
3839#include < plugins/general/GeoData/GeoDataLoader.h>
39- #include < proj.h>
4040#include < string>
4141#include < util/UDPComm.h>
4242#include < util/byteswap.h>
@@ -171,8 +171,6 @@ void JSBSimPlugin::reset(double dz)
171171
172172 osg::Matrix viewer = cover->getInvBaseMat ();
173173 std::cout << " Viewer position: " << viewer.getTrans () << std::endl;
174- osg::Vec3 viewerPosition = viewer.getTrans () - getOriginOffset ();
175- std::cout << " Viewer position (offset): " << viewerPosition << std::endl;
176174
177175 // Compute the eyepoint transformation from the aircraft. The GetXYZep method returns
178176 // a dimension in inches, so we divide by
@@ -186,18 +184,14 @@ void JSBSimPlugin::reset(double dz)
186184 }
187185
188186 // Transform the viewer coordinates to lat/lng
189- PJ_COORD c;
190- c.enu .e = viewerPosition[0 ];
191- c.enu .n = viewerPosition[1 ];
192- c.enu .u = viewerPosition[2 ];
193- PJ_COORD c_out = proj_trans (coordTransformation, PJ_INV , c);
194- IC ->SetLongitudeDegIC (c_out.lp .phi );
195- IC ->SetLatitudeDegIC (c_out.lp .lam );
196-
197- float altitude = viewerPosition[2 ] + dz;
187+ osg::Vec3 pos = GeoData::instance ()->getGlobalPosition ();
188+
189+ float altitude = pos.z ();
198190 float altitudeFt = altitude / METERS_PER_FOOT - Aircraft->GetXYZep (3 ) * FEET_PER_INCH ;
199191
200- std::cout << " Initialize aircraft at latitude " << c_out.lp .lam << " °, longitude " << c_out.lp .phi << " °, altitude " << altitude << " m (" << altitudeFt << " ft)" << std::endl;
192+ std::cout << " Initialize aircraft at latitude " << pos.y () << " °, longitude " << pos.x () << " °, altitude " << altitude << " m (" << altitudeFt << " ft)" << std::endl;
193+ IC ->SetLatitudeDegIC (pos.y ());
194+ IC ->SetLongitudeDegIC (pos.x ());
201195 IC ->SetAltitudeASLFtIC (altitudeFt);
202196 // there is also IC->SetAltitudeAGLFtIC(...), maybe we want that?
203197
@@ -312,16 +306,6 @@ bool JSBSimPlugin::initJSB()
312306 return true ;
313307}
314308
315- osg::Vec3f JSBSimPlugin::getOriginOffset () const
316- {
317- auto geoDataPlugin = coVRPluginList::instance ()->getPlugin (" GeoData" );
318- if (geoDataPlugin)
319- {
320- return (static_cast <GeoDataLoader *>(geoDataPlugin))->rootOffset ;
321- }
322- return osg::Vec3f ();
323- }
324-
325309void JSBSimPlugin::loadAvailableAircraft ()
326310{
327311 auto configFile = config ();
@@ -479,10 +463,6 @@ bool JSBSimPlugin::init()
479463 rd = " " ;
480464 RootDir = configString (" JSBSim" , " rootDir" , rd)->value ().c_str ();
481465
482- // Initialize the coordinate system
483- // TODO: move to a central geodata library
484- coordTransformation = proj_create_crs_to_crs (PJ_DEFAULT_CTX , " EPSG:4326" , " EPSG:25832" , NULL );
485-
486466 // Initialize menu
487467 JSBMenu = new ui::Menu (" JSBSim" , this );
488468
@@ -755,15 +735,10 @@ bool JSBSimPlugin::update()
755735 auto vehicleState = Propagate->GetVState ();
756736 auto location = vehicleState.vLocation ;
757737
758- PJ_COORD c;
759- c.lpz .lam = location.GetLatitudeDeg ();
760- c.lpz .phi = location.GetLongitudeDeg ();
761- c.lpz .z = location.GetGeodAltitude () * METERS_PER_FOOT ;
762- PJ_COORD c_out = proj_trans (coordTransformation, PJ_FWD , c);
738+ osg::Vec3 pos (location.GetLongitudeDeg (), location.GetLatitudeDeg (), location.GetGeodAltitude () * METERS_PER_FOOT );
763739
764740 float scale = cover->getScale ();
765- osg::Vec3 position (c_out.enu .e , c_out.enu .n , c_out.enu .u );
766- position += getOriginOffset ();
741+ auto position = GeoData::instance ()->globalToProject (pos);
767742 auto trans = osg::Matrix::translate (position * scale);
768743
769744 float heading = Propagate->GetEuler (JSBSim::FGJSBBase::ePsi);
0 commit comments