BsPhysXSliderJoint.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. mInternal = bs_new<FPhysXJoint>(joint);
  22. }
  23. PhysXSliderJoint::~PhysXSliderJoint()
  24. {
  25. bs_delete(mInternal);
  26. }
  27. float PhysXSliderJoint::getPosition() const
  28. {
  29. return getInternal()->getPosition();
  30. }
  31. float PhysXSliderJoint::getSpeed() const
  32. {
  33. return getInternal()->getVelocity();
  34. }
  35. LimitLinearRange PhysXSliderJoint::getLimit() const
  36. {
  37. PxJointLinearLimitPair pxLimit = getInternal()->getLimit();
  38. LimitLinearRange limit;
  39. limit.lower = pxLimit.lower;
  40. limit.upper = pxLimit.upper;
  41. limit.contactDist = pxLimit.contactDistance;
  42. limit.spring.stiffness = pxLimit.stiffness;
  43. limit.spring.damping = pxLimit.damping;
  44. return limit;
  45. }
  46. void PhysXSliderJoint::setLimit(const LimitLinearRange& limit)
  47. {
  48. PxJointLinearLimitPair pxLimit(gPhysX().getScale(), limit.lower, limit.upper, limit.contactDist);
  49. pxLimit.stiffness = limit.spring.stiffness;
  50. pxLimit.damping = limit.spring.damping;
  51. getInternal()->setLimit(pxLimit);
  52. }
  53. void PhysXSliderJoint::setFlag(Flag flag, bool enabled)
  54. {
  55. getInternal()->setPrismaticJointFlag(toPxFlag(flag), enabled);
  56. }
  57. bool PhysXSliderJoint::hasFlag(Flag flag)
  58. {
  59. return getInternal()->getPrismaticJointFlags() & toPxFlag(flag);
  60. }
  61. PxPrismaticJoint* PhysXSliderJoint::getInternal() const
  62. {
  63. FPhysXJoint* internal = static_cast<FPhysXJoint*>(mInternal);
  64. return static_cast<PxPrismaticJoint*>(internal->_getInternal());
  65. }
  66. }