fixed reverse Animation looping

This commit is contained in:
viktorljung
2016-02-10 23:33:23 +01:00
parent dded296cde
commit 9c08c351b8
+14 -7
View File
@@ -31,22 +31,29 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a
double nextTime = (double)animationComponent["Time" + std::to_string(i)] + animationSpeed * dt; double nextTime = (double)animationComponent["Time" + std::to_string(i)] + animationSpeed * dt;
if (!(bool)animationComponent["Loop" + std::to_string(i)] && glm::abs(nextTime) > animation->Duration) { if (!(bool)animationComponent["Loop" + std::to_string(i)]) {
(double&)animationComponent["Time" + std::to_string(i)] = glm::sign(nextTime) * animation->Duration; if (nextTime > animation->Duration) {
nextTime = animation->Duration;
} else if (nextTime < 0) {
nextTime = 0;
}
(double&)animationComponent["Speed" + std::to_string(i)] = 0.0; (double&)animationComponent["Speed" + std::to_string(i)] = 0.0;
Events::AnimationComplete e; Events::AnimationComplete e;
e.Entity = entity; e.Entity = entity;
e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)];
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} else { } else {
if (glm::abs(nextTime) > animation->Duration) { if (nextTime > animation->Duration) {
(double&)animationComponent["Time" + std::to_string(i)] = glm::abs(nextTime) - animation->Duration; nextTime -= animation->Duration;
} else { } else if (nextTime < 0) {
nextTime += animation->Duration;
}
}
(double&)animationComponent["Time" + std::to_string(i)] = nextTime; (double&)animationComponent["Time" + std::to_string(i)] = nextTime;
} }
} }
}
}
//Calculate bone transforms //Calculate bone transforms
if (skeleton != nullptr) { if (skeleton != nullptr) {