Skip to content

Commit f2c5b79

Browse files
Paul Bienkowskiopatut
authored andcommitted
JSBSim: use geodata for position transform
1 parent 1c40a5c commit f2c5b79

3 files changed

Lines changed: 10 additions & 40 deletions

File tree

src/OpenCOVER/plugins/hlrs/JSBSim/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ SET(SOURCES
1111
JSBSim.cpp
1212
VrmlNodeThermal.cpp
1313
)
14-
cover_add_plugin(JSBSim)
14+
cover_add_plugin(JSBSim coVRGeoData)
1515
#COVER_INSTALL_PLUGIN(JSBSim)

src/OpenCOVER/plugins/hlrs/JSBSim/JSBSim.cpp

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
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-
325309
void 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);

src/OpenCOVER/plugins/hlrs/JSBSim/JSBSim.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
#include <cover/ui/Label.h>
4545
#include <cover/ui/SelectionList.h>
4646

47-
#include <proj.h>
48-
4947
class UDPComm;
5048

5149
using JSBSim::Element;
@@ -127,8 +125,6 @@ class JSBSimPlugin : public coVRPlugin, public ui::Owner, public opencover::coVR
127125
void addThermal(const osg::Vec3 &velocity, float turbulence);
128126

129127
private:
130-
osg::Vec3f getOriginOffset() const;
131-
132128
void readJoystickConfiguration();
133129
void loadAvailableAircraft();
134130
void loadAircraft(const std::string &aircraftName);
@@ -243,7 +239,6 @@ class JSBSimPlugin : public coVRPlugin, public ui::Owner, public opencover::coVR
243239
virtual void key(int type, int keySym, int mod);
244240

245241
OpenThreads::Mutex mutex;
246-
PJ *coordTransformation;
247242

248243
osg::Matrix lastPos;
249244

0 commit comments

Comments
 (0)