예제 #1
0
Velocity operator+(const Velocity & lhs, const Velocity & rhs)
{
   // not a member or friend, so we need to use getters and setters

   Velocity sum;

   sum.setDx(lhs.getDx() + rhs.getDx());
   sum.setDy(lhs.getDy() + rhs.getDy());

   return sum;
}
예제 #2
0
/*************************************************
 * handles when objects hit each other
 *************************************************/
float Velocity::minimumDistance(Velocity a, Velocity  b)
{
   
   float distanceSquared;
   float minDist;
   float slice = 1 / (max(max(a.getDx(), a.getDy()   ),
                         max(b.getDx(), b.getDy())  ));
   for (float percent = 0; percent <= 100; slice++)
   {
      float distaceSquared = ((a.getX() + a.getDx() * percent) - pow((b.getX() + b.getDx() * percent),2)) +
         ((a.getY() + a.getDy() * percent) - pow((b.getY() + b.getDy() * percent),2) );
      float minDist = min(distanceSquared, minDist);
   }

   return sqrt(minDist);
}
예제 #3
0
/*************************************************
 * subtracts velocity from superman
 *************************************************/
Velocity Velocity::operator - (Velocity & v)
{
   this->dy = this->dy - v.getDy();
   this->dx = this->dx - v.getDx();
}
예제 #4
0
/*************************************************
 * adds velocity to superman
 *************************************************/
Velocity Velocity::operator + (Velocity & v)
{
   this->dy = this->dy + v.getDy();
   this->dx = this->dx + v.getDx();
}