Draw ecliptic using glsl and common BO
parent
ae02fe2c38
commit
3f757998f4
|
@ -0,0 +1,8 @@
|
|||
#version 120
|
||||
|
||||
uniform vec4 color;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_FragColor = color;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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<GLfloat> small, large;
|
||||
for (int i = 0; i < 360; i += 36)
|
||||
{
|
||||
float c, s;
|
||||
sincos(degToRad(static_cast<float>(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<GLfloat> 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();
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue