Rotate around a Center Point
in
Programming Questions
•
2 years ago
Hello I have the following class and what I am trying to do is rotate the circle and square around the center point.
Please help.
- class arrow {
- float x;
- float y;
- float a;
- float iAlpha;
- float scaleUpF = 1.01;
- float scaleDownF = 0.99;
- float fRotation;
- float vx = 0;
- arrow (float cX, float cY, float cA, float ciAlpha) {
- x= cX;
- y= cY;
- a= cA;
- iAlpha = ciAlpha;
- fRotation = 0;
- vx = 0;
- }
- void display () {
- pushMatrix();
- translate(width/2+x+vx, height/2+x+vx);
- fill(170,170,170,iAlpha);
- rotate( radians(fRotation) );
- rect (x + vx,y ,3*a,a);
- ellipse(x + vx, y, 5 ,5 );
- // x1 y1, x2 y2, x3 y3
- triangle (x+vx+(1.5*a), -a, x+vx+(1.5*a), a, vx+x+4*a, y);
- popMatrix();
- }
- void checkKey()
- {
- if(keyPressed == true && key == 's' || key == 'S') {
- a *= scaleUpF;
- }
- if(keyPressed == true && key == 'x' || key == 'X') {
- a *= scaleDownF;
- }
- if(keyPressed == true && key == 'a' || key == 'A')
- {
- iAlpha *= scaleUpF;
- }
- else if(keyPressed == true && key == 'z' || key == 'Z')
- {
- iAlpha *= scaleDownF;
- }
- else if(keyPressed == true && key == CODED && keyCode == LEFT) {
- fRotation += scaleUpF;
- }
- else if(keyPressed == true && key == CODED && keyCode == RIGHT)
- {
- fRotation -= scaleUpF;
- }
- else if(keyPressed == true && key == CODED && keyCode == UP)
- {
- vx += 1;
- }
- else if(keyPressed == true && key == CODED && keyCode == DOWN)
- {
- vx -= 1;
- }
- }
- void keyReleased() {
- if( vx > 0) vx = 0;
- }
- }
1