objective c - iPhone wheel (of fortune) rotation momentum -



objective c - iPhone wheel (of fortune) rotation momentum -

i'm having difficulties adding momentum spinning wheel. have wheel (something this) , i'm rotating around it's center using single touch event. no problems here, when touch (aka drag) ends; want wheel maintain it's momentum , ease out it's movement. can give me pointers, doesn't have in objective-c. as3, javascript or java sufficient.

* update (code rotating wheel) *

-(void)touchesbegan:(nsset *)touches withevent:(uievent *)event { rotation = _startangle = atan2(384 - touchpoint.y, 512 - touchpoint.x); }; -(void)touchesmoved:(nsset *)touches withevent:(uievent *)event { cgpoint touchpoint = [[touches anyobject] locationinview:self.view]; rotation = atan2(384 - touchpoint.y, 512 - touchpoint.x); rotation = fmod(rotation - _startangle, m_pi * 2.0f); [wheel settransform:cgaffinetransformmakerotation(_circlerotationoffset + rotation)]; }; -(void)touchesended:(nsset *)touches withevent:(uievent *)event { _circlerotationoffset = fmod(_circlerotationoffset + rotation, m_pi * 2); };

you want momentum cut down due friction; friction forcefulness that's function of velocity. technically you've got differential equation going on. that's not worth investing much thought though, because solution more reached hand waving.

so: store current angle , current angular velocity. n times sec (probably via nstimer or cadisplaylink) add together angular velocity angle, multiply angular velocity create smaller — such 0.995. constants closer 1.0 create take longer slow down; if go above 1.0 it'll accelerate. form of euler integration but, again, it's not worth worrying about.

it's perchance worth putting minimum cap on angular velocity if drops below, 0.01 radians/second snap downwards 0. modifies model of friction jump kinetic static friction @ opportune moment, , acts floating point precision buffer zone.

to initial velocity drag can work out vector centre of wheel start of drag, rotate vector 90 degrees, dot product , drag vector , scale according distance centre.

iphone objective-c touch angular-momentum

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -