I have the following code from the Creative Coding Demystified book, but it gives me an error in Xcode:
I don’t understand this, since I use gym::vec3 for norm.
void setNormals( ofMesh &mesh ){
//The number of the vertices
int nV = mesh.getNumVertices();
//The number of the triangles
int nT = mesh.getNumIndices() / 3;
vectorglm::vec3 norm( nV ); //Array for the normals
//Scan all the triangles. For each triangle add its
//normal to norm’s vectors of triangle’s vertices
for (int t=0; t<nT; t++) {
//Get indices of the triangle t
int i1 = mesh.getIndex( 3 * t );
int i2 = mesh.getIndex( 3 * t + 1 );
int i3 = mesh.getIndex( 3 * t + 2 );
//Get vertices of the triangle
const ofPoint &v1 = mesh.getVertex( i1 );
const ofPoint &v2 = mesh.getVertex( i2 );
const ofPoint &v3 = mesh.getVertex( i3 );
//Compute the triangle’s normal
ofPoint dir = ( (v2 - v1).crossed( v3 - v1 ) ).normalized();
//Accumulate it to norm array for i1, i2, i3
norm[ i1 ] += dir;
norm[ i2 ] += dir;
norm[ i3 ] += dir;
}
//Normalize the normal’s length
for (int i=0; i<nV; i++) {
norm[i] = glm::normalize(norm[i]);
}
//Set the normals to mesh
mesh.clearNormals();
mesh.addNormals(norm);
}
Blockquote
Undefined symbols for architecture x86_64:
“ofApp::setNormals(ofMesh_<glm::vec<3, float, (glm::qualifier)0>, glm::vec<3, float, (glm::qualifier)0>, ofColor_, glm::vec<2, float, (glm::qualifier)0> >&)”, referenced from:
ofApp::update() in ofApp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Blockquote