BsPhysXBoxCollider.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsPhysXBoxCollider.h"
  4. #include "BsPhysX.h"
  5. #include "PxPhysics.h"
  6. #include "BsFPhysXCollider.h"
  7. using namespace physx;
  8. namespace bs
  9. {
  10. PhysXBoxCollider::PhysXBoxCollider(PxPhysics* physx, const Vector3& position, const Quaternion& rotation,
  11. const Vector3& extents)
  12. :mExtents(extents)
  13. {
  14. PxBoxGeometry geometry(extents.x, extents.y, extents.z);
  15. PxShape* shape = physx->createShape(geometry, *gPhysX().getDefaultMaterial(), true);
  16. shape->setLocalPose(toPxTransform(position, rotation));
  17. shape->userData = this;
  18. mInternal = bs_new<FPhysXCollider>(shape);
  19. applyGeometry();
  20. }
  21. PhysXBoxCollider::~PhysXBoxCollider()
  22. {
  23. bs_delete(mInternal);
  24. }
  25. void PhysXBoxCollider::setScale(const Vector3& scale)
  26. {
  27. BoxCollider::setScale(scale);
  28. applyGeometry();
  29. }
  30. void PhysXBoxCollider::setExtents(const Vector3& extents)
  31. {
  32. mExtents = extents;
  33. applyGeometry();
  34. }
  35. Vector3 PhysXBoxCollider::getExtents() const
  36. {
  37. return mExtents;
  38. }
  39. void PhysXBoxCollider::applyGeometry()
  40. {
  41. PxBoxGeometry geometry(std::max(0.01f, mExtents.x * mScale.x),
  42. std::max(0.01f, mExtents.y * mScale.y), std::max(0.01f, mExtents.z * mScale.z));
  43. getInternal()->_getShape()->setGeometry(geometry);
  44. }
  45. FPhysXCollider* PhysXBoxCollider::getInternal() const
  46. {
  47. return static_cast<FPhysXCollider*>(mInternal);
  48. }
  49. }