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 4 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
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
30 changes: 29 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,35 @@ 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)));
// Tweak edges with two ideas:
// xshift is a left-right-shift after text rotation, i.e. along text direction --> SEEMS ENOUGH!
if ((fabs(screenPos[0])<1.) && (angleDeg>0.f )) // LEFT
{
//text.append(" - LeftEdge"); // DEBUG ONLY!
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
{
//text.append("-RightEdge"); // DEBUG ONLY!
//xshift*=(1.+1.f/tan(angleDeg*M_PI_180f));
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;
//text.append(" - TopEdge"); // DEBUG ONLY!
//xshift*=(1.+1.f/tan(angleDeg*M_PI_180f));
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);
//d->sPainter->setBlending(true); // This should have been true on entry, and we don't change it, why set it here?
}

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