Loading anim/include/anim/animation.hpp +24 −6 Original line number Diff line number Diff line Loading @@ -189,6 +189,16 @@ namespace anim { return linear_interpolate(low, high, dt); } static vec3 linear_interpolate(double t_low, vec3 low, double t_high, vec3 high, double t) { double dt = (t - t_low) / (t_high - t_low); dt = clamp(dt, 0, 1); return vec3{ linear_interpolate(low.x, high.x, dt), linear_interpolate(low.y, high.y, dt), linear_interpolate(low.z, high.z, dt) }; } template<typename T> static double linear_interpolate(double t_low, com::Reflection::ValuePtr low, double t_high, com::Reflection::ValuePtr high, double t) { double a = static_cast<double>(as<T>(low)->value); Loading Loading @@ -393,6 +403,7 @@ namespace anim { auto low = high; if (low != m_keyframes.begin()) low--; /// TODO: first keyframe not at t == 0 if (low == high) high++; double rt = get_relative_time(low->get()->time, high->get()->time, t); Loading Loading @@ -473,12 +484,19 @@ namespace anim { // } case TypeID::VEC3: { if (dynamic_cast<Keyframe<vec3>*>(low->get())) { auto low_key = dynamic_cast<Keyframe<vec3>*>(low->get()); auto high_key = dynamic_cast<Keyframe<vec3>*>(high->get()); auto val_x = linear_interpolate(low_key->time, low_key->value.x, high_key->time, high_key->value.x, t); auto val_y = linear_interpolate(low_key->time, low_key->value.y, high_key->time, high_key->value.y, t); auto val_z = linear_interpolate(low_key->time, low_key->value.z, high_key->time, high_key->value.z, t); result = make_value<ValueVEC3>(vec3{val_x, val_y, val_z}); } else { auto low_key = dynamic_cast<CompleteKey<vec3>*>(low->get()); auto high_key = dynamic_cast<CompleteKey<vec3>*>(high->get()); result = make_value<ValueVEC3>(vec3{linear_interpolate(low_key->time, low_key->value, high_key->time, high_key->value, t)}); } break; } // case TypeID::VEC4: Loading Loading
anim/include/anim/animation.hpp +24 −6 Original line number Diff line number Diff line Loading @@ -189,6 +189,16 @@ namespace anim { return linear_interpolate(low, high, dt); } static vec3 linear_interpolate(double t_low, vec3 low, double t_high, vec3 high, double t) { double dt = (t - t_low) / (t_high - t_low); dt = clamp(dt, 0, 1); return vec3{ linear_interpolate(low.x, high.x, dt), linear_interpolate(low.y, high.y, dt), linear_interpolate(low.z, high.z, dt) }; } template<typename T> static double linear_interpolate(double t_low, com::Reflection::ValuePtr low, double t_high, com::Reflection::ValuePtr high, double t) { double a = static_cast<double>(as<T>(low)->value); Loading Loading @@ -393,6 +403,7 @@ namespace anim { auto low = high; if (low != m_keyframes.begin()) low--; /// TODO: first keyframe not at t == 0 if (low == high) high++; double rt = get_relative_time(low->get()->time, high->get()->time, t); Loading Loading @@ -473,12 +484,19 @@ namespace anim { // } case TypeID::VEC3: { if (dynamic_cast<Keyframe<vec3>*>(low->get())) { auto low_key = dynamic_cast<Keyframe<vec3>*>(low->get()); auto high_key = dynamic_cast<Keyframe<vec3>*>(high->get()); auto val_x = linear_interpolate(low_key->time, low_key->value.x, high_key->time, high_key->value.x, t); auto val_y = linear_interpolate(low_key->time, low_key->value.y, high_key->time, high_key->value.y, t); auto val_z = linear_interpolate(low_key->time, low_key->value.z, high_key->time, high_key->value.z, t); result = make_value<ValueVEC3>(vec3{val_x, val_y, val_z}); } else { auto low_key = dynamic_cast<CompleteKey<vec3>*>(low->get()); auto high_key = dynamic_cast<CompleteKey<vec3>*>(high->get()); result = make_value<ValueVEC3>(vec3{linear_interpolate(low_key->time, low_key->value, high_key->time, high_key->value, t)}); } break; } // case TypeID::VEC4: Loading