void drawAthmosphere()
{
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
for (int i = 0; i < 40; i++)
{
glBegin(GL_TRIANGLE_STRIP);
for (int j = 0; j < 41; j++)
{
float normal[3];
normal[0] = sin(i/40.0f*6.282f) * sin(j/40.0f*3.141f); //Die normale des Vertex. (Is ja ne Kugel)
normal[1] = cos(j/40.0f*3.141f);
normal[2] = cos(i/40.0f*6.282f) * sin(j/40.0f*3.141f);
float light = normal[0] * lightvec[0] + // Normale dot Lichtrichtung (die Richtung zur Sonne)
normal[1] * lightvec[1] +
normal[2] * lightvec[2];
light += 0.1; //die Athmosphäre leuchtet auch noch etwas weiter in den Schatten hinein
if (light < 0.0f) light = 0.0f; else if (light > 1.0f) light = 1.0f; //auf 0.0 .. 1.0 clampen
float thickness = 1.0f+(normal[0] * viewvec[0] + //Die Länge des Weges, die das Licht von der Oberfläche
normal[1] * viewvec[1] + //durch die Athmosphäre zurück legt (angenähert) steuert,
normal[2] * viewvec[2]); //wie viel blau man sieht. Und je schräger man drauf guckt, desto Dicker ist sie.
if (thickness < 0.6) thickness = thickness / 0.6; else thickness = (1.0f - thickness) / 0.4; //Mit Ausnahme des Randes, da wird sie wieder dünner.
float f = thickness * light; //Beides zusammen multiplizieren
glColor3f(0.5f * f, 0.7f * f, 1.0f * f); //Und noch nen schönen Blauton wählen.
glVertex3f(normal[0] * 1.1, // 1.0 is der Radius des Planeten und 1.1 der Radius der Athmosphäre
normal[1] * 1.1,
normal[2] * 1.1);
normal[0] = sin((i+1)/40.0f*6.282f) * sin(j/40.0f*3.141f);
normal[1] = cos(j/40.0f*3.141f);
normal[2] = cos((i+1)/40.0f*6.282f) * sin(j/40.0f*3.141f);
light = normal[0] * lightvec[0] +
normal[1] * lightvec[1] +
normal[2] * lightvec[2];
light += 0.1;
if (light < 0.0f) light = 0.0f; else if (light > 1.0f) light = 1.0f;
thickness = 1.0f+(normal[0] * viewvec[0] +
normal[1] * viewvec[1] +
normal[2] * viewvec[2]);
if (thickness < 0.6) thickness = thickness / 0.6; else thickness = (1.0f - thickness) / 0.4;
f = thickness * light;
glColor3f(0.5f * f, 0.7f * f, 1.0f * f);
glVertex3f(normal[0] * 1.1,
normal[1] * 1.1,
normal[2] * 1.1);
}
glEnd();
}
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}