We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › rotate several object on their geometric center
Page Index Toggle Pages: 1
rotate several object on their geometric center (Read 1272 times)
rotate several object on their geometric center
Sep 5th, 2009, 11:59pm
 
Hello,

i try to rotate 3 svg graphics individually but all I can get is the full-screen rotating on its center.

Here is the simplified code :

Code:

 RotatingStar myStar1;
 RotatingStar myStar2;

void setup()
{
 

 myStar1 = new RotatingStar(color(255,0,0),0,100,2);
 myStar2 = new RotatingStar(color(0,0,255),0,10,1);

}
void draw()
{  


 background(bgColor);
 myStar1.move();
 myStar1.display();
 myStar2.move();
 myStar2.display();
 

 
}

class RotatingStar {
 
 
 
 color c;
 float xpos;
 float ypos;
 float xspeed;

 // The Constructor is defined with arguments.
 
 RotatingStar(color tempC, float tempXpos, float tempYpos, float tempXspeed) {
   c = tempC;
   xpos = tempXpos;
   ypos = tempYpos;
   xspeed = tempXspeed;
 }

 void display() {
   shape(wheel0, xpos,ypos, wheelWidth, wheelHeight);
 }

 void rotation() {
   
   angle=angle+0.1;
   rotate(angle); // here is the rotate()

 }
 

   
 
 
}

Does anyone have a clue for this ?

Should I use matrix ou several PGraphics ?
Re: rotate several object on their geometric center
Reply #1 - Sep 6th, 2009, 2:19am
 
A bit too simplified, we don't know what is wheel0 (but we can guess...).

You can load the SVG graphic into each RotatingStart and use ps.rotate() on each, for independent rotations. Which is on their center if you use shapeMode(CENTER);

Or just use pushMatrix() / popMatrix() around the global rotate(), to make each one rotating independently of the others, along with translate() to rotate the shapes around an arbitrary point.
Re: rotate several object on their geometric center
Reply #2 - Sep 6th, 2009, 8:18pm
 
Thanks for the explanations !
Page Index Toggle Pages: 1