# How to convert ofVec2f in glm::vec2?

Hi, I’ve tried to replace ofVec2f with glm::vec2 but I can’t get the rotation method. Does anyone know how to solve it?

``````glm::vec<2, float> mousePos(ofGetMouseX(), ofGetMouseY());

int numTriangoles = 10;
int minOffset = 5;
int maxOffest = 70;
int alpha = 20;

if (ofGetMousePressed(OF_MOUSE_BUTTON_LEFT)) {
//ON MOUSE PRESSED
/* ____________________________________________________________________ */
for(int triangleInstance=0; triangleInstance<numTriangoles; triangleInstance++){
float offsetDistance = ofRandom(minOffset, maxOffest);
float transparency = 40;
float brushWidth = 0.45;
// tried to use glm::vec2 and vector<glm::vec2>(don't remember exactly), but it didn't work
ofVec2f p1(0., 25.*brushWidth);
ofVec2f p2(100*brushWidth, 0);
ofVec2f p3(0, -25.0*brushWidth);

float rotation = ofRandom(360.0);
p1.rotate(rotation);
p2.rotate(rotation);
p3.rotate(rotation);

ofVec2f triangleoffset(offsetDistance);
p1 += mousePos;
p2 += mousePos;
p3 += mousePos;
``````

You can probably convert from `ofVec2f` to `glm::vec2` like this:

``````glm::vec2 new_p1 = glm::vec2(p1.x, p1.y);
``````

Thanks. At least I have no error on that part.

``````glm::vec2 p1 = glm::vec2(p1.x, p1.y);
p1.x = 0.;
p1.y = 25.*brushWidth;
glm::vec2 p2 = glm::vec2(p1.x, p1.y);
p2.x = 100*brushWidth;
p2.y = 0.;
glm::vec2 p3 = glm::vec2(p1.x, p1.y);
p3.x = 0.;
p3.y = -25.*brushWidth;

//             ofVec2f p1(0., 25.*brushWidth);
//             ofVec2f p2(100*brushWidth, 0);
//             ofVec2f p3(0, -25.0*brushWidth);

// on the following block I still have this error though `No member named 'rotate' in 'glm::vec<2, float, glm::packed_highp>' `
float rotation = ofRandom(360.0);
p1.rotate(rotation);
p2.rotate(rotation);
p3.rotate(rotation);
``````

Any thought about that?

`rotate()` is a property/class method of `ofVec2f` . `glm::vec2` has no such functionality, see here. Either convert your vectors after the rotation or use something like `glm::rotate()` , which takes a `glm::vec2` and an angle in radians, see here.

1 Like

https://glm.g-truc.net/0.9.8/index.html