Skip to content

Commit

Permalink
Animation finished
Browse files Browse the repository at this point in the history
  • Loading branch information
gecko0307 committed Aug 15, 2024
1 parent e77322f commit 4f6626b
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions extensions/iqm/src/dagon/ext/iqm.d
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct ActorState
uint currentFrame = 0;
uint nextFrame = 1;
float t = 0.0f;
bool finished = false;
}

class Actor: Owner, Drawable
Expand All @@ -114,6 +115,7 @@ class Actor: Owner, Drawable
float speed = 1.0f;
float blendSpeed = 8.0f;
bool looping = true;
double timer = 0.0;

GLuint vao = 0;
GLuint vbo = 0;
Expand Down Expand Up @@ -196,6 +198,7 @@ class Actor: Owner, Drawable
{
model.calcBindPose(&frameData);
playing = false;
state.finished = true;
}

void switchToAnimation(string name)
Expand All @@ -204,6 +207,7 @@ class Actor: Owner, Drawable
state.currentFrame = animation.firstFrame;
state.nextFrame = state.currentFrame + 1;
state.t = 0.0f;
state.finished = false;
}

void switchToAnimationSmooth(string name, float smooth)
Expand All @@ -214,12 +218,13 @@ class Actor: Owner, Drawable
nextState.nextFrame = nextState.currentFrame + 1;
nextState.t = 0.0f;
blendSpeed = smooth;
state.finished = false;
}

void switchToSequence(uint startFrame, uint endFrame)
{
uint numFrames = endFrame - startFrame;
if (animation.firstFrame != startFrame && animation.numFrames != numFrames)
if (animation.firstFrame != startFrame && animation.firstFrame + numFrames != endFrame)
{
animation.firstFrame = startFrame;
animation.numFrames = numFrames;
Expand All @@ -229,13 +234,14 @@ class Actor: Owner, Drawable
else
state.nextFrame = state.currentFrame;
state.t = 0.0f;
state.finished = false;
}
}

void switchToSequenceSmooth(uint startFrame, uint endFrame, float smooth)
{
uint numFrames = endFrame - startFrame;
if (animation.firstFrame != startFrame && animation.numFrames != numFrames)
if (animation.firstFrame != startFrame && animation.firstFrame + numFrames != endFrame)
{
nextAnimation.firstFrame = startFrame;
nextAnimation.numFrames = numFrames;
Expand All @@ -247,6 +253,7 @@ class Actor: Owner, Drawable
nextState.nextFrame = nextState.currentFrame;
nextState.t = 0.0f;
blendSpeed = smooth;
state.finished = false;
}
}

Expand All @@ -257,6 +264,7 @@ class Actor: Owner, Drawable
state.currentFrame = animation.firstFrame;
state.nextFrame = state.currentFrame + 1;
state.t = 0.0f;
state.finished = false;
}

void play()
Expand All @@ -275,38 +283,44 @@ class Actor: Owner, Drawable
return;

model.calcFrame(state.currentFrame, state.nextFrame, state.t, &frameData);

state.t += defaultFramerate * dt * speed; //animation.framerate
state.t += defaultFramerate * speed * dt;

if (state.t >= 1.0f)
{
state.t = 1.0f;

if (looping)
state.t = 0.0f;
if (state.nextFrame != state.currentFrame)
{
state.t = 0.0f;
if (state.nextFrame != state.currentFrame)
{
state.currentFrame++;
state.nextFrame++;
state.currentFrame++;
state.nextFrame++;

if (state.currentFrame == animation.firstFrame + animation.numFrames - 1)
if (state.currentFrame == animation.firstFrame + animation.numFrames - 1)
{
if (looping)
{
state.nextFrame = animation.firstFrame;
}
else if (state.currentFrame == animation.firstFrame + animation.numFrames)
else
{
state.currentFrame = animation.firstFrame;
state.nextFrame = state.currentFrame + 1;
state.currentFrame--;
state.nextFrame = state.currentFrame;
state.finished = true;
}
}
else if (state.currentFrame == animation.firstFrame + animation.numFrames)
{
state.currentFrame = animation.firstFrame;
state.nextFrame = state.currentFrame + 1;
}
}
}

if (hasNextAnimation)
{
model.blendFrame(nextState.currentFrame, nextState.nextFrame, nextState.t, &frameData, blendFactor);
nextState.t += defaultFramerate * dt * speed; //nextAnimation.framerate
nextState.t += defaultFramerate * speed * dt;
blendFactor += blendSpeed * dt;

if (nextState.t >= 1.0f)
Expand Down

0 comments on commit 4f6626b

Please sign in to comment.