BsCD6Joint.cpp 3.7 KB

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