// Specifying shell geometries based on g_tipPos, g_furHeight, and g_numShells. // You need to call this function whenver the shell needs to be updated static void updateShellGeometry() { // TASK 1 and 3 TODO: finish this function as part of Task 1 and Task 3 int numVertices = g_bunnyMesh.getNumVertices(); g_bunnyMeshCopy = Mesh(g_bunnyMesh); createSmoothNormals(g_bunnyMeshCopy); RigTForm path = getPathAccumRbt(g_world, g_bunnyNode); for(int i = 0; i < g_numShells; i++) { // iterate through each vertex in the mesh for(int j = 0; j < numVertices; j++) { Cvec3 normal = g_bunnyMesh.getVertex(j).getNormal(); Cvec3 n = normal * (((double) g_furHeight) / g_numShells); Cvec3 s = (path * RigTForm(g_tipAtRest[j])).getTranslation(); Cvec3 d = (g_tipPos[j] - s) * (2.0 / (g_numShells * (g_numShells - 1))); Mesh::Vertex v = g_bunnyMeshCopy.getVertex(j); Cvec3 vPos = v.getPosition(); Cvec3 newPos = vPos + (n + (d * (i+1))); v.setPosition(newPos); v.setNormal(newPos - vPos); } uploadMeshToSimpleGeometryPNX(g_bunnyMeshCopy, *(g_bunnyShellGeometries[i]), g_hairyness); } }
static void simpleShadeCube(Mesh& mesh) { Cvec3 normal = Cvec3(0, 1, 0); for (int i = 0; i < mesh.getNumFaces(); ++i) { const Mesh::Face f = mesh.getFace(i); Cvec3 facenorm = f.getNormal(); for (int j = 0; j < f.getNumVertices(); ++j) { const Mesh::Vertex v = f.getVertex(j); v.setNormal(facenorm); } } }
static void shadeCube(Mesh& mesh) { Cvec3 normal = Cvec3(0, 0, 0); for (int i = 0; i < mesh.getNumVertices(); ++i) { mesh.getVertex(i).setNormal(normal); } for (int i = 0; i < mesh.getNumFaces(); ++i) { const Mesh::Face f = mesh.getFace(i); Cvec3 facenorm = f.getNormal(); for (int j = 0; j < f.getNumVertices(); ++j) { const Mesh::Vertex v = f.getVertex(j); v.setNormal(facenorm + v.getNormal()); } } for (int i = 0; i < mesh.getNumVertices(); ++i) { const Mesh::Vertex v = mesh.getVertex(i); if (norm2(v.getNormal()) > .001) { v.setNormal(normalize(v.getNormal())); } } }
static void updateMeshNormals(Mesh &mesh) { for (int i = 0, n = mesh.getNumVertices(); i < n; i++) { Cvec3 vectorSum = Cvec3(); Mesh::Vertex v = mesh.getVertex(i); Mesh::VertexIterator vertexIter(v.getIterator()), iterOrigin(vertexIter); // walk around the vertex do { vectorSum += vertexIter.getFace().getNormal(); } while (++vertexIter != iterOrigin); if (dot(vectorSum, vectorSum) > CS175_EPS2) { vectorSum.normalize(); } v.setNormal(vectorSum); } }