Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak screen intersect callback #3059

Merged
merged 6 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions plugins/ArchaeoLines/src/ArchaeoLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,8 @@ void alViewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& direct
direc.normalize();
//const Vec4f tmpColor = d->sPainter->getColor();
//d->sPainter->setColor(d->textColor[0], d->textColor[1], d->textColor[2], d->textColor[3]);
const int viewportWidth = d->sPainter->getProjector()->getViewportWidth();
const int viewportHeight = d->sPainter->getProjector()->getViewportHeight();

QString text = d->text; // original text-from-coordinates taken out!
if (text.isEmpty())
Expand All @@ -1381,6 +1383,23 @@ void alViewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& direct
xshift=-d->sPainter->getFontMetrics().boundingRect(text).width()-6.f;
}

// Copy tweak from GridlineMgr
if ((fabs(screenPos[0])<1.) && (angleDeg>0.f )) // LEFT
{
xshift+=0.5f*tan(angleDeg*M_PI_180f)*d->sPainter->getFontMetrics().boundingRect(text).height();
}
else if ((fabs(screenPos[0]-viewportWidth)<1.) && (angleDeg>180.f )) // RIGHT
{
xshift += 0.5 * tan(angleDeg*M_PI_180f)*d->sPainter->getFontMetrics().boundingRect(text).height();
}
else if ((fabs(screenPos[1]-viewportHeight)<1.) && fabs(angleDeg)>5.f) // TOP
{
const float sign = angleDeg<-90.f ? 0.5f : -0.5f;
xshift += sign * (1./tan(angleDeg*M_PI_180f))*d->sPainter->getFontMetrics().boundingRect(text).height();
}
// It seems bottom edge is always OK!


d->sPainter->drawText(static_cast<float>(screenPos[0]), static_cast<float>(screenPos[1]), text, angleDeg, xshift, 3);
//d->sPainter->setColor(tmpColor[0], tmpColor[1], tmpColor[2], tmpColor[3]); // RESTORE
d->sPainter->setBlending(true);
Expand Down
11 changes: 5 additions & 6 deletions src/core/StelPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,12 @@ void StelPainter::drawText(float x, float y, const QString& str, float angleDeg,
static float vertexData[8];
// compute the vertex coordinates applying the translation and the rotation
static const float vertexBase[] = {0., 0., 1., 0., 0., 1., 1., 1.};
if (std::fabs(angleDeg)>1.f*static_cast<float>(M_PI)/180.f)
if (std::fabs(angleDeg)>1.f*M_PI_180f)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
const float cosr = std::cos(angleDeg * static_cast<float>(M_PI/180.));
const float sinr = std::sin(angleDeg * static_cast<float>(M_PI/180.));
const float cosr = std::cos(angleDeg * M_PI_180f);
const float sinr = std::sin(angleDeg * M_PI_180f);
for (int i = 0; i < 8; i+=2)
{
vertexData[i] = int(x + (tex->size.width()*vertexBase[i]+xshift) * cosr - (tex->size.height()*vertexBase[i+1]+yshift) * sinr);
Expand Down Expand Up @@ -865,14 +865,13 @@ void StelPainter::drawSmallCircleVertexArray()
smallCircleColorArray.resize(0);
}

static Vec3d pt1, pt2;
void StelPainter::drawGreatCircleArc(const Vec3d& start, const Vec3d& stop, const SphericalCap* clippingCap,
void (*viewportEdgeIntersectCallback)(const Vec3d& screenPos, const Vec3d& direction, void* userData), void* userData)
{
if (clippingCap)
{
pt1=start;
pt2=stop;
Vec3d pt1=start;
Vec3d pt2=stop;
if (clippingCap->clipGreatCircle(pt1, pt2))
{
drawSmallCircleArc(pt1, pt2, Vec3d(0.), viewportEdgeIntersectCallback, userData);
Expand Down
22 changes: 21 additions & 1 deletion src/core/modules/GridLinesMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio
const bool useOldAzimuth = StelApp::getInstance().getFlagSouthAzimuthUsage();
const float ppx = static_cast<float>(d->sPainter->getProjector()->getDevicePixelsPerPixel());

const int viewportWidth = d->sPainter->getProjector()->getViewportWidth();
const int viewportHeight = d->sPainter->getProjector()->getViewportHeight();

QString text;
if (d->text.isEmpty())
{
Expand Down Expand Up @@ -365,10 +368,27 @@ void viewportEdgeIntersectCallback(const Vec3d& screenPos, const Vec3d& directio
angleDeg+=180.f;
xshift=-(static_cast<float>(d->sPainter->getFontMetrics().boundingRect(text).width()) + xshift*ppx);
}
// DEBUG INFO ONLY!
//text=QString(" <:%1°").arg(QString::number(angleDeg, 'f', 2));
//text.append(QString(" <:%1° %2/%3 (%4x%5)").arg(QString::number(angleDeg, 'f', 2), QString::number(screenPos[0], 'f', 2), QString::number(screenPos[1], 'f', 2),
// QString::number(viewportWidth), QString::number(viewportHeight)));
if ((fabs(screenPos[0])<1.) && (angleDeg>0.f )) // LEFT
{
xshift+=0.5f*tan(angleDeg*M_PI_180f)*d->sPainter->getFontMetrics().boundingRect(text).height();
}
else if ((fabs(screenPos[0]-viewportWidth)<1.) && (angleDeg>180.f )) // RIGHT
{
xshift += 0.5 * tan(angleDeg*M_PI_180f)*d->sPainter->getFontMetrics().boundingRect(text).height();
}
else if ((fabs(screenPos[1]-viewportHeight)<1.) && fabs(angleDeg)>5.f) // TOP
{
const float sign = angleDeg<-90.f ? 0.5f : -0.5f;
xshift += sign * (1./tan(angleDeg*M_PI_180f))*d->sPainter->getFontMetrics().boundingRect(text).height();
}
// It seems bottom edge is always OK!

d->sPainter->drawText(static_cast<float>(screenPos[0]), static_cast<float>(screenPos[1]), text, angleDeg, xshift*ppx, yshift*ppx);
d->sPainter->setColor(tmpColor);
d->sPainter->setBlending(true);
}

//! Draw the sky grid in the current frame
Expand Down