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.
Page Index Toggle Pages: 1
Rotation center (Read 359 times)
Rotation center
Nov 24th, 2008, 4:43am
 
Hi,

I want to rotate an image, but I don´t want to rotate the image around it´s relative position to the origin. How can I change the rotation center?? the origin???

thanks for your help...

Alexa
Re: Rotation center
Reply #1 - Nov 24th, 2008, 5:02am
 
http://processing.org/reference/imageMode_.html
Re: Rotation center
Reply #2 - Nov 24th, 2008, 11:11am
 
In more general terms, to rotate any object about its centre, you need to translate its centre to the origin, perform the rotation and translate back again. If you want to transform more than one object in your sketch, you will also probably need to store a copy of the transformation matrix before you do the rotation and then restore it when finished - this stops other objects from being moved at the same time.

Here is a simple example:

Quote:
void setup()
{
  size(400,400);
  smooth();
  ellipseMode(CENTER);
  noLoop();
}

void draw()
{
  background(255);
  int xLocation = width/2;
  int yLocation = height/2;
  
  pushMatrix();      // Store the current transformation settings.
  translate(xLocation,yLocation);
  rotate(radians(30));
  ellipse(0,0,100,50);
  popMatrix();      // Restore the previous transformation settings.
}


Note that when performing multiple transformations, they are specified in the opposite order to that which you might expect. So reading from the bottom of the example up, ellipse(0,0,100,50) does the translation to the origin, rotate() does the rotation and translate() does the translation back to the object's centre position.
Page Index Toggle Pages: 1