I've created a surface of revolution and need to calculate the per vertex normals to pass into my vertex shader. I'm not sure where I'm going wrong:
for(int i = 0, j = 0; i <= c && j <= c; i += 3, j += 9){
GLfloat point[] = {vp1[i], vp1[i + 1], vp1[i + 2], 1.0};
multiply(scale1, point, result);
vp[i] = result[0];
vp[i + 1] = result[1];
vp[i + 2] = result[2];
GLfloat pointC[] = {vp1[j], vp1[j + 1], vp1[j + 2], 1.0};
GLfloat pointA[] = {vp1[j + 3], vp1[j + 4], vp1[j + 5], 1.0};
GLfloat pointB[] = {vp1[j + 6], vp1[j + 7], vp1[j + 8], 1.0};
GLfloat vec1[] = {pointA[0] - pointC[0], pointA[1] - pointC[1], pointA[2] - pointC[2]};
GLfloat vec2[] = {pointB[0] - pointC[0], pointB[1] - pointC[1], pointB[2] - pointC[2]};
crossProd(vec1, vec2, normal);
float mag = sqrt((normal[0]*normal[0]) + (normal[1]*normal[1]) + (normal[2]*normal[2]));
normals[j + 0] = normal[0] / mag;
normals[j + 1] = normal[1] / mag;
normals[j + 2] = normal[2] / mag;
normals[j + 3] = normal[0] / mag;
normals[j + 4] = normal[1] / mag;
normals[j + 5] = normal[2] / mag;
normals[j + 6] = normal[0] / mag;
normals[j + 7] = normal[1] / mag;
normals[j + 8] = normal[2] / mag;
}
This code is adding my vertices to vp and then trying to calculate the normal. My surface definitely doesn't look right when rendered.
I think I'm generating the surface normal from everything I've read so far, but I'm not sure how to turn my triangle soup into per-vertex normals.
Edit: To a commenter below, three successive indices make 1 point. 9 successive indices make a triangle.
Edit 2: How do I convert this into per-vertex normals?