I'm writing a 3D asteroids game with C++, SFML for networking/audio/windowing/events, and OpenGL for 3D rendering.
I've created a simple script that creates a vector of random triangles within a certain area. I do have some problems though... the asteroids are all jagged and the triangles stick up everywhere. I'm not sure at all how to create them so the triangles connect to create a full surface.
Generation code:
maxVertices = 20;
for(int i = 0; i < maxVertices; i++) {
Triangle triangle;
triangle.mVertices[0] = sf::Vector3f(std::rand() % 10, std::rand() % 8, std::rand() % 12);
triangle.mVertices[1] = sf::Vector3f(std::rand() % 8, std::rand() % 9, std::rand() % 11);
triangle.mVertices[2] = sf::Vector3f(std::rand() % 12, std::rand() % 11, std::rand() % 9);
mTriangles.push_back(triangle);
}
Rendering code:
glBegin(GL_TRIANGLES);
for(int i = 0; i < mTriangles.size(); i++) {
glVertex3f(mTriangles.mVertices[0].x, mTriangles.mVertices[0].y, mTriangles.mVertices[0].z);
glVertex3f(mTriangles.mVertices[1].x, mTriangles.mVertices[1].y, mTriangles.mVertices[1].z);
glVertex3f(mTriangles.mVertices[2].x, mTriangles.mVertices[2].y, mTriangles.mVertices[2].z);
}
glEnd();Any help on writing an algorithm for this would be very appreciated! Thank you








