BsPhysXSliderJoint.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsPhysXSliderJoint.h"
  4. #include "BsFPhysxJoint.h"
  5. #include "BsPhysX.h"
  6. using namespace physx;
  7. namespace BansheeEngine
  8. {
  9. PxPrismaticJointFlag::Enum toPxFlag(PhysXSliderJoint::Flag flag)
  10. {
  11. switch (flag)
  12. {
  13. default:
  14. case PhysXSliderJoint::Flag::Limit:
  15. return PxPrismaticJointFlag::eLIMIT_ENABLED;
  16. }
  17. }
  18. PhysXSliderJoint::PhysXSliderJoint(PxPhysics* physx)
  19. {
  20. PxPrismaticJoint* joint = PxPrismaticJointCreate(*physx, nullptr, PxTransform(), nullptr, PxTransform());
  21. joint->userData = this;
  22. mInternal = bs_new<FPhysXJoint>(joint);
  23. }
  24. PhysXSliderJoint::~PhysXSliderJoint()
  25. {
  26. bs_delete(mInternal);
  27. }
  28. float PhysXSliderJoint::getPosition() const
  29. {
  30. return getInternal()->getPosition();
  31. }
  32. float PhysXSliderJoint::getSpeed() const
  33. {
  34. return getInternal()->getVelocity();
  35. }
  36. LimitLinearRange PhysXSliderJoint::getLimit() const
  37. {
  38. PxJointLinearLimitPair pxLimit = getInternal()->getLimit();
  39. LimitLinearRange limit;
  40. limit.lower = pxLimit.lower;
  41. limit.upper = pxLimit.upper;
  42. limit.contactDist = pxLimit.contactDistance;
  43. limit.restitution = pxLimit.restitution;
  44. limit.spring.stiffness = pxLimit.stiffness;
  45. limit.spring.damping = pxLimit.damping;
  46. return limit;
  47. }
  48. void PhysXSliderJoint::setLimit(const LimitLinearRange& limit)
  49. {
  50. PxJointLinearLimitPair pxLimit(gPhysX().getScale(), limit.lower, limit.upper, limit.contactDist);
  51. pxLimit.stiffness = limit.spring.stiffness;
  52. pxLimit.damping = limit.spring.damping;
  53. pxLimit.restitution = limit.restitution;
  54. getInternal()->setLimit(pxLimit);
  55. }
  56. void PhysXSliderJoint::setFlag(Flag flag, bool enabled)
  57. {
  58. getInternal()->setPrismaticJointFlag(toPxFlag(flag), enabled);
  59. }
  60. bool PhysXSliderJoint::hasFlag(Flag flag) const
  61. {
  62. return getInternal()->getPrismaticJointFlags() & toPxFlag(flag);
  63. }
  64. PxPrismaticJoint* PhysXSliderJoint::getInternal() const
  65. {
  66. FPhysXJoint* internal = static_cast<FPhysXJoint*>(mInternal);
  67. return static_cast<PxPrismaticJoint*>(internal->_getInternal());
  68. }
  69. }