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
angle headache (Read 529 times)
angle headache
Jun 8th, 2006, 9:49pm
 
When moving the cursor down right, the image makes a skip.. and when i print the angle values, it seems i only get between -4.1 and 1.5 .. which is a bit odd to me..
any clues?

Code:

Cursor c;
void setup()
{
size(500,200);
noCursor();
c = new Cursor(loadImage("cursor.png"));
}

void draw()
{
if(!mousePressed) background(0);
c.update(10);
c.draw();
}

class Cursor
{
PImage img;
int px, py, x, y;
float theta,ttheta;
Cursor(PImage _img)
{
img = _img;
update(1);
}

void update(int C)
{
if(!(pmouseX==mouseX && pmouseY==mouseY)){
px = pmouseX;
py = pmouseY;
x = mouseX;
y = mouseY;
ttheta = angle(x,y,px,py)-HALF_PI;
}
theta += (ttheta-theta)/C;
}

void draw()
{
stroke(255);
fill(220);
pushMatrix();
translate(x,y);
rotate(theta);
image(img,0,0);
popMatrix();
}
}

float angle(float x, float y, float px, float py)
{
float dx = px-x;
float dy = py-y;
float r = atan2(dy,dx);
return r;
}



-seltar
Re: angle headache
Reply #1 - Jun 8th, 2006, 10:27pm
 
seems like your interpolation is not taking into account that TWO_PI is the same as Zero. I turned it off and it worked fine (set C to 1). Maybe just make it check if the goal value is closer by going negative or positive and choose which direction to interpolate based on that. Hope that helps..
Page Index Toggle Pages: 1