Dorald
December 24, 2020, 4:30pm
#1
Hi, I have the following code :
float rotate;
glm::vec2 center;
glm::vec2 radius;
void ofApp::draw(){
rotate++;
ofPushMatrix();
ofTranslate(ofGetMouseX(), ofGetMouseY());
ofRotateZDeg(rotate);
ofDrawCircle(center, glm::distance(center, radius));
ofPopMatrix();
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
radius = glm::vec2(x,y);
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
center = glm::vec2(x,y);
}
What I want to achieve is that circle to rotate around center.
danb
December 26, 2020, 2:05pm
#2
that’s what this appears to do when i run the code - do you mean that the circle is centred and spins ‘on’ the
center
or rotates around
center
Dorald
December 26, 2020, 2:09pm
#3
I mean spins on its center.
danb
December 26, 2020, 3:15pm
#4
aha !
ofDrawCircle(0,0, glm::distance(center, radius));
translate to where you want the circle drawn then draw at 0,0 (as this is now the centre of where you want it after the pushMatrix…
in the example you keep recentreing based on mousex & mouseY so it will keep moving where the circle is drawn but the circle will rotate on it;s own centre now.
1 Like
Dorald
December 26, 2020, 3:21pm
#5
Thank you I missed the 0,0 coordinates