Пример #1
0
// Step button animation
void drawing_button_step_animation(Button *button, int64_t epoch_ms) {
  if (!button->ani_done) {
    // check timing of animation
    if (epoch_ms - button->click_epoch > BUTTON_ANIMATION_DURATION) {
      // pretend the last click was exactly the animation duration ago
      // this sets the points to exactly the correct places for the new button state
      button->click_epoch = epoch_ms - BUTTON_ANIMATION_DURATION;
      button->ani_done = true;
    }
    // loop through the points in the button
    for (uint8_t idx = 0; idx < ARRAY_LENGTH(button->right); idx++) {
      if (button->playing) {
        button->right[idx] = interpolation_gpoint(ButtonPauseR[idx], ButtonPlay[idx],
            epoch_ms - button->click_epoch, BUTTON_ANIMATION_DURATION, CurveSinEaseInOut);
        button->left[idx] = interpolation_gpoint(ButtonPauseL[idx], ButtonPlay[idx],
            epoch_ms - button->click_epoch, BUTTON_ANIMATION_DURATION, CurveSinEaseInOut);
      } else {
        button->right[idx] = interpolation_gpoint(ButtonPlay[idx], ButtonPauseR[idx],
            epoch_ms - button->click_epoch, BUTTON_ANIMATION_DURATION, CurveSinEaseInOut);
        button->left[idx] = interpolation_gpoint(ButtonPlay[idx], ButtonPauseL[idx],
            epoch_ms - button->click_epoch, BUTTON_ANIMATION_DURATION, CurveSinEaseInOut);
      }
    }
  }
}
Пример #2
0
// Animates the position of the stick figure skeleton
// between the last position and the current frame
void stick_figure_step_animation(StickFigure *stick_figure, int64_t epoch_ms) {
  // get end skeleton frame
  SkeletonFrame end_skeleton = skeleton_frame_data[stick_figure->pose][stick_figure->frame];
  // step the animation
  if (epoch_ms - stick_figure->frame_start >
      end_skeleton.ani_duration + end_skeleton.pause_duration) {
    // wrap back to first frame
    if (++stick_figure->frame >= end_skeleton.frame_count) {
      stick_figure->frame = 0;
    }
    // prep next for next frame
    stick_figure->frame_start += end_skeleton.ani_duration + end_skeleton.pause_duration;
    memcpy(&stick_figure->old_skeleton, &stick_figure->cur_skeleton, sizeof(SkeletonFrame));
    end_skeleton = skeleton_frame_data[stick_figure->pose][stick_figure->frame];
  }

  // step the skeleton points if in animation stage, else set them to the end point
  if (epoch_ms - stick_figure->frame_start <= end_skeleton.ani_duration) {
    // must be a better way to do this without using an array for the figure's points
    stick_figure->cur_skeleton.head = interpolation_gpoint(stick_figure->old_skeleton.head,
      end_skeleton.head, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.chest = interpolation_gpoint(stick_figure->old_skeleton.chest,
      end_skeleton.chest, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.elbow_r = interpolation_gpoint(stick_figure->old_skeleton.elbow_r,
      end_skeleton.elbow_r, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.hand_r = interpolation_gpoint(stick_figure->old_skeleton.hand_r,
      end_skeleton.hand_r, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.elbow_l = interpolation_gpoint(stick_figure->old_skeleton.elbow_l,
      end_skeleton.elbow_l, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.hand_l = interpolation_gpoint(stick_figure->old_skeleton.hand_l,
      end_skeleton.hand_l, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.waist = interpolation_gpoint(stick_figure->old_skeleton.waist,
      end_skeleton.waist, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.knee_r = interpolation_gpoint(stick_figure->old_skeleton.knee_r,
      end_skeleton.knee_r, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.foot_r = interpolation_gpoint(stick_figure->old_skeleton.foot_r,
      end_skeleton.foot_r, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.knee_l = interpolation_gpoint(stick_figure->old_skeleton.knee_l,
      end_skeleton.knee_l, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
    stick_figure->cur_skeleton.foot_l = interpolation_gpoint(stick_figure->old_skeleton.foot_l,
      end_skeleton.foot_l, (int32_t)(epoch_ms - stick_figure->frame_start),
      end_skeleton.ani_duration, end_skeleton.interp_curve);
  }
  else {
    memcpy(&stick_figure->cur_skeleton, &end_skeleton, sizeof(SkeletonFrame));
  }
}