Scaling a mesh centred anchor point (ofMesh ofScale ofTranslate)

Hi
I am trying to scale a ofMesh using as anchor point its centroid.
The mesh has a video as texture and it is not a regular shape.
I have initially tried to use pushMAtrix() ofScale() and ofTransalte()

float scalefactor = 1;
    
ofPushMatrix();
ofTranslate(-centroid);
ofScale(scalefactor,scalefactor);
video.getTextureReference().bind();
mesh.draw();
video.getTextureReference().unbind();
ofPopMatrix();

however it doesn’t keep the anchor point centred.

I then tried to multiply each vertex * the scale factor but the result was similar.

Also for some reason if the scalefactor is = 2 I get a more centred result than if it is 1.

I think I am missing some basic here…
Is anyone able to help me with this please?

THanks!

The vertices in the mesh must be relative to the centroid if you want to scale them proportionally around the centroid. For example, if you have four points in a mesh (0,0), (1,0), (1,1) and (0,1) and you want to scale them around a centroid (0.5, 0.5) then you should loop through the verts in the mesh and subtract them from the centroid,

for( int i = 0; i < mesh.getNumVertices(); i++ ) {
     mesh.getVertices()[i] = mesh.getVertices()[i] - centroid;
}

Then you can translate to the centroid and scale from there.

@NickHardeman this worked perfectly!
awesome. thanks a lot!

cheers