Triangulierung einer Kugel
-
Hallo zusammen,
ich sitze gerade an meiner Aufgabe und komme irgendwie nicht weiter.
Man soll eine Kugel/Sphäre als Dreiecknetz darstellen. Dazu ist diese http://dl.dropbox.com/u/7305802/triangles.PNG Skizze gegeben und die Formel zur Berechnung des Sphärenradius für gegebene Kugelkoordinaten.
Das vorgegebene Programmgerüst
glBegin(GL_POINTS); // { float c = 0.0f; for (float theta = 0.0f; theta < 2.0f*M_PI; theta += a, c += a/2.0f) for (float phi = 0.0f; phi < 2.0f*M_PI; phi += a) { // Here something is missing... float p_1[3] = {sin(theta)*cos(phi+c), sin(theta)*sin(phi+c), cos(theta)}; glVertex3f(p_1[0], p_1[1], p_1[2]); // Here something is missing... // Compute a color value instead of hardware lighting if (g_compute_lighting == 1) { // Here something is missing... } } // } glEnd();
Woraus ich jetzt erstmal
void sp_r(float theta, float phi, float* tochange) { tochange[0] = sin(theta) * cos(phi); tochange[1] = sin(theta) * sin(phi); tochange[2] = cos(theta); } [...] float c = 0.0f; int b = 0; for (float theta = 0.0f; theta < 2.0f*M_PI; theta += a, c += a/2.0f, b++) { for (float phi = 0.0f; phi < 2.0f*M_PI; phi += a) { float p_1[3]; float p_2[3]; float p_3[3]; float p_4[3]; if (b % 2 != 0) { sp_r(theta + a, phi, p_1); sp_r(theta , phi + a/2.0f, p_2); sp_r(theta + a, phi + a, p_3); sp_r(theta , phi + a + a/2.0f, p_4); } else { sp_r(theta, phi, p_1); sp_r(theta + a, phi + a/2.0f, p_2); sp_r(theta, phi + a, p_3); sp_r(theta + a, phi + a + a/2.0f, p_4); } glBegin(GL_TRIANGLES); glVertex3f(p_1[0], p_1[1], p_1[2]); glVertex3f(p_2[0], p_2[1], p_2[2]); glVertex3f(p_3[0], p_3[1], p_3[2]); glVertex3f(p_2[0], p_2[1], p_2[2]); glVertex3f(p_3[0], p_3[1], p_3[2]); glVertex3f(p_4[0], p_4[1], p_4[2]); glEnd(); // Here something is missing... // Compute a color value instead of hardware lighting if (g_compute_lighting == 1) { // Here something is missing... } } // } }
gemacht hab. Allerdings funktioniert das jetzt nur halb. Es fehlen zwischendurch Dreiecke.
Könnte mir bitte jemand auf die Sprünge helfen?
Grüße
Webo
-
Ne Idee für ne Lösung wäre:
Dir ist bekannt, aus wie vielen Dreiecken die Kugel besteht? Oder hast du zumindest die Möglichkeit herrauszufinden?
Wenn ja ist meine Lösung:
Finde herraus, wie viele Eckpunkte du hast (sind glaube ich genau so viele, wie Dreiecke). Dann verteile diese gleichmäßig über die Kugeloberfläche und mache daraus Dreiecke.Wäre meine Idee...