PlayerControllerComponent.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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/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, getStaticClassId())
  12. {
  13. PhysicsPlayerControllerInitInfo init;
  14. init.m_position = node->getWorldTransform().getOrigin().xyz();
  15. m_player = getExternalSubsystems(*node).m_physicsWorld->newInstance<PhysicsPlayerController>(init);
  16. m_player->setUserData(this);
  17. node->setIgnoreParentTransform(true);
  18. }
  19. Error PlayerControllerComponent::update(SceneComponentUpdateInfo& info, Bool& updated)
  20. {
  21. const Transform newTrf = m_player->getTransform();
  22. updated = newTrf != m_trf;
  23. if(updated)
  24. {
  25. m_trf = newTrf;
  26. info.m_node->setLocalTransform(newTrf);
  27. }
  28. return Error::kNone;
  29. }
  30. } // end namespace anki