Rotate, Translate and Scale a glm::vec2

I’m working with a camera and openCV, and the camera is flipped.

Tho draw correctly the blob finder is quite simple as I rotate and translate as shown in the code. The challenge appears when I need to get the updated position of a flow field in this matrix called mat, which is a vector of glm::vec2.
The point is that I need to rotate -90 and translate the position and scale to mirror both, cur and mat.
I’ve been trying some examples but never getting the correct coordinates.
In other words, I need to get rid of

ofPushMatrix();
ofRotateZDeg(-90);
ofTranslate(-ofGetHeight(), ofGetWidth()); //x and y are inverted
ofScale(1,-1); //mirror the image
(...)
ofPopMatrix();

The code is the following:

   ofPushMatrix();
    ofRotateZDeg(-90);
    ofTranslate(-ofGetHeight(), ofGetWidth()); //x and y are inverted
    ofScale(1,-1); //mirror the image
    
    ofSetLineWidth(1.0);
    for(int y=0; y < 90; y+=2) {
        for(int x=0; x < 160; x+=2) {
            glm::vec2 cur = glm::vec2(x, y) * scale;
            ofDrawLine(cur, mat.at(i));
            i++;
        }
    }
    ofPopMatrix();

you can use either a 2d affine matrix (mat3), or a 3d affine matrix (mat4).
in your case they will look like this:

 r11 r12 dx
 r21 r22 dy
 0   0   1
 
 or
 
 r11 r12 0 dx
 r21 r22 0 dy
 0   0   1 0
 0   0   0 1

the rxx vectors hold your rotation matrix. dx and dy hold your translations. the scaling part is multiplied on top of the entire rows. the idea is to build this matrix once, and then do glm::vec2 cur = mat*glm::vec2(x,y)

neither code will work (because those exact commands don’t exist), but you can either build your matrix by multiplying different matrices together:

auto mat = rotation_matrix_z(90) * translation_matrix_xy(-height,width) * scale_matrix_xy(1,-1)

or, because it’s kinda simple in this case, you might be able to just guess the entire matrix from scratch:

auto mat = matrix3(
  0, // r11 = cos(-90) = 0
  1, // r21 = -sin(-90) = --1 = 1
  -height, // dx = -height
 1, // r21 = sin(-90)*-1 = --1 = 1
 0, // r22 = cos(-90)*-1 = 0
 -width, // dy = width*-1 = -width
 0, // fill up the lower
 0, // row with
 1 // identity
);

either way, now that you have your matrix you should finally be able to do glm::vec2 cur = mat*glm::vec2(x,y). i don’t use glm much, maybe you have to do something like glm::vec2 cur = (mat*glm::vec3(x,y,1)).xy;

sorry for my hasty reply, hope it helps. here is a short explanation on 2d affine matrices:

overal: using 2d affine matrices (mat3) is not something i see used a lot. in this case i wouldn’t worry about using a 3d affine matrix (mat4), which is certainly much more normal and better supported.