Function animate

Synopsis

#include <Source/Falcor/Scene/Animation/Animation.h>

glm::mat4 animate(double currentTime)

Description

Compute the animation.

Parameters

time - The current time in seconds. This can be larger then the animation time, in which case the animation will loop.

Returns
Returns the animation's transform matrix for the specified time.

Source

Lines 118-160 in Source/Falcor/Scene/Animation/Animation.cpp. Line 137 in Source/Falcor/Scene/Animation/Animation.h.

glm::mat4 Animation::animate(double currentTime)
{
    // Calculate the sample time.
    double time = currentTime;
    if (time < mKeyframes.front().time || time > mKeyframes.back().time)
    {
        time = calcSampleTime(currentTime);
    }
    // Determine if the animation behaves linearly outside of defined keyframes.
    bool isLinearPostInfinity = time > mKeyframes.back().time && this->getPostInfinityBehavior() == Behavior::Linear;
    bool isLinearPreInfinity = time < mKeyframes.front().time && this->getPreInfinityBehavior() == Behavior::Linear;
    Keyframe interpolated;
    if (isLinearPreInfinity && mKeyframes.size() > 1)
    {
        const auto& k0 = mKeyframes.front();
        auto k1 = interpolate(mInterpolationMode, k0.time + kEpsilonTime);
        double segmentDuration = k1.time - k0.time;
        float t = (float)((time - k0.time) / segmentDuration);
        interpolated = interpolateLinear(k0, k1, t);
    }
    else if (isLinearPostInfinity && mKeyframes.size() > 1)
    {
        const auto& k1 = mKeyframes.back();
        auto k0 = interpolate(mInterpolationMode, k1.time - kEpsilonTime);
        double segmentDuration = k1.time - k0.time;
        float t = (float)((time - k0.time) / segmentDuration);
        interpolated = interpolateLinear(k0, k1, t);
    }
    else
    {
        interpolated = interpolate(mInterpolationMode, time);
    }
    glm::mat4 T = translate(interpolated.translation);
    glm::mat4 R = mat4_cast(interpolated.rotation);
    glm::mat4 S = scale(interpolated.scaling);
    glm::mat4 transform = T * R * S;
    return transform;
}





Add Discussion as Guest

Log in