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 & HelpPrograms › Rotating an image to pre-set positions
Page Index Toggle Pages: 1
Rotating an image to pre-set positions (Read 902 times)
Rotating an image to pre-set positions
Jun 15th, 2008, 2:28pm
 
Hi
I'm doing a project where I'm using a WiTilt sensor to control the rotation of an image.
I've defined 8 positions for the WiTilt and then want to rotate the image accordingly.
So I need the image to rotate(with animation of the rotation) to a specific position.

Can anyone help me on how to do so?

(How can I post my code - it's to long?)
Re: Rotating an image to pre-set positions
Reply #1 - Jun 16th, 2008, 10:49am
 
I would do something like this (extend the PImage class) :

Quote:
class RotatingImage extends PImage {
 
 float angle;
 float angleToReach;
 boolean mustBeRotated;
 float rotationStep;
 
 void setAngleToReach(float angleToReach, int direction) {
   // set the rotationStep depending on direction and angle to reach
   // set mustBeRotated to true

 }
 
 void rotateIfNeeded(float angle) {
   // if the angleToReach has been reached, stop (mustBeRotated = false)
   // otherwise, increase the angle using the rotationStep value

 }
 
 void display() {
   // rotate before display
   pushMatrix();
   rotate(angle);
   image(this, 0, 0);
   popMatrix();
 }
 
}


When your image needs to be rotated to a specific position (angle), call setAngleToReach().

Then, in the draw loop, call :
Code:
void draw() {
...
myRotatingImage.rotateIfNeeded();
myRotatingImage.display();
}

Page Index Toggle Pages: 1