+ //Using edges as vectors on the plane, cross to get the normal.
+ Vector3 normalVector = edge1.Cross(edge2);
+
+ //Add this triangle's normal to the cumulative normal of each constituent point and set the index of the normal accordingly.
+ for( unsigned long j = 0; j < 3; j++, normalIndex++ )
+ {
+ triangles[i].normalIndex[j] = triangles[i].pointIndex[j]; //Normal index matches up to vertex index, as one normal per vertex.
+ normals[triangles[i].normalIndex[j]] += normalVector;
+ }
+ }
+
+ //Normalise the normals.
+ for( unsigned long i = 0; i < normals.Size(); i++ )
+ {
+ normals[i].Normalize();
+ }
+}
+
+//TODO: Use a function that can generate more than one normal/tangent per vertex (using angle)
+void ObjLoader::CalculateTangentFrame()
+{
+ //Reset tangent and bitangent vectors to hold new values.
+ mTangents.Clear();
+ mBiTangents.Clear();
+ mTangents.Resize( mPoints.Size() );
+ mBiTangents.Resize( mPoints.Size() );
+
+ //For each triangle, calculate the tangent vector and then add it to the total tangent vector of each point.
+ for ( unsigned long a = 0; a < mTriangles.Size(); a++ )
+ {
+ Vector3 tangentVector;