BsCCapsuleCollider.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsCCapsuleCollider.h"
  4. #include "BsSceneObject.h"
  5. #include "BsCRigidbody.h"
  6. #include "BsCCapsuleColliderRTTI.h"
  7. namespace BansheeEngine
  8. {
  9. CCapsuleCollider::CCapsuleCollider(const HSceneObject& parent, float radius, float halfHeight)
  10. : CCollider(parent), mRadius(radius), mHalfHeight(halfHeight)
  11. {
  12. setName("CapsuleCollider");
  13. }
  14. void CCapsuleCollider::setNormal(const Vector3& normal)
  15. {
  16. if (mNormal == normal)
  17. return;
  18. mNormal = normal;
  19. mNormal.normalize();
  20. mLocalRotation = Quaternion::getRotationFromTo(Vector3::UNIT_X, normal);
  21. if (mInternal != nullptr)
  22. updateTransform();
  23. }
  24. void CCapsuleCollider::setCenter(const Vector3& center)
  25. {
  26. if (mLocalPosition == center)
  27. return;
  28. mLocalPosition = center;
  29. if (mInternal != nullptr)
  30. updateTransform();
  31. }
  32. void CCapsuleCollider::setHalfHeight(float halfHeight)
  33. {
  34. if (mHalfHeight == halfHeight)
  35. return;
  36. mHalfHeight = halfHeight;
  37. if (mInternal != nullptr)
  38. {
  39. _getInternal()->setHalfHeight(halfHeight);
  40. if (mParent != nullptr)
  41. mParent->_updateMassDistribution();
  42. }
  43. }
  44. void CCapsuleCollider::setRadius(float radius)
  45. {
  46. if (mRadius == radius)
  47. return;
  48. mRadius = radius;
  49. if (mInternal != nullptr)
  50. {
  51. _getInternal()->setRadius(radius);
  52. if (mParent != nullptr)
  53. mParent->_updateMassDistribution();
  54. }
  55. }
  56. SPtr<Collider> CCapsuleCollider::createInternal()
  57. {
  58. return CapsuleCollider::create(mRadius, mHalfHeight, SO()->getWorldPosition(), SO()->getWorldRotation());
  59. }
  60. RTTITypeBase* CCapsuleCollider::getRTTIStatic()
  61. {
  62. return CCapsuleColliderRTTI::instance();
  63. }
  64. RTTITypeBase* CCapsuleCollider::getRTTI() const
  65. {
  66. return CCapsuleCollider::getRTTIStatic();
  67. }
  68. }