diff --git a/shaders/ecliptic_frag.glsl b/shaders/ecliptic_frag.glsl new file mode 100644 index 00000000..a8301b3c --- /dev/null +++ b/shaders/ecliptic_frag.glsl @@ -0,0 +1,8 @@ +#version 120 + +uniform vec4 color; + +void main(void) +{ + gl_FragColor = color; +} diff --git a/shaders/ecliptic_vert.glsl b/shaders/ecliptic_vert.glsl new file mode 100644 index 00000000..38e2336c --- /dev/null +++ b/shaders/ecliptic_vert.glsl @@ -0,0 +1,7 @@ +#version 120 + +void main(void) +{ + vec4 p = vec4(gl_Vertex.x, 0.0f, gl_Vertex.y, 1.0f); + gl_Position = gl_ModelViewProjectionMatrix * p; +} diff --git a/src/celengine/glmarker.cpp b/src/celengine/glmarker.cpp index c7a71219..f95f18af 100644 --- a/src/celengine/glmarker.cpp +++ b/src/celengine/glmarker.cpp @@ -146,13 +146,16 @@ constexpr const int SmallCircleOffset = StaticVtxCount; static int SmallCircleCount = 0; static int LargeCircleOffset = 0; static int LargeCircleCount = 0; +static int EclipticOffset = 0; +constexpr const int EclipticCount = 200; static void initVO(VertexObject& vo) { + float c, s; + vector small, large; for (int i = 0; i < 360; i += 36) { - float c, s; sincos(degToRad(static_cast(i)), s, c); small.push_back(c); small.push_back(s); large.push_back(c); large.push_back(s); @@ -167,8 +170,17 @@ static void initVO(VertexObject& vo) LargeCircleCount = large.size() / 2; LargeCircleOffset = SmallCircleOffset + SmallCircleCount; + vector ecliptic; + for (int i = 0; i < EclipticCount; i++) + { + sincos((float) (2 * i) / (float) EclipticCount * ((float) PI), s, c); + ecliptic.push_back(c * 1000.0f); + ecliptic.push_back(s * 1000.0f); + } + EclipticOffset = LargeCircleOffset + LargeCircleCount; + #define VTXTOMEM(a) ((a) * sizeof(GLfloat) * 2) - vo.allocate(VTXTOMEM(StaticVtxCount + SmallCircleCount + LargeCircleCount)); + vo.allocate(VTXTOMEM(StaticVtxCount + SmallCircleCount + LargeCircleCount + EclipticCount)); #define VOSTREAM(a) vo.setBufferData(a, VTXTOMEM(a ## Offset), sizeof(a)) VOSTREAM(Diamond); @@ -185,6 +197,7 @@ static void initVO(VertexObject& vo) vo.setBufferData(small.data(), VTXTOMEM(SmallCircleOffset), memsize(small)); vo.setBufferData(large.data(), VTXTOMEM(LargeCircleOffset), memsize(large)); + vo.setBufferData(ecliptic.data(), VTXTOMEM(EclipticOffset), memsize(ecliptic)); #undef VTXTOMEM vo.setVertices(2, GL_FLOAT, false, 0, 0); @@ -349,3 +362,28 @@ void Renderer::renderSelectionPointer(const Observer& observer, glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); #endif } + +/*! Draw the J2000.0 ecliptic; trivial, since this forms the basis for + * Celestia's coordinate system. + */ +void Renderer::renderEclipticLine() +{ + if ((renderFlags & ShowEcliptic) == 0) + return; + + assert(shaderManager != nullptr); + auto* prog = shaderManager->getShader("ecliptic"); + if (prog == nullptr) + return; + + markerVO.bind(); + if (!markerVO.initialized()) + initVO(markerVO); + + prog->use(); + prog->vec4Param("color") = EclipticColor.toVector4(); + markerVO.draw(GL_LINE_LOOP, EclipticCount, EclipticOffset); + + glUseProgram(0); + markerVO.unbind(); +} diff --git a/src/celengine/render.cpp b/src/celengine/render.cpp index 5b255279..9de0a5c0 100644 --- a/src/celengine/render.cpp +++ b/src/celengine/render.cpp @@ -7158,20 +7158,7 @@ void Renderer::renderSkyGrids(const Observer& observer) } } - if ((renderFlags & ShowEcliptic) != 0) - { - // Draw the J2000.0 ecliptic; trivial, since this forms the basis for - // Celestia's coordinate system. - const int subdivision = 200; - glColor(EclipticColor); - glBegin(GL_LINE_LOOP); - for (int i = 0; i < subdivision; i++) - { - double theta = (double) i / (double) subdivision * 2 * PI; - glVertex3f((float) cos(theta) * 1000.0f, 0.0f, (float) sin(theta) * 1000.0f); - } - glEnd(); - } + renderEclipticLine(); } void Renderer::labelConstellations(const AsterismList& asterisms, diff --git a/src/celengine/render.h b/src/celengine/render.h index 80b573d4..e90668c5 100644 --- a/src/celengine/render.h +++ b/src/celengine/render.h @@ -484,6 +484,7 @@ class Renderer void renderAsterisms(const Universe&, float); void renderBoundaries(const Universe&, float); + void renderEclipticLine(); void buildRenderLists(const Eigen::Vector3d& astrocentricObserverPos, const celmath::Frustum& viewFrustum,