Skip to content

Commit

Permalink
Vectorize markers of dark nebulas
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Apr 10, 2023
1 parent b146456 commit 81e7172
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 15 deletions.
94 changes: 87 additions & 7 deletions src/core/modules/Nebula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ StelTextureSP Nebula::texOpenClusterXLarge;
StelTextureSP Nebula::texGlobularCluster;
StelTextureSP Nebula::texGlobularClusterLarge;
StelTextureSP Nebula::texPlanetaryNebula;
StelTextureSP Nebula::texDarkNebula;
StelTextureSP Nebula::texDarkNebulaLarge;
StelTextureSP Nebula::texOpenClusterWithNebulosity;
StelTextureSP Nebula::texOpenClusterWithNebulosityLarge;
bool Nebula::drawHintProportional = false;
Expand Down Expand Up @@ -872,11 +870,93 @@ void Nebula::drawHints(StelPainter& sPainter, float maxMagHints, StelCore *core)
Nebula::texPlanetaryNebula->bind();
break;
case NebDn:
if (finalSize > 35.f)
Nebula::texDarkNebulaLarge->bind();
else
Nebula::texDarkNebula->bind();
break;
{
// Take into account device pixel density and global scale ratio, as we are drawing 2D stuff.
const auto pixelRatio = sPainter.getProjector()->getDevicePixelsPerPixel();
const auto scale = pixelRatio * StelApp::getInstance().getGlobalScalingRatio();
finalSize *= scale;

const float x = XY[0];
const float y = XY[1];
const float roundRadius = 0.35 * finalSize;
const int numPointsInArc = std::lround(std::clamp(5*finalSize/35, 5.f, 16.f));
std::vector<float> vertexData;
vertexData.reserve(numPointsInArc*2*4);
const float leftOuterX = x - finalSize;
const float leftInnerX = leftOuterX + roundRadius;
const float bottomOuterY = y - finalSize;
const float bottomInnerY = bottomOuterY + roundRadius;
const float rightOuterX = x + finalSize;
const float rightInnerX = rightOuterX - roundRadius;
const float topOuterY = y + finalSize;
const float topInnerY = topOuterY - roundRadius;
const float gap = 0.15*finalSize;
const float*const cossin = StelUtils::ComputeCosSinRhoZone((M_PIf/2)/(numPointsInArc-1),
numPointsInArc-1, 0);
sPainter.setLineSmooth(true);
sPainter.setLineWidth(scale * std::clamp(2*finalSize/35, 1.f, 2.5f));
sPainter.setColor(color);
sPainter.enableClientStates(true);

vertexData.clear();
vertexData.push_back(x-gap);
vertexData.push_back(bottomOuterY);
for(int n = 0; n < numPointsInArc; ++n)
{
const auto cosa = cossin[2*n], sina = cossin[2*n+1];
vertexData.push_back(leftInnerX - roundRadius*sina);
vertexData.push_back(bottomInnerY - roundRadius*cosa);
}
vertexData.push_back(leftOuterX);
vertexData.push_back(y-gap);
sPainter.setVertexPointer(2, GL_FLOAT, vertexData.data());
sPainter.drawFromArray(StelPainter::LineStrip, vertexData.size() / 2, 0, false);

vertexData.clear();
vertexData.push_back(leftOuterX);
vertexData.push_back(y+gap);
for(int n = 0; n < numPointsInArc; ++n)
{
const auto cosa = cossin[2*n], sina = cossin[2*n+1];
vertexData.push_back(leftInnerX - roundRadius*cosa);
vertexData.push_back(topInnerY + roundRadius*sina);
}
vertexData.push_back(x-gap);
vertexData.push_back(topOuterY);
sPainter.setVertexPointer(2, GL_FLOAT, vertexData.data());
sPainter.drawFromArray(StelPainter::LineStrip, vertexData.size() / 2, 0, false);

vertexData.clear();
vertexData.push_back(x+gap);
vertexData.push_back(topOuterY);
for(int n = 0; n < numPointsInArc; ++n)
{
const auto cosa = cossin[2*n], sina = cossin[2*n+1];
vertexData.push_back(rightInnerX + roundRadius*sina);
vertexData.push_back(topInnerY + roundRadius*cosa);
}
vertexData.push_back(rightOuterX);
vertexData.push_back(y+gap);
sPainter.setVertexPointer(2, GL_FLOAT, vertexData.data());
sPainter.drawFromArray(StelPainter::LineStrip, vertexData.size() / 2, 0, false);

vertexData.clear();
vertexData.push_back(rightOuterX);
vertexData.push_back(y-gap);
for(int n = 0; n < numPointsInArc; ++n)
{
const auto cosa = cossin[2*n], sina = cossin[2*n+1];
vertexData.push_back(rightInnerX + roundRadius*cosa);
vertexData.push_back(bottomInnerY - roundRadius*sina);
}
vertexData.push_back(x+gap);
vertexData.push_back(bottomOuterY);
sPainter.setVertexPointer(2, GL_FLOAT, vertexData.data());
sPainter.drawFromArray(StelPainter::LineStrip, vertexData.size() / 2, 0, false);

sPainter.enableClientStates(false);
return;
}
case NebCn:
if (finalSize > 35.f)
Nebula::texOpenClusterWithNebulosityLarge->bind();
Expand Down
2 changes: 0 additions & 2 deletions src/core/modules/Nebula.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ friend class NebulaMgr;
static StelTextureSP texGlobularCluster; // Type 2
static StelTextureSP texGlobularClusterLarge; // Type 2_large
static StelTextureSP texPlanetaryNebula; // Type 3
static StelTextureSP texDarkNebula; // Type 5
static StelTextureSP texDarkNebulaLarge; // Type 5_large
static StelTextureSP texOpenClusterWithNebulosity; // Type 6
static StelTextureSP texOpenClusterWithNebulosityLarge; // Type 6_large
static float hintsBrightness;
Expand Down
6 changes: 0 additions & 6 deletions src/core/modules/NebulaMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ NebulaMgr::~NebulaMgr()
Nebula::texGlobularCluster = StelTextureSP();
Nebula::texGlobularClusterLarge = StelTextureSP();
Nebula::texPlanetaryNebula = StelTextureSP();
Nebula::texDarkNebula = StelTextureSP();
Nebula::texDarkNebulaLarge = StelTextureSP();
Nebula::texOpenClusterWithNebulosity = StelTextureSP();
Nebula::texOpenClusterWithNebulosityLarge = StelTextureSP();
}
Expand Down Expand Up @@ -206,10 +204,6 @@ void NebulaMgr::init()
Nebula::texGlobularClusterLarge = texMan.createTexture(StelFileMgr::getInstallationDir()+"/textures/neb_gcl_lrg.png");
// Load planetary nebula marker texture
Nebula::texPlanetaryNebula = texMan.createTexture(StelFileMgr::getInstallationDir()+"/textures/neb_pnb.png");
// Load dark nebula marker texture
Nebula::texDarkNebula = texMan.createTexture(StelFileMgr::getInstallationDir()+"/textures/neb_drk.png");
// Load dark nebula marker texture for large DSO
Nebula::texDarkNebulaLarge = texMan.createTexture(StelFileMgr::getInstallationDir()+"/textures/neb_drk_lrg.png");
// Load Ocl/Nebula marker texture
Nebula::texOpenClusterWithNebulosity = texMan.createTexture(StelFileMgr::getInstallationDir()+"/textures/neb_ocln.png");
// Load Ocl/Nebula marker texture for large objects
Expand Down
Binary file removed textures/neb_drk.png
Binary file not shown.
Binary file removed textures/neb_drk_lrg.png
Binary file not shown.

0 comments on commit 81e7172

Please sign in to comment.