@name keyf_test5
@inputs 
@outputs CurrentFrame AnimStepPrev AnimStep Loops FrameTime Lerp
@persist [Duration FPS FrameCount FrameTotal FrameBetween FrameBetweenTime]
@persist [CurrentFrame AnimStepPrev AnimStep Loops] [CurTime DeltaTime FrameTime] Frames:array
@trigger none


if (first()) {
    
    Duration   = 2
    FPS        = 60
    
    Frames = array(
        0 = ang(),
        1 = ang(45,0,0),
        2 = ang(90,0,0),
        3 = ang(135,0,0),
        4 = ang(90,0,0),
        5 = ang(45,0,0),
        6 = ang(0,0,0)

    )
    
    FrameCount = Frames:count()

    FrameTotal       = FPS*Duration 
    FrameBetween     = FrameTotal/FrameCount
    FrameBetweenTime = Duration/FrameCount
    
    print( FrameTotal )
    
    CurrentFrame = 0
    AnimStepPrev = 0
    AnimStep = 1
    
    CurTime = curtime()
    
    holoCreate(1)
    holoModel(1, "models/sprops/misc/origin.mdl")
    
    function number linear( Y0, Y1, T ) {
        return Y0 + T * (Y1 - Y0)
    }

    function number cosine( Y0, Y1, T ) {
        return linear( Y0, Y1, -cosr( pi() * T ) / 2 + 0.5 )
    }
    
    function number accelerate( Y0, Y1, T ) {
        return linear( Y0, Y1, T^2 )
    }
    
    function number decelerate( Y0, Y1, T ) {
        return linear( Y0, Y1, 1 - ( 1 - T )^2 )
    }

}


interval(60)

DeltaTime = curtime() - CurTime
CurTime   = curtime()

if (CurrentFrame == FrameBetween) {
    AnimStepPrev = AnimStep
    AnimStep     = (AnimStep + 1) % FrameCount
    
    if (AnimStepPrev == 0) {
        print( curtime() - FrameTime )

        FrameTime = curtime()
        Loops++    
    }
    
    CurrentFrame = 0
}

CurrentFrame = min(CurrentFrame + FPS*DeltaTime, FrameBetween)

local ILerp = CurrentFrame/FrameBetween #linear(0, 1, CurrentFrame/FrameBetween)
local Blend = slerp(quat(Frames[AnimStepPrev, angle]), quat(Frames[AnimStep, angle]), ILerp):toAngle()

holoAng(1, Blend)
