コード例 #1
0
ファイル: MapPage.cpp プロジェクト: jmc734/OpenEaagles
//------------------------------------------------------------------------------
// converts screen to lat/lon coordinates
//------------------------------------------------------------------------------
bool MapPage::screen2LatLon(const LCreal x, const LCreal y,
                              double* const lat, double* const lon) const
{
   bool ok = false;

   const double scale = getScale();
   const double cosLat = getCosRefLat();
   if (lat != nullptr && lon != nullptr && scale != 0 && cosLat != 0) {

      // buffer the inputs
      double screenX = x;
      double screenY = y;

      // Adjust for the decentered displayment
      if ( !getCentered() ) screenY -= getDisplacement();

      // Scale from screen (inches) to A/C (NM) and
      // transpose the X and Y from screen to A/C
      const double acX = screenY/scale;
      const double acY = screenX/scale;

      // Rotate A/C to NED
      double earthX = 0.0;
      double earthY = 0.0;
      if (getNorthUp()) {
         earthX = acX;
         earthY = acY;
      }
      else {
         earthX = (acX * headingCos) - (acY * headingSin);
         earthY = (acX * headingSin) + (acY * headingCos);
      }

      // Convert nautical miles (NED) from ref point to lat/lon
      *lat = (earthX/60.0) + getReferenceLatDeg();
      *lon = (earthY/(60.0*cosLat)) + getReferenceLonDeg();

      ok = true;
   }
   return ok;
}
コード例 #2
0
ファイル: MapPage.cpp プロジェクト: jmc734/OpenEaagles
//------------------------------------------------------------------------------
// converts lat/lon to screen coordinates
//------------------------------------------------------------------------------
bool MapPage::latLon2Screen(const double lat, const double lon,
                              LCreal* const x, LCreal* const y) const
{
   bool ok = false;
   if (x != nullptr && y != nullptr) {

      // Convert to nautical miles (NED) centered on ownship
      const double earthX = ((lat - getReferenceLatDeg()) * 60.0);
      const double earthY = ((lon - getReferenceLonDeg()) * 60.0 * getCosRefLat());

      // Rotate to aircraft coordinates
      double acX = 0;
      double acY = 0;
      if (getNorthUp()) {
         acX = earthX;
         acY = earthY;
      }
      else {
         acX =  (earthX * headingCos) + (earthY * headingSin);
         acY = -(earthX * headingSin) + (earthY * headingCos);
      }

      // Scale from nautical miles to inches and
      // transpose the X and Y from A/C to screen
      double screenY = acX * getScale();
      const double screenX = acY * getScale();

      // Adjust for the decentered displayment
      if ( !getCentered() ) screenY += getDisplacement();

      *x = static_cast<LCreal>(screenX);
      *y = static_cast<LCreal>(screenY);

      ok = true;
   }

   return ok;
}
コード例 #3
0
ファイル: MapDrawer.cpp プロジェクト: azcbuell/OpenEaagles
// -----------------------------------------------------------------------
// drawMap() - Called from draw fun, it tells our specific map to draw.
// -----------------------------------------------------------------------
void MapDrawer::drawMap(const int zone, const int idx)
{
    if (myMap != 0 && pagers[idx] != 0 && showMap && getDisplay() != 0){
        // Update the tiles for the pager
        pagers[idx]->updateTextures(textureRow[idx], textureCol[idx]);
        // Set up for drawing	     
        lcColor3(mapIntensity, mapIntensity, mapIntensity);
        glPushMatrix();
            // Not centered, move the whole map down the displacement value.
            if (!getCentered()) {
                LCreal dis = getOuterRadius();
                //LCreal scale = getScale();
                LCreal myScale = vpHL / dis;
                glTranslatef(0, GLfloat(getDisplacement() * myScale), 0);
            }
            glTranslatef(0, 0, -0.1f);
            sinAng = 0.0f;
            cosAng = 1.0f;

            // Set the scale, if not the CENTER_PAGER
            if (idx != CENTER_PAGER) determineScaling(idx);

            bool nu = getNorthUp();
            if (!nu) {
                GLfloat hdg = (GLfloat) getHeadingDeg();
                glRotatef(hdg, 0.0f, 0.0f, 1.0f);
                sinAng = (LCreal)lcSin(hdg * (LCreal)Basic::Angle::D2RCC);
                cosAng = (LCreal)lcCos(hdg * (LCreal)Basic::Angle::D2RCC);
            }

            // Translate down the pixels first
            float transPixelX =  -pixelCol[idx] * scalingEast[idx]; 
            float transPixelY =   pixelRow[idx] * scalingNorth[idx]; 

            // Translate to the next tile
            glTranslatef(transPixelX, transPixelY, 0.0f);
            TextureTable& tbl = pagers[idx]->getTable();
            int si = tbl.getLowerBoundIndex();

            int i1 = si;
            int i = 0;
            int lb = 0, ub = 0;

            // Enable texturing
            glEnable(GL_TEXTURE_2D);
            lb = tbl.getLowerBoundIndex();
            ub = tbl.getUpperBoundIndex();
            for (i = lb; i <= ub; i++) {
                int j1 = si;
                for (int j = lb; j <= ub; j++) {
                    drawTexture(i1, j1, idx);
                    j1++;
                }
                i1++;
            }
            glDisable(GL_TEXTURE_2D);

            // Done drawing tiles, now draw grid, if selected to draw.

            if (drawGrid) {
                i1 = si;
                for (i = lb; i <= ub; i++) {
                    int j1 = si;
                    for (int j = lb; j <= ub; j++) {
                        goDrawGrid(i1, j1, idx);
                        j1++;
                    }
                    i1++;
                }
            }
        glPopMatrix();
    }
}
コード例 #4
0
ファイル: InputDevice.hpp プロジェクト: LittleForker/sirikata
 AxisValue operator - () const {
     return fromCentered(-getCentered());
 }
