On Sep 12, 2012, at 5:09 AM, iQue <[email protected]> wrote:
> 
> this gives a weird result where 90% of the time the "stick" will set its 
> position to 0,0 when I try to use it. 
> 

Yup, I made a huge mistake there. Here's revised code;

Point imageCenter = new Point(25, 25);
Point touchPos = new Point(5, 5);
int dx = touchPos.x - imageCenter.x;
int dy = touchPos.y - imageCenter.y;
float distance = FloatMath.sqrt(dx * dx + dy * dy);
                        
final float radius = 25.0f;
if (distance > radius) {
        touchPos.x = imageCenter.x + (int)(dx * radius / distance);
        touchPos.y = imageCenter.y + (int)(dy * radius / distance);
}

Don't know what I was thinking about earlier...

--
H

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to