void PointerCoordinates::draw(StelCore *core) { if (!isEnabled()) return; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000, StelCore::RefractionAuto); StelPainter sPainter(prj); sPainter.setColor(textColor[0], textColor[1], textColor[2], 1.f); font.setPixelSize(getFontSize()); sPainter.setFont(font); QPoint p = QCursor::pos(); // get screen coordinates of mouse cursor Vec3d mousePosition; float wh = prj->getViewportWidth()/2; // get half of width of the screen float hh = prj->getViewportHeight()/2; // get half of height of the screen float mx = p.x()-wh; // point 0 in center of the screen, axis X directed to right float my = p.y()-hh; // point 0 in center of the screen, axis Y directed to bottom // calculate position of mouse cursor via position of center of the screen (and invert axis Y) prj->unProject(prj->getViewportPosX()+wh+mx, prj->getViewportPosY()+hh+1-my, mousePosition); double dec_j2000, ra_j2000; StelUtils::rectToSphe(&ra_j2000,&dec_j2000,mousePosition); // Calculate RA/DE (J2000.0) and show it... QString coordsText = QString("%1/%2").arg(StelUtils::radToHmsStr(ra_j2000, true)).arg(StelUtils::radToDmsStr(dec_j2000, true)); sPainter.drawText(getCoordinatesPlace(coordsText).first, getCoordinatesPlace(coordsText).second, coordsText); }
void PointerCoordinates::draw(StelCore *core) { if (!isEnabled()) return; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000, StelCore::RefractionAuto); StelPainter sPainter(prj); sPainter.setColor(textColor[0], textColor[1], textColor[2], 1.f); font.setPixelSize(getFontSize()); sPainter.setFont(font); QPoint p = StelMainView::getInstance().getMousePos(); // get screen coordinates of mouse cursor Vec3d mousePosition; float wh = prj->getViewportWidth()/2.; // get half of width of the screen float hh = prj->getViewportHeight()/2.; // get half of height of the screen float mx = p.x()-wh; // point 0 in center of the screen, axis X directed to right float my = p.y()-hh; // point 0 in center of the screen, axis Y directed to bottom // calculate position of mouse cursor via position of center of the screen (and invert axis Y) // If coordinates are invalid, don't draw them. bool coordsValid=false; coordsValid = prj->unProject(prj->getViewportPosX()+wh+mx, prj->getViewportPosY()+hh+1-my, mousePosition); { // Nick Fedoseev patch Vec3d win; prj->project(mousePosition,win); float dx = prj->getViewportPosX()+wh+mx - win.v[0]; float dy = prj->getViewportPosY()+hh+1-my - win.v[1]; coordsValid = prj->unProject(prj->getViewportPosX()+wh+mx+dx, prj->getViewportPosY()+hh+1-my+dy, mousePosition); } if (!coordsValid) return; bool withDecimalDegree = StelApp::getInstance().getFlagShowDecimalDegrees(); bool useSouthAzimuth = StelApp::getInstance().getFlagSouthAzimuthUsage(); QString coordsSystem, cxt, cyt; double cx, cy; switch (getCurrentCoordinateSystem()) { case RaDecJ2000: { StelUtils::rectToSphe(&cx,&cy,mousePosition); // Calculate RA/DE (J2000.0) and show it... coordsSystem = qc_("RA/Dec (J2000.0)", "abbreviated in the plugin"); if (withDecimalDegree) { cxt = StelUtils::radToDecDegStr(cx, 5, false, true); cyt = StelUtils::radToDecDegStr(cy); } else { cxt = StelUtils::radToHmsStr(cx, true); cyt = StelUtils::radToDmsStr(cy, true); } break; } case RaDec: { StelUtils::rectToSphe(&cx,&cy,core->j2000ToEquinoxEqu(mousePosition)); // Calculate RA/DE and show it... coordsSystem = qc_("RA/Dec", "abbreviated in the plugin"); if (withDecimalDegree) { cxt = StelUtils::radToDecDegStr(cx, 5, false, true); cyt = StelUtils::radToDecDegStr(cy); } else { cxt = StelUtils::radToHmsStr(cx, true); cyt = StelUtils::radToDmsStr(cy, true); } break; } case AltAzi: { StelUtils::rectToSphe(&cy,&cx,core->j2000ToAltAz(mousePosition, StelCore::RefractionAuto)); float direction = 3.; // N is zero, E is 90 degrees if (useSouthAzimuth) direction = 2.; cy = direction*M_PI - cy; if (cy > M_PI*2) cy -= M_PI*2; coordsSystem = qc_("Az/Alt", "abbreviated in the plugin"); if (withDecimalDegree) { cxt = StelUtils::radToDecDegStr(cy); cyt = StelUtils::radToDecDegStr(cx); } else { cxt = StelUtils::radToDmsStr(cy); cyt = StelUtils::radToDmsStr(cx); } break; } case Galactic: { StelUtils::rectToSphe(&cx,&cy,core->j2000ToGalactic(mousePosition)); // Calculate galactic position and show it... coordsSystem = qc_("Gal. Long/Lat", "abbreviated in the plugin"); if (withDecimalDegree) { cxt = StelUtils::radToDecDegStr(cx); cyt = StelUtils::radToDecDegStr(cy); } else { cxt = StelUtils::radToDmsStr(cx, true); cyt = StelUtils::radToDmsStr(cy, true); } break; } case Ecliptic: { double lambda, beta; StelUtils::rectToSphe(&cx,&cy,core->j2000ToEquinoxEqu(mousePosition)); StelUtils::equToEcl(cx, cy, core->getCurrentPlanet()->getRotObliquity(core->getJDE()), &lambda, &beta); // Calculate ecliptic position and show it... if (lambda<0) lambda+=2.0*M_PI; coordsSystem = qc_("Ecl. Long/Lat", "abbreviated in the plugin"); if (withDecimalDegree) { cxt = StelUtils::radToDecDegStr(lambda); cyt = StelUtils::radToDecDegStr(beta); } else { cxt = StelUtils::radToDmsStr(lambda, true); cyt = StelUtils::radToDmsStr(beta, true); } break; } case EclipticJ2000: { double lambda, beta; StelUtils::rectToSphe(&cx,&cy, mousePosition); StelUtils::equToEcl(cx, cy, core->getCurrentPlanet()->getRotObliquity(2451545.0), &lambda, &beta); // Calculate ecliptic position and show it... if (lambda<0) lambda+=2.0*M_PI; coordsSystem = qc_("Ecl. Long/Lat (J2000.0)", "abbreviated in the plugin"); if (withDecimalDegree) { cxt = StelUtils::radToDecDegStr(lambda); cyt = StelUtils::radToDecDegStr(beta); } else { cxt = StelUtils::radToDmsStr(lambda, true); cyt = StelUtils::radToDmsStr(beta, true); } break; } case HourAngle: { Vec3d v = core->j2000ToAltAz(mousePosition, StelCore::RefractionAuto); StelUtils::rectToSphe(&cx,&cy,Mat4d::zrotation(-core->getLocalSiderealTime())*core->altAzToEquinoxEqu(v, StelCore::RefractionOff)); cx = 2.*M_PI-cx; coordsSystem = qc_("HA/Dec", "abbreviated in the plugin"); if (withDecimalDegree) { double ha_sidereal = cx*12/M_PI; if (ha_sidereal>24.) ha_sidereal -= 24.; cxt = QString("%1h").arg(ha_sidereal, 0, 'f', 5); cyt = StelUtils::radToDecDegStr(cy); } else { cxt = StelUtils::radToHmsStr(cx); cyt = StelUtils::radToDmsStr(cy); } break; } } QString coordsText = QString("%1: %2/%3").arg(coordsSystem).arg(cxt).arg(cyt); sPainter.drawText(getCoordinatesPlace(coordsText).first, getCoordinatesPlace(coordsText).second, coordsText); }