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 › rotation smoothing
Page Index Toggle Pages: 1
rotation smoothing (Read 270 times)
rotation smoothing
Dec 8th, 2008, 1:40am
 

hey, i'm trying to get an arrow to point from the center towards a cursor ... with smoothing (that's the problematic part)

of course, there's the dreadful moment when the angle goes from 0 and 315 and the arrow rotates 315 degrees forward instead of -45 degrees.

is there a good way to determine the shortest rotation amt?

something like this?

if((destAngle-currentAngle) > 180) { destAngle -= 360; };
if((destAngle-currentAngle) <= -180) { destAngle += 360; };

currentAngle = (currentAngle * 0.8) + (destAngle * 0.2);

thanks++

Re: rotation smoothing
Reply #1 - Dec 12th, 2008, 1:08pm
 
The way I'd do this is with vectors.

Get the right vector of the direction you are currently pointing:

Vec vRight;
vRight.x = sin(ang+90);
vRight.y = cos(ang+90);


Get the vector of the direction you want to point at and normalise:

Vector vAim;
vAim.x = targetx - myx;
vAim.y = targety - myy;
vAim.normalise();

Compute the dot product. A value of <1 means left, a value of >1 means right:

float turnSpeed;
turnSpeed = currentAngle-destAngle * sign(dot(vAim, vRight)) * 0.5;
Page Index Toggle Pages: 1