BsCD6Joint.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Components/BsCD6Joint.h"
  4. #include "Scene/BsSceneObject.h"
  5. #include "Private/RTTI/BsCD6JointRTTI.h"
  6. namespace bs
  7. {
  8. CD6Joint::CD6Joint()
  9. : CJoint(mDesc)
  10. {
  11. setName("D6Joint");
  12. }
  13. CD6Joint::CD6Joint(const HSceneObject& parent)
  14. : CJoint(parent, mDesc)
  15. {
  16. setName("D6Joint");
  17. }
  18. D6JointMotion CD6Joint::getMotion(D6JointAxis axis) const
  19. {
  20. return mDesc.motion[(int)axis];
  21. }
  22. void CD6Joint::setMotion(D6JointAxis axis, D6JointMotion motion)
  23. {
  24. if (mDesc.motion[(int)axis] == motion)
  25. return;
  26. mDesc.motion[(int)axis] = motion;
  27. if (mInternal != nullptr)
  28. _getInternal()->setMotion(axis, motion);
  29. }
  30. Radian CD6Joint::getTwist() const
  31. {
  32. if (mInternal == nullptr)
  33. return Radian(0.0f);
  34. return _getInternal()->getTwist();
  35. }
  36. Radian CD6Joint::getSwingY() const
  37. {
  38. if (mInternal == nullptr)
  39. return Radian(0.0f);
  40. return _getInternal()->getSwingY();
  41. }
  42. Radian CD6Joint::getSwingZ() const
  43. {
  44. if (mInternal == nullptr)
  45. return Radian(0.0f);
  46. return _getInternal()->getSwingZ();
  47. }
  48. LimitLinear CD6Joint::getLimitLinear() const
  49. {
  50. return mDesc.limitLinear;
  51. }
  52. void CD6Joint::setLimitLinear(const LimitLinear& limit)
  53. {
  54. if (mDesc.limitLinear == limit)
  55. return;
  56. mDesc.limitLinear = limit;
  57. if (mInternal != nullptr)
  58. _getInternal()->setLimitLinear(limit);
  59. }
  60. LimitAngularRange CD6Joint::getLimitTwist() const
  61. {
  62. return mDesc.limitTwist;
  63. }
  64. void CD6Joint::setLimitTwist(const LimitAngularRange& limit)
  65. {
  66. if (mDesc.limitTwist == limit)
  67. return;
  68. mDesc.limitTwist = limit;
  69. if (mInternal != nullptr)
  70. _getInternal()->setLimitTwist(limit);
  71. }
  72. LimitConeRange CD6Joint::getLimitSwing() const
  73. {
  74. return mDesc.limitSwing;
  75. }
  76. void CD6Joint::setLimitSwing(const LimitConeRange& limit)
  77. {
  78. if (mDesc.limitSwing == limit)
  79. return;
  80. mDesc.limitSwing = limit;
  81. if (mInternal != nullptr)
  82. _getInternal()->setLimitSwing(limit);
  83. }
  84. D6JointDrive CD6Joint::getDrive(D6JointDriveType type) const
  85. {
  86. return mDesc.drive[(int)type];
  87. }
  88. void CD6Joint::setDrive(D6JointDriveType type, const D6JointDrive& drive)
  89. {
  90. if (mDesc.drive[(int)type] == drive)
  91. return;
  92. mDesc.drive[(int)type] = drive;
  93. if (mInternal != nullptr)
  94. _getInternal()->setDrive(type, drive);
  95. }
  96. Vector3 CD6Joint::getDrivePosition() const
  97. {
  98. return mDesc.drivePosition;
  99. }
  100. Quaternion CD6Joint::getDriveRotation() const
  101. {
  102. return mDesc.driveRotation;
  103. }
  104. void CD6Joint::setDriveTransform(const Vector3& position, const Quaternion& rotation)
  105. {
  106. if (mDesc.drivePosition == position && mDesc.driveRotation == rotation)
  107. return;
  108. mDesc.drivePosition = position;
  109. mDesc.driveRotation = rotation;
  110. if (mInternal != nullptr)
  111. _getInternal()->setDriveTransform(position, rotation);
  112. }
  113. Vector3 CD6Joint::getDriveLinearVelocity() const
  114. {
  115. return mDesc.driveLinearVelocity;
  116. }
  117. Vector3 CD6Joint::getDriveAngularVelocity() const
  118. {
  119. return mDesc.driveAngularVelocity;
  120. }
  121. void CD6Joint::setDriveVelocity(const Vector3& linear, const Vector3& angular)
  122. {
  123. if (mDesc.driveLinearVelocity == linear && mDesc.driveAngularVelocity == angular)
  124. return;
  125. mDesc.driveLinearVelocity = linear;
  126. mDesc.driveAngularVelocity = angular;
  127. if (mInternal != nullptr)
  128. _getInternal()->setDriveVelocity(linear, angular);
  129. }
  130. SPtr<Joint> CD6Joint::createInternal()
  131. {
  132. SPtr<Joint> joint = D6Joint::create(mDesc);
  133. joint->_setOwner(PhysicsOwnerType::Component, this);
  134. return joint;
  135. }
  136. RTTITypeBase* CD6Joint::getRTTIStatic()
  137. {
  138. return CD6JointRTTI::instance();
  139. }
  140. RTTITypeBase* CD6Joint::getRTTI() const
  141. {
  142. return CD6Joint::getRTTIStatic();
  143. }
  144. }