#include "CompositeHandle.h" #include #include "CompositeWidgetManager.h" #include #define M_PI 3.14159265358979323846 /* mathematical constant pi */ ///Radian to degree conversion factor static const double RAD2DEG = 180.0 / M_PI; ///Degree to radian conversion factor static const double DEG2RAD = M_PI / 180.0; inline double angFix360(double in) { in -= 45.0; if ((in < 0.0) || (in >= 360.0)) { in = fmod(in, 360.0); if (in < 0.0) in += 360.0; } return in; } inline bool areEqual(double a, double b, double t = 1.0e-6) { return fabs(a - b) < t; } CompositeHandle::CompositeHandle(CompositeWidgetManager* cw) : _cw(cw), _operate(cw->GetcanvasO()), _N(cw->GetcanvasN()), _light(cw->GetcanvasFX()), _background(cw->GetcanvasBackGround()), _num(0), _move(false) { } bool CompositeHandle::handle(const osgGA::GUIEventAdapter&ea, osgGA::GUIActionAdapter& aa) { if (ea.getEventType() == osgGA::GUIEventAdapter::FRAME) { constexpr double TWO_DECIMAL_PLACES = 1e-02; double heading = 0.0; osgViewer::View* activeView = static_cast(aa.asView()); const osgEarth::Util::EarthManipulator* manip = dynamic_cast(activeView->getCameraManipulator()); if (manip != NULL) { manip->getCompositeEulerAngles(&heading); // Convert to degrees heading = angFix360(heading * RAD2DEG); } else { // Fall back to the viewpoint's heading heading = angFix360(manip->getViewpoint().heading()->as(osgEarth::Units::DEGREES)); } // make sure that anything equivalent to 0.00 is displayed as 0.00 if (areEqual(heading, 0.0, TWO_DECIMAL_PLACES) || areEqual(heading, 360.0, TWO_DECIMAL_PLACES)) { heading = 0.0; } if (!areEqual(_N->getRotate(), -heading, TWO_DECIMAL_PLACES)) { _N->setRotate(-heading); _N->update(); } } // compass_->update_(); return false; }