Added labelling of constellations.

This commit is contained in:
Chris Laurel 2001-04-23 19:19:13 +00:00
parent 9621e27dd5
commit c0fabb0457
2 changed files with 43 additions and 3 deletions

View file

@ -568,6 +568,8 @@ void Renderer::render(const Observer& observer,
if ((labelMode & StarLabels) != 0)
labelStars(labelledStars, starDB, observer);
if ((labelMode & ConstellationLabels) != 0 && asterisms != NULL)
labelConstellations(*asterisms, observer);
glPopMatrix();
@ -665,7 +667,7 @@ void Renderer::render(const Observer& observer,
// reset the depth range
glDepthRange(0, 1);
if ((labelMode & PlanetOrbits) != 0)
if ((renderFlags & ShowOrbits) != 0)
{
// At this point, we're not rendering into the depth buffer
// so we'll set the far plane to be way out there. If we don't
@ -1939,7 +1941,6 @@ void Renderer::labelStars(const vector<Star*>& stars,
const Observer& observer)
{
Point3f observerPos = (Point3f) observer.getPosition();
Vec3f relPos;
for (vector<Star*>::const_iterator iter = stars.begin(); iter != stars.end(); iter++)
{
@ -1962,6 +1963,42 @@ void Renderer::labelStars(const vector<Star*>& stars,
}
void Renderer::labelConstellations(const AsterismList& asterisms,
const Observer& observer)
{
Point3f observerPos = (Point3f) observer.getPosition();
for (AsterismList::const_iterator iter = asterisms.begin();
iter != asterisms.end(); iter++)
{
Asterism* ast = *iter;
if (ast->getChainCount() > 0)
{
const Asterism::Chain& chain = ast->getChain(0);
if (chain.size() > 0)
{
// The constellation label is positioned at the average
// position of all stars in the first chain. This usually
// gives reasonable results.
Vec3f avg(0, 0, 0);
for (Asterism::Chain::const_iterator iter = chain.begin();
iter != chain.end(); iter++)
avg += (*iter - Point3f(0, 0, 0));
avg = avg / (float) chain.size();
Vec3f rpos = Point3f(avg.x, avg.y, avg.z) - observerPos;
if ((rpos * conjugate(observer.getOrientation()).toMatrix3()).z < 0) {
addLabel(ast->getName(),
Color(0.5f, 0.0f, 1.0f, 1.0f),
Point3f(rpos.x, rpos.y, rpos.z));
}
}
}
}
}
void Renderer::renderParticles(const vector<Particle>& particles,
Quatf orientation)
{

View file

@ -56,7 +56,7 @@ class Renderer
NoLabels = 0,
StarLabels = 1,
PlanetLabels = 2,
PlanetOrbits = 4,
ConstellationLabels = 4,
};
enum {
ShowNothing = 0,
@ -65,6 +65,7 @@ class Renderer
ShowGalaxies = 4,
ShowDiagrams = 8,
ShowCloudMaps = 16,
ShowOrbits = 32
};
int getRenderFlags() const;
void setRenderFlags(int);
@ -156,6 +157,8 @@ class Renderer
void labelStars(const vector<Star*>& stars,
const StarDatabase& starDB,
const Observer& observer);
void labelConstellations(const AsterismList& asterisms,
const Observer& observer);
void renderParticles(const vector<Particle>& particles,
Quatf orientation);
void renderLabels();