Move asterisms and boundaries drawing from Renderer::draw()

pull/3/head
Hleb Valoshka 2018-11-08 20:37:51 +03:00
parent fe40034189
commit 9069df6c6b
2 changed files with 68 additions and 61 deletions

View File

@ -2943,68 +2943,10 @@ void Renderer::draw(const Observer& observer,
glTranslatef(-observerPosLY.x(), -observerPosLY.y(), -observerPosLY.z());
// Render asterisms
if ((renderFlags & ShowDiagrams) != 0 && universe.getAsterisms() != nullptr)
{
/* We'll linearly fade the lines as a function of the observer's
distance to the origin of coordinates: */
float opacity = 1.0f;
float dist = observerPosLY.norm() * 1.6e4f;
if (dist > MaxAsterismLinesConstDist)
{
opacity = clamp((MaxAsterismLinesConstDist - dist) /
(MaxAsterismLinesDist - MaxAsterismLinesConstDist) + 1);
}
glColor(ConstellationColor, opacity);
glDisable(GL_TEXTURE_2D);
if ((renderFlags & ShowSmoothLines) != 0)
enableSmoothLines();
AsterismList* asterisms = universe.getAsterisms();
for (const auto ast : *asterisms)
{
if (ast->getActive())
{
if (ast->isColorOverridden())
glColor(ast->getOverrideColor(), opacity);
else
glColor(ConstellationColor, opacity);
for (int i = 0; i < ast->getChainCount(); i++)
{
const Asterism::Chain& chain = ast->getChain(i);
glBegin(GL_LINE_STRIP);
for (const auto& c : chain)
glVertex3fv(c.data());
glEnd();
}
}
}
if (renderFlags & ShowSmoothLines)
disableSmoothLines();
}
if ((renderFlags & ShowBoundaries) && (universe.getBoundaries() != nullptr))
{
/* We'll linearly fade the boundaries as a function of the
observer's distance to the origin of coordinates: */
float opacity = 1.0f;
float dist = observerPosLY.norm() * 1.6e4f;
if (dist > MaxAsterismLabelsConstDist)
{
opacity = clamp((MaxAsterismLabelsConstDist - dist) /
(MaxAsterismLabelsDist - MaxAsterismLabelsConstDist) + 1);
}
glDisable(GL_TEXTURE_2D);
if (renderFlags & ShowSmoothLines)
enableSmoothLines();
universe.getBoundaries()->render(Color(BoundaryColor, opacity));
if (renderFlags & ShowSmoothLines)
disableSmoothLines();
}
float dist = observerPosLY.norm() * 1.6e4f;
renderAsterisms(universe, dist);
renderBoundaries(universe, dist);
// Render star and deep sky object labels
renderBackgroundAnnotations(FontNormal);
@ -5891,6 +5833,68 @@ void Renderer::renderReferenceMark(const ReferenceMark& refMark,
}
void Renderer::renderAsterisms(const Universe& universe, float dist)
{
if ((renderFlags & ShowDiagrams) == 0 || universe.getAsterisms() == nullptr)
return;
float opacity = 1.0f;
if (dist > MaxAsterismLinesConstDist)
{
opacity = clamp((MaxAsterismLinesConstDist - dist) /
(MaxAsterismLinesDist - MaxAsterismLinesConstDist) + 1);
}
glColor(ConstellationColor, opacity);
glDisable(GL_TEXTURE_2D);
enableSmoothLines(renderFlags);
for (const auto ast : *universe.getAsterisms())
{
if (!ast->getActive())
continue;
if (ast->isColorOverridden())
glColor(ast->getOverrideColor(), opacity);
else
glColor(ConstellationColor, opacity);
for (int i = 0; i < ast->getChainCount(); i++)
{
const Asterism::Chain& chain = ast->getChain(i);
glBegin(GL_LINE_STRIP);
for (const auto& c : chain)
glVertex3fv(c.data());
glEnd();
}
}
disableSmoothLines(renderFlags);
}
void Renderer::renderBoundaries(const Universe& universe, float dist)
{
if ((renderFlags & ShowBoundaries) == 0 || universe.getBoundaries() == nullptr)
return;
/* We'll linearly fade the boundaries as a function of the
observer's distance to the origin of coordinates: */
float opacity = 1.0f;
if (dist > MaxAsterismLabelsConstDist)
{
opacity = clamp((MaxAsterismLabelsConstDist - dist) /
(MaxAsterismLabelsDist - MaxAsterismLabelsConstDist) + 1);
}
glDisable(GL_TEXTURE_2D);
enableSmoothLines(renderFlags);
universe.getBoundaries()->render(Color(BoundaryColor, opacity));
disableSmoothLines(renderFlags);
}
// Helper function to compute the luminosity of a perfectly
// reflective disc with the specified radius. This is used as an upper
// bound for the apparent brightness of an object when culling

View File

@ -424,6 +424,9 @@ class Renderer
const Frustum& viewFrustum,
const Selection& sel);
void renderAsterisms(const Universe&, float);
void renderBoundaries(const Universe&, float);
void buildRenderLists(const Eigen::Vector3d& astrocentricObserverPos,
const Frustum& viewFrustum,
const Eigen::Vector3d& viewPlaneNormal,