BsPhysXSphericalJoint.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsPhysXSphericalJoint.h"
  4. #include "BsFPhysxJoint.h"
  5. using namespace physx;
  6. namespace BansheeEngine
  7. {
  8. PxSphericalJointFlag::Enum toPxFlag(PhysXSphericalJoint::Flag flag)
  9. {
  10. switch (flag)
  11. {
  12. default:
  13. case PhysXSphericalJoint::Flag::Limit:
  14. return PxSphericalJointFlag::eLIMIT_ENABLED;
  15. }
  16. }
  17. PhysXSphericalJoint::PhysXSphericalJoint(PxPhysics* physx)
  18. {
  19. PxSphericalJoint* joint = PxSphericalJointCreate(*physx, nullptr, PxTransform(), nullptr, PxTransform());
  20. joint->userData = this;
  21. mInternal = bs_new<FPhysXJoint>(joint);
  22. }
  23. PhysXSphericalJoint::~PhysXSphericalJoint()
  24. {
  25. bs_delete(mInternal);
  26. }
  27. LimitConeRange PhysXSphericalJoint::getLimit() const
  28. {
  29. PxJointLimitCone pxLimit = getInternal()->getLimitCone();
  30. LimitConeRange limit;
  31. limit.yLimitAngle = pxLimit.yAngle;
  32. limit.zLimitAngle = pxLimit.zAngle;
  33. limit.contactDist = pxLimit.contactDistance;
  34. limit.restitution = pxLimit.restitution;
  35. limit.spring.stiffness = pxLimit.stiffness;
  36. limit.spring.damping = pxLimit.damping;
  37. return limit;
  38. }
  39. void PhysXSphericalJoint::setLimit(const LimitConeRange& limit)
  40. {
  41. PxJointLimitCone pxLimit(limit.yLimitAngle.valueRadians(), limit.zLimitAngle.valueRadians(), limit.contactDist);
  42. pxLimit.stiffness = limit.spring.stiffness;
  43. pxLimit.damping = limit.spring.damping;
  44. pxLimit.restitution = limit.restitution;
  45. getInternal()->setLimitCone(pxLimit);
  46. }
  47. void PhysXSphericalJoint::setFlag(Flag flag, bool enabled)
  48. {
  49. getInternal()->setSphericalJointFlag(toPxFlag(flag), enabled);
  50. }
  51. bool PhysXSphericalJoint::hasFlag(Flag flag) const
  52. {
  53. return getInternal()->getSphericalJointFlags() & toPxFlag(flag);
  54. }
  55. PxSphericalJoint* PhysXSphericalJoint::getInternal() const
  56. {
  57. FPhysXJoint* internal = static_cast<FPhysXJoint*>(mInternal);
  58. return static_cast<PxSphericalJoint*>(internal->_getInternal());
  59. }
  60. }