BsPhysXCapsuleCollider.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "BsPhysXCapsuleCollider.h"
  2. #include "BsPhysX.h"
  3. #include "PxPhysics.h"
  4. #include "BsFPhysXCollider.h"
  5. using namespace physx;
  6. namespace BansheeEngine
  7. {
  8. PhysXCapsuleCollider::PhysXCapsuleCollider(PxPhysics* physx, const Vector3& position, const Quaternion& rotation,
  9. float radius, float halfHeight)
  10. :mRadius(radius), mHalfHeight(halfHeight)
  11. {
  12. PxCapsuleGeometry geometry(radius, halfHeight);
  13. PxShape* shape = physx->createShape(geometry, *gPhysX().getDefaultMaterial(), true);
  14. shape->setLocalPose(toPxTransform(position, rotation));
  15. shape->userData = this;
  16. mInternal = bs_new<FPhysXCollider>(shape);
  17. }
  18. PhysXCapsuleCollider::~PhysXCapsuleCollider()
  19. {
  20. bs_delete(mInternal);
  21. }
  22. void PhysXCapsuleCollider::setScale(const Vector3& scale)
  23. {
  24. CapsuleCollider::setScale(scale);
  25. applyGeometry();
  26. }
  27. void PhysXCapsuleCollider::setHalfHeight(float halfHeight)
  28. {
  29. mHalfHeight = halfHeight;
  30. applyGeometry();
  31. }
  32. float PhysXCapsuleCollider::getHalfHeight() const
  33. {
  34. return mHalfHeight;
  35. }
  36. void PhysXCapsuleCollider::setRadius(float radius)
  37. {
  38. mRadius = radius;
  39. applyGeometry();
  40. }
  41. float PhysXCapsuleCollider::getRadius() const
  42. {
  43. return mRadius;
  44. }
  45. void PhysXCapsuleCollider::applyGeometry()
  46. {
  47. PxCapsuleGeometry geometry(mRadius * std::max(mScale.x, mScale.z), mHalfHeight * mScale.y);
  48. getInternal()->_getShape()->setGeometry(geometry);
  49. }
  50. FPhysXCollider* PhysXCapsuleCollider::getInternal() const
  51. {
  52. return static_cast<FPhysXCollider*>(mInternal);
  53. }
  54. }