# No member named 'getNormalized' in glm::vec3

I’m working from the ‘Mastering openFrameworks: Creative Coding Demystifies’ where I’m trying to compute normals for the mesh.

The problem I’m facing is that with the line:

``````norm[i].getNormalized();
``````

I am getting the error:

``````No member named 'getNormalized' in 'glm::tvec3<float, glm::packed_highp>'
``````

I have looked on other threads and this error doesn’t come up with the fixed issues. Any help would be great, I’m going insane.

Full setNormals() section:

``````void setNormals( ofMesh &mesh ){

//The number of the vertices
int nV = mesh.getNumVertices();

//The number of the triangles
int nT = mesh.getNumIndices() / 3;

vector<glm::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).getCrossed( v3 - v1 ) ).getNormalized();

//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].getNormalized();
}

//Set the normals to mesh
mesh.clearNormals();
``````

}

Hi. Since version 0.10, openFrameworks officially moved to use GLM (openGL vector maths library) as its standard, instead of the previous own vector maths classes and functions.
ofVec3f is compatible with glm::vec3 in terms of auto converting from one to the other but glm is function based instead of ofVec* which is method based.
Arturo made this nice post explaning so.

but then, the short answer is change:

``````   //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).getCrossed( v3 - v1 ) ).getNormalized();

``````

for

``````   //Get vertices of the triangle
const glm::vec3 &v1 = mesh.getVertex( i1 );
const glm::vec3 &v2 = mesh.getVertex( i2 );
const glm::vec3 &v3 = mesh.getVertex( i3 );

//Compute the triangle's normal
glm::vec3 dir = glm::normalize(glm::cross( v2 - v1,  v3 - v1 ));

``````

and also change

``````//Normalize the normal's length
for (int i=0; i<nV; i++) {
norm[i].getNormalized();
}
``````

for

``````//Normalize the normal's length
for (int i=0; i<nV; i++) {
norm[i] = glm::normalize(norm[i]);
}
``````

hope this helps

3 Likes

Great help! Thank you for all the information

good hints. glm::normalize() seems not to check for passing a zero length vector, so this needs a check beforehand. ofVec2f did perform such a zero length check.

if (glm::length2(First) > 0.0) First = glm::normalize(First); // First.length() crashes as well…

Thanks for this hint. `First.length()` returns the number of elements in the vector, so glm::vec3 will always return 3. Thus it will always pass the test.

thanks @roymacdonald . I assume there lie some code bombs in using glm as a direct replacement for ofVecXf

yes.

That’s the nastiest one.

although, I think it is the only (or maybe one of few) functions that the `glm` classes have. This means, that all the functions you can run on glm are non-class functions. So the checking out the direct replacement of `ofVec*f` to `glm::vec*` can be carried out by some regex search.