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

Allow line loops on Cylindrical projection. #3505

Merged
merged 3 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 19 additions & 4 deletions src/core/StelVertexArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
StelVertexArray StelVertexArray::removeDiscontinuousTriangles(const StelProjector* prj) const
{
StelVertexArray ret = *this;
ret.primitiveType = Triangles;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to put it inside the switch, for symmetry with lines.


if (isIndexed())
{
Expand Down Expand Up @@ -55,14 +56,13 @@ StelVertexArray StelVertexArray::removeDiscontinuousTriangles(const StelProjecto
else
{
ret.indices.clear();
unsigned short int limit;
const unsigned short int limit=static_cast<unsigned short int>(vertex.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a good idea to assert that vertex.size() <= USHRT_MAX (or std::numeric_limits<unsigned short>::max()).

Also, this line could be shortened by removing repetition from the LHS and the useless int from the RHS. Or just using an implicit cast.

// Create a 'Triangles' vertex array from this array.
// We have different algorithms for different original mode
switch (primitiveType)
{
case TriangleStrip:
ret.indices.reserve(vertex.size() * 3);
limit = static_cast<unsigned short int>(vertex.size());
for (unsigned short int i = 2; i < limit; ++i)
{
if (prj->intersectViewportDiscontinuity(vertex[i], vertex[i-1]) ||
Expand All @@ -83,7 +83,6 @@ StelVertexArray StelVertexArray::removeDiscontinuousTriangles(const StelProjecto

case Triangles:
ret.indices.reserve(vertex.size());
limit = static_cast<unsigned short int>(vertex.size());
for (unsigned short int i = 0; i < limit; i += 3)
{
if (prj->intersectViewportDiscontinuity(vertex.at(i), vertex.at(i+1)) ||
Expand All @@ -99,6 +98,23 @@ StelVertexArray StelVertexArray::removeDiscontinuousTriangles(const StelProjecto
}
break;

case LineLoop:
case LineStrip:
// convert to an indexed set of GL_LINEs, leaving those away which intersect
ret.primitiveType=Lines;
ret.indices.reserve(2*vertex.size());
for (unsigned short int i = 0; i < limit-1; i++)
{
if (!prj->intersectViewportDiscontinuity(vertex.at(i), vertex.at(i+1)) )
ret.indices << i << i+1;
}
if (primitiveType==LineLoop)
{
if (!prj->intersectViewportDiscontinuity(vertex.at(limit-1), vertex.at(0)) )
ret.indices << limit-1 << 0;
}
break;

default:
Q_ASSERT(false);
}
Expand All @@ -108,7 +124,6 @@ StelVertexArray StelVertexArray::removeDiscontinuousTriangles(const StelProjecto
// FIXME: we should use an attribute for indexed array.
if (ret.indices.isEmpty())
ret.vertex.clear();
ret.primitiveType = Triangles;

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/modules/GridLinesMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ void SkyLine::draw(StelCore *core) const
rot.transfo(point); // rotate towards earth position
circle.vertex.append(pos+point); // attach to earth centre
}
sPainter.drawStelVertexArray(circle, false); // setting true does not paint for cylindrical&friends :-(
sPainter.drawStelVertexArray(circle, true);

// Special case for Umbra and Penumbra labels
Vec3d point(dist, 0.0, 0.0);
Expand Down
Loading