Rotating a polyline in place? (sorry if re-post)

(having some problems with the board , sorry if this was posted multiple times)

I’m trying to rotate a polyline, as part of a rudimentary vector graphics program. I want to be able to make shapes with polylines, move them, resize them, and rotate them at will.

Currently I am trying to PushMatrix and PopMatrix, and using the ofRotate function. I would like the polyline to spin in place, relative to it’s center inside of it’s bounding box. In order to do that I also used the ofTranslate function with the Rotate.

But I can’t seem to get it to work right. I don’t think I’m using translate correctly, but I’m not sure how to properly do it. I’ve tried translating via width/2 and height/2, and other variations on that. I’m working within a class, and the x,y,width and height are inherited from a parent class. Maybe I’m accidentally referencing global x and y values? Not sure.

How do I get any polyline to rotate in place?

I am also open to perhaps addressing each individual Vertex in the poly line and re-addressing it that way. I had been looking at formulas that might be useful to impliment, but I slowly tied my brain into a knot. If someone has an X-Y / point based solution for rotating a polyline at will, I would be interested in that as well.

Here is some code and some images to make things clearer:

  
ofPushMatrix();  
    //ofTranslate((width/2),(height/2));  
    ofRotate(45);  
  
  
    myPolyline.addVertex(x,y+height);  
    myPolyline.addVertex(x+(width/2),y);  
    myPolyline.addVertex(x+width,y+height);  
  
    myPolyline.close();  
  
    myPolyline.draw();  
  
ofPopMatrix();  
    	  
  
  
//draw the bounding box  
  
        ofRectangle boundingboxRect;  
        ofRectangle resizeboxRect;  
  
  
        ofSetColor(0,0,255);  
        ofNoFill();  
        boundingboxRect.x=x-2;  
        boundingboxRect.y=y-2;  
        boundingboxRect.width=width+4;  
        boundingboxRect.height=height+4;  
  
        ofRect(boundingboxRect);  
  
  
        ofSetColor(0,0,255);  
        ofFill();  
        resizeboxRect.width=boundingboxRect.width/10;  
        resizeboxRect.height=boundingboxRect.height/10;  
        resizeboxRect.x=boundingboxRect.x+(boundingboxRect.width-resizeboxRect.width);  
        resizeboxRect.y=boundingboxRect.y;  
  
        ofRect(resizeboxRect);  
  

I tried to clean up my code enough so that things could be readable. If there are unexplained variables or questions, I can clarify. I added some images of what the different states look like on my end. Probably not necessary, but might help.

Any wisdom in regards to rotating is greatly appreciated.

hi,

here is a very rough example…

  
  
ofPushMatrix();  
    ofFill();  
    ofTranslate(mouseX, mouseY);  
    ofRotateZ(ofGetFrameNum()/5);  
    ofSetColor(30, 200, 200);  
    ofBeginShape();  
    ofVertex(0, -30);  
    ofVertex(-30,30);  
    ofVertex(30, 30);  
    ofEndShape();  
    ofPopMatrix();  
    ofPushMatrix();  
    ofSetColor(255);  
    ofTranslate(mouseX, mouseY);  
    ofNoFill();  
    ofRect(-30, -30, 60, 60);  
    ofPopMatrix();