コード例 #5
0
ファイル: SymbolLoader.cpp プロジェクト: azcbuell/OpenEaagles
//------------------------------------------------------------------------------
// draw() - draw the objects in their proper place
//------------------------------------------------------------------------------
void SymbolLoader::draw()
{
    if (isVisible()) {

        // Y Displacement (ie, decentered)
        LCreal displacement = 0;
        if (!getCentered()) displacement = getDisplacement();

        // Radius (ie., range)
        LCreal radius = 0;
        if (!getCentered()) radius = getOuterRadiusDC();
        else radius = getOuterRadius();
        LCreal radius2 = radius * radius;

        // ---
        // Setup the drawing parameters for all of our symbols ...
        // ---
        for (int i = 0; i < MAX_SYMBOLS; i++) {

            if (symbols[i] != 0) {

                // When the symbol visibility flag is true ...
                if (symbols[i]->isVisible()) {

                    // Get the pointer to the symbol's graphical component
                    Basic::Pair* p = symbols[i]->getSymbolPair();
                    BasicGL::Graphic* g = (BasicGL::Graphic*)p->object();

                    // We need the symbol's position in screen coordinates (inches) ...
                    LCreal xScn = (LCreal) symbols[i]->getScreenXPos();
                    LCreal yScn = (LCreal) symbols[i]->getScreenYPos();

                    if ( !(symbols[i]->isPositionScreen()) ) {

                        // But when we were not give screen coordinates,
                        // we'll need to compute them from A/C coordinates
                        LCreal acX = 0.0;
                        LCreal acY = 0.0;

                        // 1) when given A/C coordinates ...
                        if ( symbols[i]->isPositionAC() ) {
                            acX = (LCreal) symbols[i]->getXPosition();
                            acY = (LCreal) symbols[i]->getYPosition();
                        }

                        // 2) when given NED or L/L coordinates ..
                        else {
                            LCreal north = 0;
                            LCreal east  = 0;

                            if (symbols[i]->isPositionLL()) {
                                // 2a) we were give L/L so convert to NED coordinates
                                double lat = symbols[i]->getXPosition();
                                double lon = symbols[i]->getYPosition();
                                latLon2Earth(lat, lon, &north, &east);
                            }
                            else {
                                // 2b) we were give NED coordinates
                                north = (LCreal) symbols[i]->getXPosition();
                                east  = (LCreal) symbols[i]->getYPosition();
                            }

                            // 2c) convert the NED coordinates to aircraft coordinates
                            earth2Aircraft(north, east, &acX, &acY);
                        }

                        // 3) Convert the aircraft coordinates to screen coordinates
                        aircraft2Screen(acX, acY, &xScn, &yScn);

                        // 4) Save the screen coordinates (inches)
                        symbols[i]->setXScreenPos(xScn);
                        symbols[i]->setYScreenPos(yScn);
                    }

                    // In range?  Do we care?
                    bool inRange  = !showInRangeOnly || (((xScn * xScn) + (yScn * yScn)) <= radius2);

                    if (inRange) {

                        // set symbol's visibility
                        g->setVisibility(true);

                        // and set the symbol's position
                        g->lcSaveMatrix();
                        g->lcTranslate(xScn, yScn + displacement);

                        // pass the argument value to the symbol (if needed)
                        if (symbols[i]->getValue() != 0) {
                            g->event(UPDATE_VALUE, symbols[i]->getValue());
                        }

                        // rotate the symbol's heading subcomponent (if needed)
                        // -- sending a 'Z' rotation event to a component named 'hdg'
                        if (symbols[i]->isHeadingValid()) {
                            BasicGL::Graphic* phdg = symbols[i]->getHdgGraphics();
                            if (phdg == 0) {
                                Basic::Pair* hpair = (Basic::Pair*) g->findByName("hdg");
                                if (hpair != 0) {
                                    phdg = dynamic_cast<Graphic*>(hpair->object());
                                    symbols[i]->setHdgGraphics(phdg);
                                }
                            }
                            if (phdg != 0) {
                                Basic::Degrees* angObj = symbols[i]->getHdgAngleObj();
                                if (angObj == 0) {
                                    angObj = new Basic::Degrees();
                                    symbols[i]->setHdgAngleObj(angObj);
                                }
                                double relHeading = symbols[i]->getHeadingDeg() - getHeadingDeg();
                                angObj->set(-relHeading);
                                phdg->event(UPDATE_VALUE6, angObj);
                            }
                        }
                    }
                    else {
                        // out of range, so clear the graphical component's visibility flag
                        g->setVisibility(false);
                    }
                }

                // When the symbol visibility flag is false ...
                else {
                    Basic::Pair* p = symbols[i]->getSymbolPair();
                    BasicGL::Graphic* g = (BasicGL::Graphic*)p->object();
                    g->setVisibility(false);
                }
            }
        }

        // ---
        // Let our base class handle the drawing
        // ---
        BaseClass::draw();

        // ---
        // now restore the matrices on all of our graphical components
        // ---
        for (int i = 0; i < MAX_SYMBOLS; i++) {
            if (symbols[i] != 0) {
                Basic::Pair* p = symbols[i]->getSymbolPair();
                BasicGL::Graphic* g = (BasicGL::Graphic*)p->object();
                if (g->isVisible()) g->lcRestoreMatrix();
            }
        }

    }
}