2
0

AnimationEvent.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Scene/Events/AnimationEvent.h>
  6. #include <AnKi/Scene/SceneNode.h>
  7. #include <AnKi/Scene/Components/MoveComponent.h>
  8. #include <AnKi/Resource/ResourceManager.h>
  9. namespace anki
  10. {
  11. AnimationEvent::AnimationEvent(EventManager* manager)
  12. : Event(manager)
  13. {
  14. }
  15. Error AnimationEvent::init(const AnimationResourcePtr& anim, SceneNode* movableSceneNode)
  16. {
  17. ANKI_ASSERT(movableSceneNode);
  18. m_anim = anim;
  19. Event::init(m_anim->getStartingTime(), m_anim->getDuration());
  20. m_reanimate = true;
  21. m_associatedNodes.emplaceBack(getAllocator(), movableSceneNode);
  22. return Error::NONE;
  23. }
  24. Error AnimationEvent::update(Second prevUpdateTime, Second crntTime)
  25. {
  26. Vec3 pos;
  27. Quat rot;
  28. F32 scale = 1.0;
  29. m_anim->interpolate(0, crntTime, pos, rot, scale);
  30. Transform trf;
  31. trf.setOrigin(pos.xyz0());
  32. trf.setRotation(Mat3x4(Vec3(0.0f), rot));
  33. trf.setScale(scale);
  34. MoveComponent& move = m_associatedNodes[0]->getFirstComponentOfType<MoveComponent>();
  35. move.setLocalTransform(trf);
  36. return Error::NONE;
  37. }
  38. } // end namespace anki