BsCHingeJoint.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Components/BsCHingeJoint.h"
  4. #include "Scene/BsSceneObject.h"
  5. #include "Private/RTTI/BsCHingeJointRTTI.h"
  6. namespace bs
  7. {
  8. CHingeJoint::CHingeJoint()
  9. : CJoint(mDesc)
  10. {
  11. setName("HingeJoint");
  12. }
  13. CHingeJoint::CHingeJoint(const HSceneObject& parent)
  14. : CJoint(parent, mDesc)
  15. {
  16. setName("HingeJoint");
  17. }
  18. Radian CHingeJoint::getAngle() const
  19. {
  20. if (mInternal == nullptr)
  21. return Radian(0.0f);
  22. return _getInternal()->getAngle();
  23. }
  24. float CHingeJoint::getSpeed() const
  25. {
  26. if (mInternal == nullptr)
  27. return 0.0f;
  28. return _getInternal()->getSpeed();
  29. }
  30. LimitAngularRange CHingeJoint::getLimit() const
  31. {
  32. return mDesc.limit;
  33. }
  34. void CHingeJoint::setLimit(const LimitAngularRange& limit)
  35. {
  36. if (limit == mDesc.limit)
  37. return;
  38. mDesc.limit = limit;
  39. if (mInternal != nullptr)
  40. _getInternal()->setLimit(limit);
  41. }
  42. HingeJointDrive CHingeJoint::getDrive() const
  43. {
  44. return mDesc.drive;
  45. }
  46. void CHingeJoint::setDrive(const HingeJointDrive& drive)
  47. {
  48. if (drive == mDesc.drive)
  49. return;
  50. mDesc.drive = drive;
  51. if (mInternal != nullptr)
  52. _getInternal()->setDrive(drive);
  53. }
  54. void CHingeJoint::setFlag(HingeJointFlag flag, bool enabled)
  55. {
  56. bool isEnabled = ((UINT32)mDesc.flag & (UINT32)flag) != 0;
  57. if (isEnabled == enabled)
  58. return;
  59. if (enabled)
  60. mDesc.flag = (HingeJointFlag)((UINT32)mDesc.flag | (UINT32)flag);
  61. else
  62. mDesc.flag = (HingeJointFlag)((UINT32)mDesc.flag & ~(UINT32)flag);
  63. if (mInternal != nullptr)
  64. _getInternal()->setFlag(flag, enabled);
  65. }
  66. bool CHingeJoint::hasFlag(HingeJointFlag flag) const
  67. {
  68. return ((UINT32)mDesc.flag & (UINT32)flag) != 0;
  69. }
  70. SPtr<Joint> CHingeJoint::createInternal()
  71. {
  72. SPtr<Joint> joint = HingeJoint::create(mDesc);
  73. joint->_setOwner(PhysicsOwnerType::Component, this);
  74. return joint;
  75. }
  76. RTTITypeBase* CHingeJoint::getRTTIStatic()
  77. {
  78. return CHingeJointRTTI::instance();
  79. }
  80. RTTITypeBase* CHingeJoint::getRTTI() const
  81. {
  82. return CHingeJoint::getRTTIStatic();
  83. }
  84. }