Rotate a mesh around a point

I am rotating meshes with a 4x4 matrix I manipulate with a GUI, here is my manipulation code:

from my .h file:

  ofParameterGroup params;
    ofParameter <bool> drawOn;
    ofParameter <glm::vec3> translationCoarseVec;
    ofParameter <glm::vec3> translationFineVec;
    ofParameter <float> rotationCoarseX, rotationCoarseY, rotationCoarseZ, rotationFineX, rotationFineY, rotationFineZ;
    
    void translationCoarseVecChanged(glm::vec3 & _translationCoarseVec);
    void translationFineVecChanged(glm::vec3 & _translationFineVec);
    void rotationCoarseXChanged(float & _rotationX);
    void rotationCoarseYChanged(float & _rotationY);
    void rotationCoarseZChanged(float & _rotationZ);
    void rotationFineXChanged(float & _rotationX);
    void rotationFineYChanged(float & _rotationY);
    void rotationFineZChanged(float & _rotationZ);
  
    ofMatrix4x4 rotationXMatrix;
    ofMatrix4x4 rotationYMatrix;
    ofMatrix4x4 rotationZMatrix;
    ofMatrix4x4 drawMatrix;
    ofMatrix4x4 translationMatrix;

    ofMatrix4x4 getDrawMatrix();
     void calcuateDrawMatrix();

And my .cpp file

void apopManipulator::translationCoarseVecChanged(glm::vec3 & _translationCoarseVec){
    if(isRealsense){
        translationMatrix.setTranslation(translationCoarseVec.get()/1000 + translationFineVec.get()/1000);

    }
    else{
        translationMatrix.setTranslation((translationCoarseVec.get() + translationFineVec.get()));

    }
    calcuateDrawMatrix();
}
void apopManipulator::translationFineVecChanged(glm::vec3 & _translationFineVec){
    if(isRealsense){
        translationMatrix.setTranslation((translationCoarseVec.get()/1000 + translationFineVec.get()/1000));

    }
    else{
        translationMatrix.setTranslation((translationCoarseVec.get() + translationFineVec.get()));
    }
    calcuateDrawMatrix();
    
}

void apopManipulator::rotationCoarseXChanged(float & _rotationCoarseX){
    ofQuaternion tq;
    tq.makeRotate(rotationCoarseX + rotationFineX, 1, 0, 0);
    rotationXMatrix.setRotate(tq);
    calcuateDrawMatrix();
}
void apopManipulator::rotationCoarseYChanged(float & _rotationCoarseY){
    ofQuaternion tq;
    tq.makeRotate(rotationCoarseY + rotationFineY, 0, 1, 0);
    rotationYMatrix.setRotate(tq);
    calcuateDrawMatrix();
}
void apopManipulator::rotationCoarseZChanged(float & _rotationCoarseZ){
    ofQuaternion tq;
    tq.makeRotate(rotationCoarseZ + rotationFineZ, 0, 0, 1);
    rotationZMatrix.setRotate(tq);
    calcuateDrawMatrix();
}



void apopManipulator::rotationFineXChanged(float & _rotationFineX){
    ofQuaternion tq;
    tq.makeRotate(rotationCoarseX + rotationFineX, 1, 0, 0);
    rotationXMatrix.setRotate(tq);
    calcuateDrawMatrix();
    
}
void apopManipulator::rotationFineYChanged(float & _rotationFineY){
    ofQuaternion tq;
    tq.makeRotate(rotationCoarseY + rotationFineY, 0, 1, 0);
    rotationYMatrix.setRotate(tq);
    calcuateDrawMatrix();
}
void apopManipulator::rotationFineZChanged(float & _rotationFineZ){
    ofQuaternion tq;
    tq.makeRotate(rotationCoarseZ + rotationFineZ, 0, 0, 1);
    rotationZMatrix.setRotate(tq);
    calcuateDrawMatrix();
}
ofMatrix4x4 apopManipulator::getDrawMatrix(){
    return drawMatrix;
}
 

void apopManipulator::calcuateDrawMatrix(){
        drawMatrix = rotationXMatrix * rotationYMatrix * rotationZMatrix * translationMatrix;
}

It seems to work ok, I can move things around, but I am not sure if I am combining the matricies in the correct way in my calcuateDrawMatrix() method - for posterity:

void apopManipulator::calcuateDrawMatrix(){
        drawMatrix = rotationXMatrix * rotationYMatrix * rotationZMatrix * translationMatrix;
}

Things get complicated after I translate the mesh and try to adjust its rotation, it seems as though the mesh is being rotated from its origin point and not relative to its translated position.

Is this approach problematic? Is there a good way or does someone have an example of how to manipulate an ofMatrix4x4 with a gui in a more sensible way?

Setting the translation is not so hard, but as soon as I rotate then the translation is affected and vice versa, making subtle movements quite difficult. How can I make sure that once I have translated the mesh I am rotating around a known point?

Hey I’m wondering if what you are trying to do is generally in oF with ofNode. If your meshes are 3dPrimitives, you can use ofNode with them. It has some functions for setting/getting global orientation, position, scale, etc that might be useful. The apopManipulator class could inherit from ofNode if you need to build it out in a specific way. Sorry if I am way off base.