Movable.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "anki/scene/Movable.h"
  2. #include "anki/scene/Property.h"
  3. namespace anki {
  4. //==============================================================================
  5. Movable::Movable(U32 flags_, Movable* parent, PropertyMap& pmap,
  6. const SceneAllocator<Movable>& alloc)
  7. : Base(parent, alloc), Flags(flags_)
  8. {
  9. pmap.addNewProperty(
  10. new ReadWritePointerProperty<Transform>("localTransform", &lTrf));
  11. pmap.addNewProperty(
  12. new ReadPointerProperty<Transform>("worldTransform", &wTrf));
  13. movableMarkUpdated();
  14. }
  15. //==============================================================================
  16. Movable::~Movable()
  17. {}
  18. //==============================================================================
  19. void Movable::update()
  20. {
  21. // If root begin updating
  22. if(getParent() == nullptr)
  23. {
  24. updateWorldTransform();
  25. }
  26. }
  27. //==============================================================================
  28. void Movable::updateWorldTransform()
  29. {
  30. prevWTrf = wTrf;
  31. const Movable* parent = getParent();
  32. const Bool dirty = isFlagEnabled(MF_TRANSFORM_DIRTY);
  33. // If dirty then update world transform
  34. if(dirty)
  35. {
  36. if(parent)
  37. {
  38. if(isFlagEnabled(MF_IGNORE_LOCAL_TRANSFORM))
  39. {
  40. wTrf = parent->getWorldTransform();
  41. }
  42. else
  43. {
  44. wTrf = Transform::combineTransformations(
  45. parent->getWorldTransform(), lTrf);
  46. }
  47. }
  48. else
  49. {
  50. wTrf = lTrf;
  51. }
  52. movableUpdate();
  53. }
  54. // Update the children
  55. Movable::Container::iterator it = getChildrenBegin();
  56. for(; it != getChildrenEnd(); it++)
  57. {
  58. // If parent is dirty then make children dirty as well
  59. if(dirty)
  60. {
  61. (*it)->movableMarkUpdated();
  62. }
  63. (*it)->updateWorldTransform();
  64. }
  65. // Now it's a good time to cleanse parent
  66. disableFlag(MF_TRANSFORM_DIRTY);
  67. }
  68. } // end namespace anki