title: Iphone 2d game - Applying Gravity , Bounce issue
body: <p>Am a flash game developer at present I started writing games for iphone using cocos 2d engine, I have implemented separate Axis theorem for collision detection which works perfect.  All the polygons are drawn as follows in openGl. 
  Now am trying to apply gravity to this 16x16 box after many search I found this tutorial <a href="http://www.seinia.com/tutorials/Bounce/" rel="nofollow">http://www.seinia.com/tutorials/Bounce/</a> and implemented the same in objective C. </p>
  
  <p>The problem am having is after the square comes to rest it keeps bouncing up/down in fractions. I tried a lot to fix this but I couldn't control that tiny movement.I never had such problem in flash but here the floating value is affecting the square position a lot. </p>
  
  <p>Please let me know what is the write way to handle such issue , any reference URL would be helpful. Appriciated your help.Thanks! </p>
  
  <pre><code>0,16        16,16 
  
   ------------
  |            |
  |            |
  |            |
  |            |       
   ------------
  
  0,0          16,0
  </code></pre>
  
  <p>Objective C code</p>
  
  <pre><code>if (square.points[0].y &lt;= 0.1f) {
          velocity.vy *= -bounce;
          [square restInPeace:[Vector2D createVectorWithComponentX:velocity.vx Y:8.0f]];
          // landed
          if (fabs(velocity.vy) &lt; 0.9f) {
              velocity.vy = 0.0f;
              [square restInPeace:[Vector2D createVectorWithComponentX:velocity.vx Y:8.0f]];
              isLanded = YES;
          }   
      } 
  </code></pre>
  
  <p><strong>Translate the object</strong></p>
  
  <pre><code>-(void) translateVelocity:(Vector2D*)velocity
  {   
      // The center as well as all of the vertices need to be
      // accommodated.
      center.x += velocity.vx;
      center.y += velocity.vy;
  
      for(int i=0; i &lt; count; i++)
      {
          points[i].x += velocity.vx;
          points[i].y += velocity.vy;
  
          ////NSLog(@"velocity %f %f",points[i].x , points[i].y);
      }
  }
  </code></pre>