OpenIG  2.0.4
cross-platform open-source OpenSceneGraph Image Generator
Mathematics.h
1 //#******************************************************************************
2 //#*
3 //#* Copyright (C) 2015 Compro Computer Services
4 //#* http://openig.compro.net
5 //#*
6 //#* Source available at: https://github.com/CCSI-CSSI/MuseOpenIG
7 //#*
8 //#* This software is released under the LGPL.
9 //#*
10 //#* This software is free software; you can redistribute it and/or modify
11 //#* it under the terms of the GNU Lesser General Public License as published
12 //#* by the Free Software Foundation; either version 2.1 of the License, or
13 //#* (at your option) any later version.
14 //#*
15 //#* This software is distributed in the hope that it will be useful,
16 //#* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 //#* the GNU Lesser General Public License for more details.
19 //#*
20 //#* You should have received a copy of the GNU Lesser General Public License
21 //#* along with this library; if not, write to the Free Software
22 //#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //#*
24 //#* Please direct any questions or comments to the OpenIG Forums
25 //#* Email address: openig@compro.net
26 //#*
27 //#*
28 //#* Please direct any questions or comments to the OpenIG Forums
29 //#* Email address: openig@compro.net
30 //#*
31 //#*
32 //#*****************************************************************************
33 #ifndef MATHEMATICS_H
34 #define MATHEMATICS_H
35 
36 #if defined(OPENIG_SDK)
37  #include <OpenIG-Base/Export.h>
38 #else
39  #include <Core-Base/Export.h>
40 #endif
41 
42 #include <osg/Vec3d>
43 #include <osg/Vec3>
44 #include <osg/Matrixd>
45 #include <osg/Quat>
46 #include <osg/CoordinateSystemNode>
47 
48 namespace OpenIG {
49  namespace Base {
50 
57  class IGCORE_EXPORT Math
58  {
59  protected:
60  Math() {}
61  ~Math() {}
62  public:
63 
71  static Math* instance();
72 
73  //Some constants from legacy Muse to ensure we match
74  static const float M_PER_FT; /* No. of meters in a linear foot */
75  static const float M_PER_NMI; /* No. of meters in a nautical mile */
76  static const float FT_PER_M; /* No. of feet in a meter */
77  static const float FT_PER_NMI; /* No. of feet in a nautical mile */
78 
92  osg::Matrixd toMatrix(double x, double y, double z, double h, double p, double r);
93 
107  osg::Matrixd toMuseMatrix(double x, double y, double z, double h, double p, double r);
122  osg::Matrixd toViewMatrix(double x, double y, double z, double h, double p, double r);
123 
134  osg::Quat toQuat(double h, double p, double r);
135 
149  osg::Matrixd toGeocentricCameraMatrix(double lat, double lon, double alt, double h, double p, double r);
150 
151 
165  void fromMatrix(const osg::Matrixd& mx, double& x, double& y, double& z, double& h, double& p, double& r);
166 
175  osg::Vec3d fromQuat(const osg::Quat& q);
176 
186  void fixVerticalAxis(osg::Vec3d& eye, osg::Quat& rotation, bool disallowFlipOver = true);
187 
188  protected:
197  osg::Vec3d getUpVector(const osg::CoordinateFrame& cf);
198 
208  void fixVerticalAxis(osg::Quat& rotation, const osg::Vec3d& localUp, bool disallowFlipOver = true);
209  };
210  } // namespace
211 } // namespace
212 
213 #endif // MATHEMATICS_H
Definition: ImageGenerator.h:62
The Math singleton class.
Definition: Mathematics.h:57