thebigbo

05-18-2014, 04:59 AM

Hi,

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 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;

}

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 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;

}