PlayerControllerComponent.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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/Components/PlayerControllerComponent.h>
  6. #include <AnKi/Scene/SceneNode.h>
  7. #include <AnKi/Scene/SceneGraph.h>
  8. #include <AnKi/Physics/PhysicsWorld.h>
  9. namespace anki {
  10. PlayerControllerComponent::PlayerControllerComponent(SceneNode* node)
  11. : SceneComponent(node, kClassType)
  12. {
  13. PhysicsPlayerControllerInitInfo init;
  14. init.m_initialPosition = node->getWorldTransform().getOrigin().xyz();
  15. m_player = PhysicsWorld::getSingleton().newPlayerController(init);
  16. m_player->setUserData(this);
  17. node->setIgnoreParentTransform(true);
  18. }
  19. void PlayerControllerComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
  20. {
  21. U32 posVersion;
  22. const Vec3 newPos = m_player->getPosition(&posVersion);
  23. if(posVersion != m_positionVersion)
  24. {
  25. updated = true;
  26. m_positionVersion = posVersion;
  27. info.m_node->setLocalOrigin(newPos);
  28. }
  29. }
  30. } // end namespace anki