Movable.cpp 1.9 KB

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