Posted By

vaishnavi on 12/09/10


Tagged

accelerometer


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

vaishnavi
terababy
Tintenklecks
cnathan


implementing accelerometer to move objects


 / Published in: Objective C
 

motion of objects(labels and images)

  1. #define SIGN(x) ((x < 0.0f) ? -1.0f : 1.0f)
  2.  
  3. float yaccel, yvelocity;
  4.  
  5. - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
  6.  
  7. float yy = acceleration.y;
  8. float accelDirY = SIGN(yvelocity) * -1.0f;
  9. float newDirY = SIGN(yy);
  10.  
  11. if (accelDirY == newDirY)
  12. yaccel = (abs(yaccel) + 0.99f) * SIGN(yaccel);
  13.  
  14. yvelocity = -yaccel * yy;
  15. }

Report this snippet  

You need to login to post a comment.