BsPhysXBoxCollider.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 BansheeEngine
  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. }
  20. PhysXBoxCollider::~PhysXBoxCollider()
  21. {
  22. bs_delete(mInternal);
  23. }
  24. void PhysXBoxCollider::setScale(const Vector3& scale)
  25. {
  26. BoxCollider::setScale(scale);
  27. applyGeometry();
  28. }
  29. void PhysXBoxCollider::setExtents(const Vector3& extents)
  30. {
  31. mExtents = extents;
  32. applyGeometry();
  33. }
  34. Vector3 PhysXBoxCollider::getExtents() const
  35. {
  36. return mExtents;
  37. }
  38. void PhysXBoxCollider::applyGeometry()
  39. {
  40. PxBoxGeometry geometry(mExtents.x * mScale.x, mExtents.y * mScale.y, mExtents.z * mScale.z);
  41. getInternal()->_getShape()->setGeometry(geometry);
  42. }
  43. FPhysXCollider* PhysXBoxCollider::getInternal() const
  44. {
  45. return static_cast<FPhysXCollider*>(mInternal);
  46. }
  47. }