本文整理汇总了C++中StelProjectorP::getViewportPosX方法的典型用法代码示例。如果您正苦于以下问题:C++ StelProjectorP::getViewportPosX方法的具体用法?C++ StelProjectorP::getViewportPosX怎么用?C++ StelProjectorP::getViewportPosX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StelProjectorP
的用法示例。
在下文中一共展示了StelProjectorP::getViewportPosX方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 = 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);
}
示例2: 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);
}
示例3: 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);
//.........这里部分代码省略.........
示例4: 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))
//.........这里部分代码省略.........
示例5: 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;
}
示例6: updateGrid
void Atmosphere::updateGrid(const StelProjectorP projector)
{
viewport = projector->getViewport();
const float viewportWidth = projector->getViewportWidth();
const float viewportHeight = projector->getViewportHeight();
const float aspectRatio = viewportWidth / viewportHeight;
skyResolutionY = StelApp::getInstance()
.getSettings()
->value("landscape/atmosphereybin", 44)
.toInt();
const float resolutionX = skyResolutionY * 0.5 * sqrt(3.0) * aspectRatio;
skyResolutionX = static_cast<int>(floor(0.5 + resolutionX));
const float stepX = viewportWidth / (skyResolutionX - 0.5);
const float stepY = viewportHeight / skyResolutionY;
const float viewportLeft = projector->getViewportPosX();
const float viewportBottom = projector->getViewportPosY();
vertexGrid->unlock();
vertexGrid->clear();
// Construct the vertex grid.
for(int y = 0; y <= skyResolutionY; ++y)
{
const float yPos = viewportBottom + y * stepY;
for (int x = 0; x <= skyResolutionX; ++x)
{
const float offset = (x == 0) ? 0.0f :
(x == skyResolutionX) ? viewportWidth
: (x - 0.5 * (y & 1)) * stepX;
const float xPos = viewportLeft + offset;
vertexGrid->addVertex(Vertex(Vec2f(xPos, yPos), Vec4f()));
}
}
vertexGrid->lock();
// The grid is (resolutionX + 1) * (resolutionY + 1),
// so the rows are for 0 to resolutionY-1
// The last row includes vertices in row resolutionY
// Construct an index buffer for each row in the grid.
for(int row = 0; row < skyResolutionY; ++row)
{
StelIndexBuffer* buffer;
// Reuse previously used row index buffer.
if(rowIndices.size() > row)
{
buffer = rowIndices[row];
buffer->unlock();
buffer->clear();
}
// Add new row index buffer.
else
{
buffer = renderer->createIndexBuffer(IndexType_U16);
rowIndices.append(buffer);
}
uint g0 = row * (1 + skyResolutionX);
uint g1 = (row + 1) * (1 + skyResolutionX);
for (int col = 0; col <= skyResolutionX; ++col)
{
buffer->addIndex(g0++);
buffer->addIndex(g1++);
}
buffer->lock();
Q_ASSERT_X(buffer->length() == (skyResolutionX + 1) * 2, Q_FUNC_INFO,
"Unexpected grid row index buffer size");
}
Q_ASSERT_X(rowIndices.size() >= skyResolutionY, Q_FUNC_INFO,
"Not enough row index buffers");
}