BsPhysXSphereCollider.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "BsPhysXSphereCollider.h"
  2. #include "BsPhysX.h"
  3. #include "PxPhysics.h"
  4. #include "BsFPhysXCollider.h"
  5. using namespace physx;
  6. namespace BansheeEngine
  7. {
  8. PhysXSphereCollider::PhysXSphereCollider(PxPhysics* physx, const Vector3& position, const Quaternion& rotation,
  9. float radius)
  10. {
  11. PxSphereGeometry geometry(radius);
  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. PhysXSphereCollider::~PhysXSphereCollider()
  18. {
  19. bs_delete(mInternal);
  20. }
  21. void PhysXSphereCollider::setRadius(float radius)
  22. {
  23. PxSphereGeometry geometry(radius);
  24. getInternal()->_getShape()->setGeometry(geometry);
  25. }
  26. float PhysXSphereCollider::getRadius() const
  27. {
  28. return getInternal()->_getShape()->getGeometry().sphere().radius;
  29. }
  30. FPhysXCollider* PhysXSphereCollider::getInternal() const
  31. {
  32. return static_cast<FPhysXCollider*>(mInternal);
  33. }
  34. }