/// Interpolate animation frame from two other frames. /// /// \param src Source frame (earlier). /// \param dst Destination frame (later). /// \param current_time Animation time. void interpolateFrom(const AnimationFrame &lhs, const AnimationFrame &rhs, float current_time) { unsigned bone_count = lhs.getBoneCount(); #if defined(USE_LD) if(rhs.getBoneCount() != bone_count) { std::ostringstream sstr; sstr << "cannot interpolate between frames of size " << bone_count << " and " << rhs.getBoneCount(); BOOST_THROW_EXCEPTION(std::runtime_error(sstr.str())); } #endif //std::cout << "resizing bones or not? " << m_bones.size() << " vs " << bone_count << std::endl; m_time = current_time; m_bones.resize(bone_count); for(unsigned ii = 0; (bone_count > ii); ++ii) { const BoneState &ll = lhs.getBoneState(ii); const BoneState &rr = rhs.getBoneState(ii); float ltime = lhs.getTime(); float rtime = rhs.getTime(); float mix_time = (current_time - ltime) / (rtime - ltime); vec3 mix_pos = mix(ll.getPosition(), rr.getPosition(), mix_time); quat mix_rot = mix(ll.getRotation(), rr.getRotation(), mix_time); //std::cout << "mix time: " << mix_time << ": " << mix_pos << " ; " << mix_rot << std::endl; m_bones[ii] = BoneState(mix_pos, mix_rot); } }
void Animation::draw(ResourceLoader *resLoader, SDL_Surface *screen, AnimationInstance *ai, float x, float y) { AnimationFrame *currFrame = NULL; float cumulativeTime = 0; float timeThisFrame = 0; float timeInSeconds = ai->getComplete()*totalTime; for (int i = 0; i < numFrames; ++i) { if (timeInSeconds >= cumulativeTime) { timeThisFrame = timeInSeconds-cumulativeTime; currFrame = &(frames[i]); }else { break; } cumulativeTime += currFrame->getTime(); } if (currFrame != NULL) { for (int i = 0; i < currFrame->getEffectSize(); ++i) currFrame->getEffect(i)->setTime(timeThisFrame); for (int i = 0; i < currFrame->getNumImages(); ++i) { Pos2 *offset = currFrame->getOffset(i); resLoader->draw_image( currFrame->getImage(i), screen, x+offset->getX(), y+offset->getY(), currFrame->getEffects(), currFrame->getEffectSize()); } } //SDL_BlitSurface( resLoader->get_image(currFrame->image_type), src_rect, screen, dst_rect ); }
/// Duplicate from given frame. /// /// \param op Frame to duplicate. void duplicate(const AnimationFrame &op) { unsigned bone_count = op.getBoneCount(); m_time = op.getTime(); m_bones.resize(bone_count); for(unsigned ii = 0; (bone_count > ii); ++ii) { m_bones[ii] = op.getBoneState(ii); } }