I use vector storing vertices data needed to draw a sphere. The question is, how do I know which three vertices build a triangle and how do I iterate through every single triangle of one mesh to check if it intersects with a triangle of another 3d mesh.
Here is how I populate vector 'vertices' with data:
vector<GLfloat> vertices;
float const R = 1.0f / (float)(rings - 1);
float const S = 1.0f / (float)(sectors - 1);
unsigned int r, s;
vertices.resize(rings * sectors * 3);
vector<GLfloat>::iterator v = vertices.begin();
for(r = 0; r < rings; r++) for(s = 0; s < sectors; s++)
{
float const x = sinf(M_PI * r * R) * cosf(2 * M_PI * s * S);
float const y = sinf(-M_PI_2 + M_PI * r * R );
float const z = sinf(2.0f * M_PI * s * S) * sinf(M_PI * r * R );
*v++ = x * radius;
*v++ = y * radius;
*v++ = z * radius;
}
You might wonder, if I'm about to check for collisions between 2 spheres, why I don't use their radii instead. This is because I intend to use more complex shapes in future, where this simple method won't be of any use.