BsCBoxCollider.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsCBoxCollider.h"
  4. #include "BsSceneObject.h"
  5. #include "BsCRigidbody.h"
  6. #include "BsCBoxColliderRTTI.h"
  7. namespace BansheeEngine
  8. {
  9. CBoxCollider::CBoxCollider(const HSceneObject& parent, const Vector3& extents)
  10. : CCollider(parent), mExtents(extents)
  11. {
  12. setName("BoxCollider");
  13. }
  14. void CBoxCollider::setExtents(const Vector3& extents)
  15. {
  16. Vector3 clampedExtents = Vector3::max(extents, Vector3(0.01f, 0.01f, 0.01f));
  17. if (mExtents == clampedExtents)
  18. return;
  19. mExtents = clampedExtents;
  20. if (mInternal != nullptr)
  21. {
  22. _getInternal()->setExtents(clampedExtents);
  23. if (mParent != nullptr)
  24. mParent->_updateMassDistribution();
  25. }
  26. }
  27. void CBoxCollider::setCenter(const Vector3& center)
  28. {
  29. if (mLocalPosition == center)
  30. return;
  31. mLocalPosition = center;
  32. if (mInternal != nullptr)
  33. updateTransform();
  34. }
  35. SPtr<Collider> CBoxCollider::createInternal()
  36. {
  37. SPtr<Collider> collider = BoxCollider::create(mExtents, SO()->getWorldPosition(), SO()->getWorldRotation());
  38. collider->_setOwner(PhysicsOwnerType::Component, this);
  39. return collider;
  40. }
  41. RTTITypeBase* CBoxCollider::getRTTIStatic()
  42. {
  43. return CBoxColliderRTTI::instance();
  44. }
  45. RTTITypeBase* CBoxCollider::getRTTI() const
  46. {
  47. return CBoxCollider::getRTTIStatic();
  48. }
  49. }