BsCD6Joint.cpp 3.7 KB

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