@name keyf_test2
@inputs
@outputs
@persist CurFrame FrameInStep AnimStepPrev AnimStep Anim:table CurTime DeltaTime
@trigger none

#[

local duration = 1               -- animation duration
local fps      = 30              -- frames per second
local framec   = 4               -- total keyframes
local framet   = fps*duration    -- total real frames
local frameb   = framet/framec   -- transition frames
local tweent   = duration/framec -- time between keyframes

print( framet, frameb, "\n\n" )
print( tweent )

local currentFrame    = 0
local animateStepPrev = 0
local animateStep     = 1

while animateStepPrev < framec - 1 do

    if currentFrame == frameb then

        currentFrame    = 0
        animateStepPrev = animateStep
        animateStep     = (animateStep + 1) % framec

    end

    currentFrame = math.min( currentFrame + 1, frameb ) -- need to find proper increment value

    --print( currentFrame )
end

]#

if (first()) {
    AnimStepPrev = 0
    AnimStep = 1

    CurFrame = 0
    FrameInStep = 30 #tweened frames per interval

    Anim = table(
        0 = ang(),
        1 = ang(45,0,0),
        2 = ang(90,0,0),
        3 = ang(135,0,0),
        4 = ang(135,90,0)
    )

    holoCreate(1)
    holoModel(1, "models/sprops/misc/origin.mdl")

    CurTime = curtime()
}

interval(60)

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

if (CurFrame == FrameInStep) {
    CurFrame = 0
    AnimStepPrev = AnimStep
    AnimStep = (AnimStep + 1) % Anim:count()
}
#CurFrame = min(CurFrame + 60*DeltaTime, FrameInStep)
CurFrame = min(CurFrame + 1, FrameInStep)

Off = (Anim[AnimStep, angle] - Anim[AnimStepPrev, angle]) * (CurFrame / FrameInStep) + Anim[AnimStepPrev, angle]

holoAng(1, Off)

#[

	for(int i=0;i<6;i++){

		//Set colors of the vertices
		if(fillorder[i]==0 || fillorder[i]==3){
			glColor3f(0.31,0.01,0.01);
		}
		else{
			glColor3f(0.64,0.01,0.01);
		}
		//compute to x and y offsets caused by linear interpolation
		//xOff = (x2 - x1)* (currframe/framesneeded)
	   float xOff = ((xKey[fillorder[i]][animstep] - xKey[fillorder[i]][animstepprev]) * (float)(((float)currframe) / ((float)framesinstep))) + xKey[fillorder[i]][animstepprev];
	   float yOff = ((yKey[fillorder[i]][animstep] - yKey[fillorder[i]][animstepprev]) * (float)(((float)currframe) / ((float)framesinstep))) + yKey[fillorder[i]][animstepprev];

	   //The actual vertex calls
	   glVertex2f(xCo[fillorder[i]]+x+xOff,yCo[fillorder[i]]+y+yOff);
	}]#
