JitterMoveEvent.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2009-present, 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/JitterMoveEvent.h>
  6. #include <AnKi/Scene/SceneNode.h>
  7. #include <AnKi/Util/Functions.h>
  8. namespace anki {
  9. JitterMoveEvent::JitterMoveEvent(Second startTime, Second duration, SceneNode* node)
  10. : Event(startTime, duration)
  11. {
  12. if(!ANKI_EXPECT(node))
  13. {
  14. markForDeletion();
  15. return;
  16. }
  17. m_associatedNodes.emplaceBack(node);
  18. m_originalPos = node->getWorldTransform().getOrigin().xyz;
  19. }
  20. void JitterMoveEvent::setPositionLimits(Vec3 posMin, Vec3 posMax)
  21. {
  22. for(U32 i = 0; i < 3; i++)
  23. {
  24. m_newPos[i] = getRandomRange(posMin[i], posMax[i]);
  25. }
  26. m_newPos[3] = 0.0;
  27. m_newPos += m_originalPos;
  28. }
  29. void JitterMoveEvent::update([[maybe_unused]] Second prevUpdateTime, Second crntTime)
  30. {
  31. SceneNode* node = m_associatedNodes[0];
  32. Transform trf = node->getLocalTransform();
  33. const F32 factor = F32(sin(getDelta(crntTime) * kPi));
  34. trf.setOrigin(linearInterpolate(m_originalPos, m_newPos, factor));
  35. node->setLocalTransform(trf);
  36. }
  37. } // end namespace anki