Ejemplo n.º 1
0
int main() {
  std::vector<vec2> points;
  points.reserve(100);

  // Since we will be using the ‘smooth’ animation algorithm, we must register
  // it with the engine.
  SmoothInit::Register();

  // The engine is the central place where animation data is stored and
  // processed.
  MotiveEngine motive_engine;

  //! [Duck Example]
  // Initialize the Motivator to use the "smooth" animation algorithm.
  Motivator2f duck_position;
  duck_position.InitializeWithTarget(SmoothInit(), &motive_engine,
                                     Tar2f::Current(kDuckStartPosition));

  // Smoothly transition the duck to wherever a touch occurs.
  while (FollowDuck()) {
    vec2 touch_position;
    if (ScreenTouch(&touch_position)) {
      // Set the duck's target position, velocity, and time.
      duck_position.SetTarget(Tar2f::Target(touch_position, kZeros2f,
                                            kTimeToTouchPosition));
    }

    // Once per frame, motive_engine.AdvanceFrame() is called to animate *all*
    // Motivators at once. In this case, we only have one Motivator,
    // but in many applications there will be thousands.
    motive_engine.AdvanceFrame(kDeltaTime);

    // Draw the duck at its current position.
    // Use the velocity to draw motion lines behind the duck, too.
    DrawDuck(duck_position.Value(), duck_position.Velocity());
  }
  //! [Duck Example]
  return 0;
}