BsPhysXSphereCollider.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. :mRadius(radius)
  11. {
  12. PxSphereGeometry geometry(radius);
  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. PhysXSphereCollider::~PhysXSphereCollider()
  19. {
  20. bs_delete(mInternal);
  21. }
  22. void PhysXSphereCollider::setScale(const Vector3& scale)
  23. {
  24. SphereCollider::setScale(scale);
  25. applyGeometry();
  26. }
  27. void PhysXSphereCollider::setRadius(float radius)
  28. {
  29. mRadius = radius;
  30. applyGeometry();
  31. }
  32. float PhysXSphereCollider::getRadius() const
  33. {
  34. return mRadius;
  35. }
  36. void PhysXSphereCollider::applyGeometry()
  37. {
  38. PxSphereGeometry geometry(mRadius * std::max(std::max(mScale.x, mScale.y), mScale.z));
  39. getInternal()->_getShape()->setGeometry(geometry);
  40. }
  41. FPhysXCollider* PhysXSphereCollider::getInternal() const
  42. {
  43. return static_cast<FPhysXCollider*>(mInternal);
  44. }
  45. }