2
0

AnimationEvent.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (C) 2009-2022, 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. AnimationEvent::AnimationEvent(EventManager* manager)
  11. : Event(manager)
  12. {
  13. }
  14. Error AnimationEvent::init(const AnimationResourcePtr& anim, SceneNode* movableSceneNode)
  15. {
  16. ANKI_ASSERT(movableSceneNode);
  17. m_anim = anim;
  18. Event::init(m_anim->getStartingTime(), m_anim->getDuration());
  19. m_reanimate = true;
  20. m_associatedNodes.emplaceBack(getAllocator(), movableSceneNode);
  21. return Error::NONE;
  22. }
  23. Error AnimationEvent::update([[maybe_unused]] Second prevUpdateTime, [[maybe_unused]] Second crntTime)
  24. {
  25. Vec3 pos;
  26. Quat rot;
  27. F32 scale = 1.0;
  28. m_anim->interpolate(0, crntTime, pos, rot, scale);
  29. Transform trf;
  30. trf.setOrigin(pos.xyz0());
  31. trf.setRotation(Mat3x4(Vec3(0.0f), rot));
  32. trf.setScale(scale);
  33. MoveComponent& move = m_associatedNodes[0]->getFirstComponentOfType<MoveComponent>();
  34. move.setLocalTransform(trf);
  35. return Error::NONE;
  36. }
  37. } // end namespace anki