本文整理汇总了C++中StelProjectorP::project方法的典型用法代码示例。如果您正苦于以下问题:C++ StelProjectorP::project方法的具体用法?C++ StelProjectorP::project怎么用?C++ StelProjectorP::project使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StelProjectorP
的用法示例。
在下文中一共展示了StelProjectorP::project方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleverFind
// Find an object in a "clever" way, v in J2000 frame
StelObjectP StelObjectMgr::cleverFind(const StelCore* core, const Vec3d& v) const
{
StelObjectP sobj;
QList<StelObjectP> candidates;
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
// Field of view for a searchRadiusPixel pixel diameter circle on screen
float fov_around = core->getMovementMgr()->getCurrentFov()/qMin(prj->getViewportWidth(), prj->getViewportHeight()) * searchRadiusPixel;
// Collect the objects inside the range
for (const auto* m : objectsModule)
candidates += m->searchAround(v, fov_around, core);
// GZ 2014-08-17: This should be exactly the sky's limit magnitude (or even more, but not less!), else visible stars cannot be clicked.
float limitMag = core->getSkyDrawer()->getLimitMagnitude(); // -2.f;
QList<StelObjectP> tmp;
for (const auto& obj : candidates)
{
if (obj->getSelectPriority(core)<=limitMag)
tmp.append(obj);
}
candidates = tmp;
// Now select the object minimizing the function y = distance(in pixel) + magnitude
Vec3d winpos;
prj->project(v, winpos);
float xpos = winpos[0];
float ypos = winpos[1];
float best_object_value;
best_object_value = 100000.f;
for (const auto& obj : candidates)
{
prj->project(obj->getJ2000EquatorialPos(core), winpos);
float distance = std::sqrt((xpos-winpos[0])*(xpos-winpos[0]) + (ypos-winpos[1])*(ypos-winpos[1]))*distanceWeight;
float priority = obj->getSelectPriority(core);
// qDebug() << (*iter).getShortInfoString(core) << ": " << priority << " " << distance;
if (distance + priority < best_object_value)
{
best_object_value = distance + priority;
sobj = obj;
}
}
return sobj;
}
示例2: drawPointer
void StarMgr::drawPointer(StelRenderer* renderer, StelProjectorP projector, const StelCore* core)
{
const QList<StelObjectP> newSelected = objectMgr->getSelectedObject("Star");
if (!newSelected.empty())
{
const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getJ2000EquatorialPos(core);
Vec3d win;
// Compute 2D pos and return if outside screen
if (!projector->project(pos, win))
{
return;
}
if(NULL == texPointer)
{
texPointer = renderer->createTexture("textures/pointeur2.png"); // Load pointer texture
}
Vec3f c(obj->getInfoColor());
if (StelApp::getInstance().getVisionModeNight())
c = StelUtils::getNightColor(c);
renderer->setGlobalColor(c[0], c[1], c[2]);
texPointer->bind();
renderer->setBlendMode(BlendMode_Alpha);
const float angle = StelApp::getInstance().getTotalRunTime() * 40.0f;
renderer->drawTexturedRect(win[0] - 13.0f, win[1] - 13.0f, 26.0f, 26.0f, angle);
}
}
示例3: drawPointer
void Supernovae::drawPointer(StelCore* core, StelRenderer* renderer, StelProjectorP projector)
{
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)->getSelectedObject("Supernova");
if (!newSelected.empty())
{
const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getJ2000EquatorialPos(core);
Vec3d screenpos;
// Compute 2D pos and return if outside screen
if (!projector->project(pos, screenpos))
{
return;
}
const Vec3f& c(obj->getInfoColor());
renderer->setGlobalColor(c[0],c[1],c[2]);
if(NULL == texPointer)
{
texPointer = renderer->createTexture("textures/pointeur2.png");
}
texPointer->bind();
renderer->setBlendMode(BlendMode_Alpha);
renderer->drawTexturedRect(screenpos[0] - 13.0f, screenpos[1] - 13.0f, 26.0f, 26.0f,
StelApp::getInstance().getTotalRunTime() * 40.0f);
}
}
示例4: draw
//! Draw any parts on the screen which are for our module
void AngleMeasure::draw(StelCore* core)
{
if (lineVisible.getInterstate() < 0.000001f && messageFader.getInterstate() < 0.000001f)
return;
const StelProjectorP prj = core->getProjection(StelCore::FrameEquinoxEqu);
StelPainter painter(prj);
painter.setFont(font);
if (lineVisible.getInterstate() > 0.000001f)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
Vec3d xy;
QString displayedText;
if (prj->project(perp1EndPoint,xy))
{
painter.setColor(textColor[0], textColor[1], textColor[2], lineVisible.getInterstate());
if (flagShowPA)
displayedText = QString("%1 (%2%3)").arg(calculateAngle(), messagePA, calculatePositionAngle(startPoint, endPoint));
else
displayedText = calculateAngle();
painter.drawText(xy[0], xy[1], displayedText, 0, 15, 15);
}
glDisable(GL_TEXTURE_2D);
// OpenGL ES 2.0 doesn't have GL_LINE_SMOOTH
// glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
// main line is a great circle
painter.setColor(lineColor[0], lineColor[1], lineColor[2], lineVisible.getInterstate());
painter.drawGreatCircleArc(startPoint, endPoint, NULL);
// End lines
painter.drawGreatCircleArc(perp1StartPoint, perp1EndPoint, NULL);
painter.drawGreatCircleArc(perp2StartPoint, perp2EndPoint, NULL);
}
if (messageFader.getInterstate() > 0.000001f)
{
painter.setColor(textColor[0], textColor[1], textColor[2], messageFader.getInterstate());
int x = 83;
int y = 120;
int ls = painter.getFontMetrics().lineSpacing();
painter.drawText(x, y, messageEnabled);
y -= ls;
painter.drawText(x, y, messageLeftButton);
y -= ls;
painter.drawText(x, y, messageRightButton);
}
}
示例5: draw
void Quasar::draw(StelCore* core, StelRenderer* renderer, StelProjectorP projector, StelTextureNew* markerTexture)
{
StelSkyDrawer* sd = core->getSkyDrawer();
const Vec3f color = sd->indexToColor(BvToColorIndex(bV))*0.75f;
Vec3f dcolor = Vec3f(1.2f,0.5f,0.4f);
if (StelApp::getInstance().getVisionModeNight())
dcolor = StelUtils::getNightColor(dcolor);
float rcMag[2], size, shift;
double mag;
StelUtils::spheToRect(qRA, qDE, XYZ);
mag = getVMagnitude(core, true);
if (GETSTELMODULE(Quasars)->getDisplayMode())
{
renderer->setBlendMode(BlendMode_Add);
renderer->setGlobalColor(dcolor[0], dcolor[1], dcolor[2], 1);
markerTexture->bind();
if (labelsFader.getInterstate()<=0.f)
{
Vec3d win;
if(projector->project(XYZ, win))
{
renderer->drawTexturedRect(win[0] - 4, win[1] - 4, 8, 8);
}
}
}
else
{
sd->preDrawPointSource();
if (mag <= sd->getLimitMagnitude())
{
sd->computeRCMag(mag, rcMag);
const Vec3f XYZf(XYZ[0], XYZ[1], XYZ[2]);
Vec3f win;
if(sd->pointSourceVisible(&(*projector), XYZf, rcMag, false, win))
{
sd->drawPointSource(win, rcMag, sd->indexToColor(BvToColorIndex(bV)));
}
renderer->setGlobalColor(color[0], color[1], color[2], 1.0f);
size = getAngularSize(NULL)*M_PI/180.*projector->getPixelPerRadAtCenter();
shift = 6.f + size/1.8f;
if (labelsFader.getInterstate()<=0.f)
{
renderer->drawText(TextParams(XYZ, projector, designation).shift(shift, shift).useGravity());
}
}
sd->postDrawPointSource(projector);
}
}
示例6: draw
//! Draw any parts on the screen which are for our module
void CompassMarks::draw(StelCore* core)
{
if (markFader.getInterstate() <= 0.0) { return; }
Vec3d pos, screenPos;
StelProjectorP prj = core->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
StelPainter painter(prj);
painter.setFont(font);
int f = 0;
if (StelApp::getInstance().getFlagSouthAzimuthUsage())
f = 180;
painter.setColor(markColor[0], markColor[1], markColor[2], markFader.getInterstate());
painter.setBlending(true);
painter.setLineSmooth(true);
for(int i=0; i<360; i++)
{
float a = i*M_PI/180;
pos.set(sin(a),cos(a), 0.f);
float h = -0.002;
if (i % 15 == 0)
{
h = -0.02; // the size of the mark every 15 degrees
QString s = QString("%1").arg((i+90+f)%360);
float shiftx = painter.getFontMetrics().width(s) / 2.;
float shifty = painter.getFontMetrics().height() / 2.;
painter.drawText(pos, s, 0, -shiftx, shifty);
}
else if (i % 5 == 0)
{
h = -0.01; // the size of the mark every 5 degrees
}
// Limit arcs to those that are visible for improved performance
if (prj->project(pos, screenPos) &&
screenPos[0]>prj->getViewportPosX() && screenPos[0] < prj->getViewportPosX() + prj->getViewportWidth()) {
painter.drawGreatCircleArc(pos, Vec3d(pos[0], pos[1], h), Q_NULLPTR);
}
}
painter.setBlending(false);
painter.setLineSmooth(false);
}
示例7: handleMouseMoves
bool AngleMeasure::handleMouseMoves(int x, int y, Qt::MouseButtons)
{
if (dragging)
{
const StelProjectorP prj = StelApp::getInstance().getCore()->getProjection(StelCore::FrameEquinoxEqu);
prj->unProject(x,y,endPoint);
{ // Nick Fedoseev patch: improve click match
Vec3d win;
prj->project(endPoint,win);
float dx = x - win.v[0];
float dy = y - win.v[1];
prj->unProject(x+dx, y+dy, endPoint);
}
const StelProjectorP prjHor = StelApp::getInstance().getCore()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
prjHor->unProject(x,y,endPointHor);
calculateEnds();
lineVisible = true;
return true;
}
else
return false;
}
示例8: handleMouseClicks
void AngleMeasure::handleMouseClicks(class QMouseEvent* event)
{
if (!flagShowAngleMeasure)
{
event->setAccepted(false);
return;
}
if (event->type()==QEvent::MouseButtonPress && event->button()==Qt::LeftButton)
{
const StelProjectorP prj = StelApp::getInstance().getCore()->getProjection(StelCore::FrameEquinoxEqu);
prj->unProject(event->x(),event->y(),startPoint);
{ // Nick Fedoseev patch: improve click match
Vec3d win;
prj->project(startPoint,win);
float dx = event->x() - win.v[0];
float dy = event->y() - win.v[1];
prj->unProject(event->x()+dx, event->y()+dy, startPoint);
}
const StelProjectorP prjHor = StelApp::getInstance().getCore()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
prjHor->unProject(event->x(),event->y(),startPointHor);
// first click reset the line... only draw it after we've dragged a little.
if (!dragging)
{
lineVisible = false;
endPoint = startPoint;
endPointHor=startPointHor;
}
else
lineVisible = true;
dragging = true;
calculateEnds();
event->setAccepted(true);
return;
}
else if (event->type()==QEvent::MouseButtonRelease && event->button()==Qt::LeftButton)
{
dragging = false;
calculateEnds();
event->setAccepted(true);
return;
}
else if (event->type()==QEvent::MouseButtonPress && event->button()==Qt::RightButton)
{
const StelProjectorP prj = StelApp::getInstance().getCore()->getProjection(StelCore::FrameEquinoxEqu);
prj->unProject(event->x(),event->y(),endPoint);
{ // Nick Fedoseev patch: improve click match
Vec3d win;
prj->project(endPoint,win);
float dx = event->x() - win.v[0];
float dy = event->y() - win.v[1];
prj->unProject(event->x()+dx, event->y()+dy, endPoint);
}
const StelProjectorP prjHor = StelApp::getInstance().getCore()->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
prjHor->unProject(event->x(),event->y(),endPointHor);
calculateEnds();
event->setAccepted(true);
return;
}
event->setAccepted(false);
}
示例9: drawOne
void AngleMeasure::drawOne(StelCore *core, const StelCore::FrameType frameType, const StelCore::RefractionMode refractionMode, const Vec3f txtColor, const Vec3f lineColor)
{
const StelProjectorP prj = core->getProjection(frameType, refractionMode);
StelPainter painter(prj);
painter.setFont(font);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
if (lineVisible.getInterstate() > 0.000001f)
{
Vec3d xy;
QString displayedText;
if (frameType==StelCore::FrameEquinoxEqu)
{
if (prj->project(perp1EndPoint,xy))
{
painter.setColor(txtColor[0], txtColor[1], txtColor[2], lineVisible.getInterstate());
if (flagShowPA)
displayedText = QString("%1 (%2%3)").arg(calculateAngle(), messagePA, calculatePositionAngle(startPoint, endPoint));
else
displayedText = calculateAngle();
painter.drawText(xy[0], xy[1], displayedText, 0, 15, 15);
}
}
else
{
if (prj->project(perp1EndPointHor,xy))
{
painter.setColor(txtColor[0], txtColor[1], txtColor[2], lineVisible.getInterstate());
if (flagShowHorizontalPA)
displayedText = QString("%1 (%2%3)").arg(calculateAngle(true), messagePA, calculatePositionAngle(startPointHor, endPointHor));
else
displayedText = calculateAngle(true);
painter.drawText(xy[0], xy[1], displayedText, 0, 15, -5);
}
}
glDisable(GL_TEXTURE_2D);
// OpenGL ES 2.0 doesn't have GL_LINE_SMOOTH. But it looks much better.
#ifdef GL_LINE_SMOOTH
if (QOpenGLContext::currentContext()->format().renderableType()==QSurfaceFormat::OpenGL)
glEnable(GL_LINE_SMOOTH);
#endif
// main line is a great circle
painter.setColor(lineColor[0], lineColor[1], lineColor[2], lineVisible.getInterstate());
if (frameType==StelCore::FrameEquinoxEqu)
{
painter.drawGreatCircleArc(startPoint, endPoint, NULL);
// End lines
painter.drawGreatCircleArc(perp1StartPoint, perp1EndPoint, NULL);
painter.drawGreatCircleArc(perp2StartPoint, perp2EndPoint, NULL);
}
else
{
painter.drawGreatCircleArc(startPointHor, endPointHor, NULL);
// End lines
painter.drawGreatCircleArc(perp1StartPointHor, perp1EndPointHor, NULL);
painter.drawGreatCircleArc(perp2StartPointHor, perp2EndPointHor, NULL);
}
#ifdef GL_LINE_SMOOTH
if (QOpenGLContext::currentContext()->format().renderableType()==QSurfaceFormat::OpenGL)
glDisable(GL_LINE_SMOOTH);
#endif
}
if (messageFader.getInterstate() > 0.000001f)
{
painter.setColor(txtColor[0], txtColor[1], txtColor[2], messageFader.getInterstate());
int x = 83;
int y = 120;
int ls = painter.getFontMetrics().lineSpacing();
painter.drawText(x, y, messageEnabled);
y -= ls;
painter.drawText(x, y, messageLeftButton);
y -= ls;
painter.drawText(x, y, messageRightButton);
}
glDisable(GL_BLEND);
}
示例10: draw
bool SkyLabel::draw(StelCore* core, StelRenderer* renderer, StelProjectorP projector)
{
if(labelFader.getInterstate() <= 0.0)
return false;
Vec3d objectPos = labelObject->getJ2000EquatorialPos(core);
Vec3d labelXY;
projector->project(objectPos, labelXY);
renderer->setFont(labelFont);
double xOffset(0.);
double yOffset(0.);
char hJustify = 'c';
char vJustify = 'c';
if (labelSide.toUpper().contains("N"))
{
yOffset = 1.0;
vJustify = 'b'; // bottom justify text
}
else if (labelSide.toUpper().contains("S"))
{
yOffset = -1.0;
vJustify = 't'; // top justufy text
}
if (labelSide.toUpper().contains("E"))
{
xOffset = 1.0;
hJustify = 'l'; // right justify text
}
else if (labelSide.toUpper().contains("W"))
{
xOffset = -1.0;
hJustify = 'r'; // left justify text
}
if (labelDistance >= 0.0)
{
xOffset *= labelDistance;
yOffset *= labelDistance;
}
else
{
float shift = 4.0f + labelObject->getAngularSize(core) * M_PI / 180.0f *
projector->getPixelPerRadAtCenter() / 1.8f;
// use the object size
xOffset *= shift;
yOffset *= shift;
}
QFontMetrics fontMetrics(labelFont);
const float jxOffset = hJustify == 'r' ? fontMetrics.width(labelText) :
hJustify == 'c' ? fontMetrics.width(labelText) * 0.5 :
0.0;
const float jyOffset = vJustify == 't' ? fontMetrics.height() :
vJustify == 'c' ? fontMetrics.height() * 0.5 :
0.0;
renderer->setGlobalColor(labelColor[0], labelColor[1],
labelColor[2], labelFader.getInterstate());
renderer->drawText(TextParams(labelXY[0] + xOffset - jxOffset,
labelXY[1] + yOffset - jyOffset,
labelText).useGravity());
if (labelStyle == SkyLabel::Line)
{
renderer->setBlendMode(BlendMode_Alpha);
// screen coordinates of object
Vec3d objXY;
projector->project(objectPos, objXY);
double lineEndX = labelXY[0]+xOffset;
double lineEndY = labelXY[1]+yOffset;
if (vJustify == 'b')
lineEndY -= 5;
else if (vJustify == 't')
lineEndY += 5;
if (hJustify == 'l')
lineEndX -= 5;
else if (hJustify == 'r')
lineEndX += 5;
renderer->setGlobalColor(labelColor[0], labelColor[1], labelColor[2],
labelFader.getInterstate());
renderer->drawLine(lineEndX,lineEndY,objXY[0], objXY[1]);
}
return true;
}
示例11: draw
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);
//.........这里部分代码省略.........
示例12: draw
//! Draw the sky grid in the current frame
void SkyGrid::draw(const StelCore* core) const
{
const StelProjectorP prj = core->getProjection(frameType, frameType!=StelCore::FrameAltAz ? StelCore::RefractionAuto : StelCore::RefractionOff);
if (!fader.getInterstate())
return;
bool withDecimalDegree = dynamic_cast<StelGui*>(StelApp::getInstance().getGui())->getFlagShowDecimalDegrees();
// Look for all meridians and parallels intersecting with the disk bounding the viewport
// Check whether the pole are in the viewport
bool northPoleInViewport = false;
bool southPoleInViewport = false;
Vec3f win;
if (prj->project(Vec3f(0,0,1), win) && prj->checkInViewport(win))
northPoleInViewport = true;
if (prj->project(Vec3f(0,0,-1), win) && prj->checkInViewport(win))
southPoleInViewport = true;
// Get the longitude and latitude resolution at the center of the viewport
Vec3d centerV;
prj->unProject(prj->getViewportPosX()+prj->getViewportWidth()/2, prj->getViewportPosY()+prj->getViewportHeight()/2+1, centerV);
double lon2, lat2;
StelUtils::rectToSphe(&lon2, &lat2, centerV);
const double gridStepParallelRad = M_PI/180.*getClosestResolutionDMS(prj->getPixelPerRadAtCenter());
double gridStepMeridianRad;
if (northPoleInViewport || southPoleInViewport)
gridStepMeridianRad = (frameType==StelCore::FrameAltAz || frameType==StelCore::FrameGalactic) ? M_PI/180.* 10. : M_PI/180.* 15.;
else
{
const double closetResLon = (frameType==StelCore::FrameAltAz || frameType==StelCore::FrameGalactic) ? getClosestResolutionDMS(prj->getPixelPerRadAtCenter()*std::cos(lat2)) : getClosestResolutionHMS(prj->getPixelPerRadAtCenter()*std::cos(lat2));
gridStepMeridianRad = M_PI/180.* ((northPoleInViewport || southPoleInViewport) ? 15. : closetResLon);
}
// Get the bounding halfspace
const SphericalCap& viewPortSphericalCap = prj->getBoundingCap();
// Compute the first grid starting point. This point is close to the center of the screen
// and lays at the intersection of a meridien and a parallel
lon2 = gridStepMeridianRad*((int)(lon2/gridStepMeridianRad+0.5));
lat2 = gridStepParallelRad*((int)(lat2/gridStepParallelRad+0.5));
Vec3d firstPoint;
StelUtils::spheToRect(lon2, lat2, firstPoint);
firstPoint.normalize();
// Q_ASSERT(viewPortSphericalCap.contains(firstPoint));
// Initialize a painter and set openGL state
StelPainter sPainter(prj);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
Vec4f textColor(color[0], color[1], color[2], 0);
sPainter.setColor(color[0],color[1],color[2], fader.getInterstate());
textColor*=2;
textColor[3]=fader.getInterstate();
sPainter.setFont(font);
ViewportEdgeIntersectCallbackData userData(&sPainter);
userData.textColor = textColor;
userData.frameType = frameType;
/////////////////////////////////////////////////
// Draw all the meridians (great circles)
SphericalCap meridianSphericalCap(Vec3d(1,0,0), 0);
Mat4d rotLon = Mat4d::zrotation(gridStepMeridianRad);
Vec3d fpt = firstPoint;
Vec3d p1, p2;
int maxNbIter = (int)(M_PI/gridStepMeridianRad);
int i;
for (i=0; i<maxNbIter; ++i)
{
StelUtils::rectToSphe(&lon2, &lat2, fpt);
userData.raAngle = lon2;
meridianSphericalCap.n = fpt^Vec3d(0,0,1);
meridianSphericalCap.n.normalize();
if (!SphericalCap::intersectionPoints(viewPortSphericalCap, meridianSphericalCap, p1, p2))
{
if (viewPortSphericalCap.d<meridianSphericalCap.d && viewPortSphericalCap.contains(meridianSphericalCap.n))
{
// The meridian is fully included in the viewport, draw it in 3 sub-arcs to avoid length > 180.
const Mat4d& rotLon120 = Mat4d::rotation(meridianSphericalCap.n, 120.*M_PI/180.);
Vec3d rotFpt=fpt;
rotFpt.transfo4d(rotLon120);
Vec3d rotFpt2=rotFpt;
rotFpt2.transfo4d(rotLon120);
sPainter.drawGreatCircleArc(fpt, rotFpt, NULL, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt, rotFpt2, NULL, viewportEdgeIntersectCallback, &userData);
sPainter.drawGreatCircleArc(rotFpt2, fpt, NULL, viewportEdgeIntersectCallback, &userData);
fpt.transfo4d(rotLon);
continue;
}
else
break;
}
Vec3d middlePoint = p1+p2;
middlePoint.normalize();
if (!viewPortSphericalCap.contains(middlePoint))
//.........这里部分代码省略.........
示例13: draw
// returns true if visible
// Assumes that we are in local frame
void Meteor::draw(const StelCore* core, StelPainter& sPainter)
{
if (!alive)
return;
const StelProjectorP proj = sPainter.getProjector();
Vec3d spos = position;
Vec3d epos = posTrain;
// convert to equ
spos.transfo4d(mmat);
epos.transfo4d(mmat);
// convert to local and correct for earth radius [since equ and local coordinates in stellarium use same 0 point!]
spos = core->equinoxEquToAltAz( spos );
epos = core->equinoxEquToAltAz( epos );
spos[2] -= EARTH_RADIUS;
epos[2] -= EARTH_RADIUS;
// 1216 is to scale down under 1 for desktop version
spos/=1216;
epos/=1216;
// qDebug("[%f %f %f] (%d, %d) (%d, %d)\n", position[0], position[1], position[2], (int)start[0], (int)start[1], (int)end[0], (int)end[1]);
if (train)
{
// connect this point with last drawn point
double tmag = mag*distMultiplier;
// compute an intermediate point so can curve slightly along projection distortions
Vec3d posi = posInternal;
posi[2] = position[2] + (posTrain[2] - position[2])/2;
posi.transfo4d(mmat);
posi = core->equinoxEquToAltAz( posi );
posi[2] -= EARTH_RADIUS;
posi/=1216;
// draw dark to light
Vec4f colorArray[3];
colorArray[0].set(0,0,0,0);
colorArray[1].set(1,1,1,tmag*0.5);
colorArray[2].set(1,1,1,tmag);
Vec3d vertexArray[3];
vertexArray[0]=epos;
vertexArray[1]=posi;
vertexArray[2]=spos;
sPainter.setColorPointer(4, GL_FLOAT, colorArray);
sPainter.setVertexPointer(3, GL_DOUBLE, vertexArray);
// TODO the crash doesn't appear when the last true is set to false
sPainter.enableClientStates(true, false, true);
sPainter.drawFromArray(StelPainter::LineStrip, 3, 0, true);
sPainter.enableClientStates(false);
}
else
{
sPainter.setPointSize(1.f);
Vec3d start;
proj->project(spos, start);
sPainter.drawPoint2d(start[0],start[1]);
}
train = 1;
}
示例14: drawText
void StelQGLRenderer::drawText(const TextParams& params)
{
statistics[TEXT_DRAWS] += 1.0;
StelQGLTextureBackend* currentTexture = currentlyBoundTextures[0];
if(params.string_.length() == 0)
{
return;
}
viewport.enablePainting();
if(currentFontSet)
{
viewport.setFont(currentFont);
}
QPainter* painter = viewport.getPainter();
Q_ASSERT_X(NULL != painter, Q_FUNC_INFO,
"Trying to draw text but painting is disabled");
QFontMetrics fontMetrics = painter->fontMetrics();
StelProjectorP projector = NULL == params.projector_
? StelApp::getInstance().getCore()->getProjection2d()
: params.projector_;
Vec3f win;
if(params.doNotProject_)
{
win = params.position_;
}
else if(!projector->project(params.position_, win))
{
viewport.disablePainting();
return;
}
const int x = win[0];
const int y = win[1];
// Avoid drawing if outside viewport.
// We do a worst-case approximation as getting exact text dimensions is expensive.
// We also account for rotation by assuming the worst case in bot X and Y
// (culling with a rotating rectangle would be expensive)
const int cullDistance =
std::max(fontMetrics.height(), params.string_.size() * fontMetrics.maxWidth());
const Vec4i viewXywh = projector->getViewportXywh();
const int viewMinX = viewXywh[0];
const int viewMinY = viewXywh[1];
const int viewMaxX = viewMinX + viewXywh[2];
const int viewMaxY = viewMinY + viewXywh[3];
if(y + cullDistance < viewMinY || y - cullDistance > viewMaxY ||
x + cullDistance < viewMinX || x - cullDistance > viewMaxX)
{
viewport.disablePainting();
return;
}
if(projector->useGravityLabels() && !params.noGravity_)
{
drawTextGravityHelper(params, *painter, x, y, projector);
return;
}
const int pixelSize = painter->font().pixelSize();
// Strings drawn by drawText() can differ by text, font size, or the font itself.
const QByteArray hash = params.string_.toUtf8() + QByteArray::number(pixelSize) +
painter->font().family().toUtf8();
StelQGLTextureBackend* textTexture = textTextureCache.object(hash);
// No texture in cache for this string, need to draw it.
if (NULL == textTexture)
{
const QRect extents = fontMetrics.boundingRect(params.string_);
// Width and height of the text.
// Texture width/height is required to be at least equal to this.
//
// Both X and Y need to be at least 1 so we don't create an empty image
// (doesn't work with textures)
const int requiredWidth = std::max(1, extents.width() + 1 + static_cast<int>(0.02f * extents.width()));
const int requiredHeight = std::max(1, extents.height());
// Create temporary image and render text into it
// QImage is used solely to reuse existing QGLTextureBackend constructor
// function. QPixmap could be used as well (not sure which is faster,
// needs profiling)
QImage image = areNonPowerOfTwoTexturesSupported()
? QImage(requiredWidth, requiredHeight, QImage::Format_ARGB32_Premultiplied)
: QImage(StelUtils::smallestPowerOfTwoGreaterOrEqualTo(requiredWidth),
StelUtils::smallestPowerOfTwoGreaterOrEqualTo(requiredHeight),
QImage::Format_ARGB32);
image.fill(Qt::transparent);
QPainter fontPainter(&image);
fontPainter.setFont(painter->font());
fontPainter.setRenderHints(QPainter::TextAntialiasing, true);
fontPainter.setPen(Qt::white);
// The second argument ensures the text is positioned correctly even if
// the image is enlarged to power-of-two.
//.........这里部分代码省略.........
示例15: draw
// Draw the Comet and all the related infos : name, circle etc... GZ: Taken from Planet.cpp 2013-11-05 and extended
void Comet::draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont)
{
if (hidden)
return;
if (getEnglishName() == core->getCurrentLocation().planetName)
{ // GZ moved this up. Maybe even don't do that? E.g., draw tail while riding the comet? Decide later.
return;
}
// The CometOrbit is in fact available in userDataPtr!
CometOrbit* orbit=(CometOrbit*)userDataPtr;
Q_ASSERT(orbit);
if (!orbit->objectDateValid(core->getJDay())) return; // out of useful date range. This allows having hundreds of comet elements.
if (orbit->getUpdateTails()){
// Compute lengths and orientations from orbit object, but only if required.
// TODO: This part should possibly be moved to another thread to keep draw() free from too much computation.
Vec2f tailFactors=getComaDiameterAndTailLengthAU();
float gasTailEndRadius=qMax(tailFactors[0], 0.025f*tailFactors[1]) ; // This avoids too slim gas tails for bright comets like Hale-Bopp.
float gasparameter=gasTailEndRadius*gasTailEndRadius/(2.0f*tailFactors[1]); // parabola formula: z=r²/2p, so p=r²/2z
// The dust tail is thicker and usually shorter. The factors can be configured in the elements.
float dustparameter=gasTailEndRadius*gasTailEndRadius*dustTailWidthFactor*dustTailWidthFactor/(2.0f*dustTailLengthFactor*tailFactors[1]);
// Find valid parameters to create paraboloid vertex arrays: dustTail, gasTail.
computeParabola(gasparameter, gasTailEndRadius, -0.5f*gasparameter, gastailVertexArr, gastailTexCoordArr, gastailIndices);
// This was for a rotated straight parabola:
//computeParabola(dustparameter, 2.0f*tailFactors[0], -0.5f*dustparameter, dusttailVertexArr, dusttailTexCoordArr, dusttailIndices);
// Now we make a skewed parabola. Skew factor 15 (last arg) ad-hoc/empirical. TBD later: Find physically correct solution.
computeParabola(dustparameter, dustTailWidthFactor*gasTailEndRadius, -0.5f*dustparameter, dusttailVertexArr, gastailTexCoordArr, gastailIndices, 25.0f*orbit->getVelocity().length());
// Note that we use a diameter larger than what the formula returns. A scale factor of 1.2 is ad-hoc/empirical (GZ), but may look better.
computeComa(1.0f*tailFactors[0]);
orbit->setUpdateTails(false); // don't update until position has been recalculated elsewhere
}
Mat4d mat = Mat4d::translation(eclipticPos) * rotLocalToParent;
/* // We can remove that - a Comet has no parent except for the sun...
PlanetP p = parent;
while (p && p->parent)
{
mat = Mat4d::translation(p->eclipticPos) * mat * p->rotLocalToParent;
p = p->parent;
}
*/
// This removed totally the Planet shaking bug!!!
StelProjector::ModelViewTranformP transfo = core->getHeliocentricEclipticModelViewTransform();
transfo->combine(mat);
// Compute the 2D position and check if in the screen
const StelProjectorP prj = core->getProjection(transfo);
float screenSz = getAngularSize(core)*M_PI/180.*prj->getPixelPerRadAtCenter();
float viewport_left = prj->getViewportPosX();
float viewport_bottom = prj->getViewportPosY();
if (prj->project(Vec3d(0), screenPos)
&& screenPos[1]>viewport_bottom - screenSz && screenPos[1] < viewport_bottom + prj->getViewportHeight()+screenSz
&& screenPos[0]>viewport_left - screenSz && screenPos[0] < viewport_left + prj->getViewportWidth() + screenSz)
{
// Draw the name, and the circle if it's not too close from the body it's turning around
// this prevents name overlapping (ie for jupiter satellites)
float ang_dist = 300.f*atan(getEclipticPos().length()/getEquinoxEquatorialPos(core).length())/core->getMovementMgr()->getCurrentFov();
// if (ang_dist==0.f) ang_dist = 1.f; // if ang_dist == 0, the Planet is sun.. --> GZ: we can remove it.
// by putting here, only draw orbit if Comet is visible for clarity
drawOrbit(core); // TODO - fade in here also...
if (flagLabels && ang_dist>0.25 && maxMagLabels>getVMagnitude(core))
{
labelsFader=true;
}
else
{
labelsFader=false;
}
drawHints(core, planetNameFont);
draw3dModel(core,transfo,screenSz);
}
// tails should also be drawn if core is off-screen...
drawTail(core,transfo,true); // gas tail
drawTail(core,transfo,false); // dust tail
//Coma: this is just a fan disk tilted towards the observer;-)
drawComa(core, transfo);
return;
}