I'm working on a lab for school, and we're using a data structure neither the book nor lecture covers. Basically, we are defining a diamond shape using 6 vertices and 8 faces. I am supposed to find the normals and do a bunch of other stuff. Here's where I get lost...
int numFaces = 8;
Vector3 p1, p2, p3; // points or vertices of the triangle
// define 5 vertices of a diamond shape - colors not being used now
Vector3 vertexes[] = {
Vector3( 0, 2, 0 ), // vertex 0
Vector3( 1, 0, 1 ), // vertex 1
Vector3( 1, 0, -1 ), // vertex 2 ...
Vector3( -1, 0, -1 ),
Vector3( -1, 0, 1 ),
Vector3( 0, -2, 0 )
};
// set up the face index data into the vertex array above
// each triple will define a single face (triangle) of our shape
Face faceData[] = {
0, 4, 1, // top front-facing face
0, 3, 4, // top left face
0, 2, 3, // top rear face
0, 1, 2, // top right face
5, 1, 4, // bottom front face ...
5, 4, 3,
5, 3, 2,
5, 2, 1,
};
I am supposed to insert my normals into the faceData array. How do I do that? Teh Google-fu, it fails....
I have a means to calculate the normal by defining another Vector3 and assigning it the value of CrossProduct(Vector3 a, Vector3 b), and then using the normalize() function on that variable. I have done this like so:
Vector3 normals[] = {
CrossProduct(vertexes[0],vertexes[4]), // normal for face 0, 4, 1
CrossProduct(vertexes[0],vertexes[3]), // normal for face 0, 3, 4
CrossProduct(vertexes[0],vertexes[2]), // etc.
CrossProduct(vertexes[0],vertexes[1]),
CrossProduct(vertexes[5],vertexes[1]),
CrossProduct(vertexes[5],vertexes[4]),
CrossProduct(vertexes[5],vertexes[3]),
CrossProduct(vertexes[5],vertexes[2])
};
for (int count = 0;count < numFaces;count++)
normals[count].normalize();
Don't worry if my normals are wrong. I can figure out the solution to that. I just need to know how to insert this data into the faceData array? |