BsPhysXCapsuleCollider.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. {
  11. PxCapsuleGeometry geometry(radius, halfHeight);
  12. PxShape* shape = physx->createShape(geometry, *gPhysX().getDefaultMaterial(), true);
  13. shape->setLocalPose(toPxTransform(position, rotation));
  14. shape->userData = this;
  15. mInternal = bs_new<FPhysXCollider>(shape);
  16. }
  17. PhysXCapsuleCollider::~PhysXCapsuleCollider()
  18. {
  19. bs_delete(mInternal);
  20. }
  21. void PhysXCapsuleCollider::setHalfHeight(float halfHeight)
  22. {
  23. PxCapsuleGeometry geometry(getRadius(), halfHeight);
  24. getInternal()->_getShape()->setGeometry(geometry);
  25. }
  26. float PhysXCapsuleCollider::getHalfHeight() const
  27. {
  28. return getInternal()->_getShape()->getGeometry().capsule().halfHeight;
  29. }
  30. void PhysXCapsuleCollider::setRadius(float radius)
  31. {
  32. PxCapsuleGeometry geometry(radius, getHalfHeight());
  33. getInternal()->_getShape()->setGeometry(geometry);
  34. }
  35. float PhysXCapsuleCollider::getRadius() const
  36. {
  37. return getInternal()->_getShape()->getGeometry().capsule().radius;
  38. }
  39. FPhysXCollider* PhysXCapsuleCollider::getInternal() const
  40. {
  41. return static_cast<FPhysXCollider*>(mInternal);
  42. }
  43. }