slider_joint_bullet.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*************************************************************************/
  2. /* slider_joint_bullet.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "slider_joint_bullet.h"
  31. #include "bullet_types_converter.h"
  32. #include "bullet_utilities.h"
  33. #include "rigid_body_bullet.h"
  34. #include <BulletDynamics/ConstraintSolver/btSliderConstraint.h>
  35. /**
  36. @author AndreaCatania
  37. */
  38. SliderJointBullet::SliderJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB) :
  39. JointBullet() {
  40. Transform scaled_AFrame(frameInA.scaled(rbA->get_body_scale()));
  41. scaled_AFrame.basis.rotref_posscale_decomposition(scaled_AFrame.basis);
  42. btTransform btFrameA;
  43. G_TO_B(scaled_AFrame, btFrameA);
  44. if (rbB) {
  45. Transform scaled_BFrame(frameInB.scaled(rbB->get_body_scale()));
  46. scaled_BFrame.basis.rotref_posscale_decomposition(scaled_BFrame.basis);
  47. btTransform btFrameB;
  48. G_TO_B(scaled_BFrame, btFrameB);
  49. sliderConstraint = bulletnew(btSliderConstraint(*rbA->get_bt_rigid_body(), *rbB->get_bt_rigid_body(), btFrameA, btFrameB, true));
  50. } else {
  51. sliderConstraint = bulletnew(btSliderConstraint(*rbA->get_bt_rigid_body(), btFrameA, true));
  52. }
  53. setup(sliderConstraint);
  54. }
  55. const RigidBodyBullet *SliderJointBullet::getRigidBodyA() const {
  56. return static_cast<RigidBodyBullet *>(sliderConstraint->getRigidBodyA().getUserPointer());
  57. }
  58. const RigidBodyBullet *SliderJointBullet::getRigidBodyB() const {
  59. return static_cast<RigidBodyBullet *>(sliderConstraint->getRigidBodyB().getUserPointer());
  60. }
  61. const Transform SliderJointBullet::getCalculatedTransformA() const {
  62. btTransform btTransform = sliderConstraint->getCalculatedTransformA();
  63. Transform gTrans;
  64. B_TO_G(btTransform, gTrans);
  65. return gTrans;
  66. }
  67. const Transform SliderJointBullet::getCalculatedTransformB() const {
  68. btTransform btTransform = sliderConstraint->getCalculatedTransformB();
  69. Transform gTrans;
  70. B_TO_G(btTransform, gTrans);
  71. return gTrans;
  72. }
  73. const Transform SliderJointBullet::getFrameOffsetA() const {
  74. btTransform btTransform = sliderConstraint->getFrameOffsetA();
  75. Transform gTrans;
  76. B_TO_G(btTransform, gTrans);
  77. return gTrans;
  78. }
  79. const Transform SliderJointBullet::getFrameOffsetB() const {
  80. btTransform btTransform = sliderConstraint->getFrameOffsetB();
  81. Transform gTrans;
  82. B_TO_G(btTransform, gTrans);
  83. return gTrans;
  84. }
  85. Transform SliderJointBullet::getFrameOffsetA() {
  86. btTransform btTransform = sliderConstraint->getFrameOffsetA();
  87. Transform gTrans;
  88. B_TO_G(btTransform, gTrans);
  89. return gTrans;
  90. }
  91. Transform SliderJointBullet::getFrameOffsetB() {
  92. btTransform btTransform = sliderConstraint->getFrameOffsetB();
  93. Transform gTrans;
  94. B_TO_G(btTransform, gTrans);
  95. return gTrans;
  96. }
  97. real_t SliderJointBullet::getLowerLinLimit() const {
  98. return sliderConstraint->getLowerLinLimit();
  99. }
  100. void SliderJointBullet::setLowerLinLimit(real_t lowerLimit) {
  101. sliderConstraint->setLowerLinLimit(lowerLimit);
  102. }
  103. real_t SliderJointBullet::getUpperLinLimit() const {
  104. return sliderConstraint->getUpperLinLimit();
  105. }
  106. void SliderJointBullet::setUpperLinLimit(real_t upperLimit) {
  107. sliderConstraint->setUpperLinLimit(upperLimit);
  108. }
  109. real_t SliderJointBullet::getLowerAngLimit() const {
  110. return sliderConstraint->getLowerAngLimit();
  111. }
  112. void SliderJointBullet::setLowerAngLimit(real_t lowerLimit) {
  113. sliderConstraint->setLowerAngLimit(lowerLimit);
  114. }
  115. real_t SliderJointBullet::getUpperAngLimit() const {
  116. return sliderConstraint->getUpperAngLimit();
  117. }
  118. void SliderJointBullet::setUpperAngLimit(real_t upperLimit) {
  119. sliderConstraint->setUpperAngLimit(upperLimit);
  120. }
  121. real_t SliderJointBullet::getSoftnessDirLin() const {
  122. return sliderConstraint->getSoftnessDirLin();
  123. }
  124. real_t SliderJointBullet::getRestitutionDirLin() const {
  125. return sliderConstraint->getRestitutionDirLin();
  126. }
  127. real_t SliderJointBullet::getDampingDirLin() const {
  128. return sliderConstraint->getDampingDirLin();
  129. }
  130. real_t SliderJointBullet::getSoftnessDirAng() const {
  131. return sliderConstraint->getSoftnessDirAng();
  132. }
  133. real_t SliderJointBullet::getRestitutionDirAng() const {
  134. return sliderConstraint->getRestitutionDirAng();
  135. }
  136. real_t SliderJointBullet::getDampingDirAng() const {
  137. return sliderConstraint->getDampingDirAng();
  138. }
  139. real_t SliderJointBullet::getSoftnessLimLin() const {
  140. return sliderConstraint->getSoftnessLimLin();
  141. }
  142. real_t SliderJointBullet::getRestitutionLimLin() const {
  143. return sliderConstraint->getRestitutionLimLin();
  144. }
  145. real_t SliderJointBullet::getDampingLimLin() const {
  146. return sliderConstraint->getDampingLimLin();
  147. }
  148. real_t SliderJointBullet::getSoftnessLimAng() const {
  149. return sliderConstraint->getSoftnessLimAng();
  150. }
  151. real_t SliderJointBullet::getRestitutionLimAng() const {
  152. return sliderConstraint->getRestitutionLimAng();
  153. }
  154. real_t SliderJointBullet::getDampingLimAng() const {
  155. return sliderConstraint->getDampingLimAng();
  156. }
  157. real_t SliderJointBullet::getSoftnessOrthoLin() const {
  158. return sliderConstraint->getSoftnessOrthoLin();
  159. }
  160. real_t SliderJointBullet::getRestitutionOrthoLin() const {
  161. return sliderConstraint->getRestitutionOrthoLin();
  162. }
  163. real_t SliderJointBullet::getDampingOrthoLin() const {
  164. return sliderConstraint->getDampingOrthoLin();
  165. }
  166. real_t SliderJointBullet::getSoftnessOrthoAng() const {
  167. return sliderConstraint->getSoftnessOrthoAng();
  168. }
  169. real_t SliderJointBullet::getRestitutionOrthoAng() const {
  170. return sliderConstraint->getRestitutionOrthoAng();
  171. }
  172. real_t SliderJointBullet::getDampingOrthoAng() const {
  173. return sliderConstraint->getDampingOrthoAng();
  174. }
  175. void SliderJointBullet::setSoftnessDirLin(real_t softnessDirLin) {
  176. sliderConstraint->setSoftnessDirLin(softnessDirLin);
  177. }
  178. void SliderJointBullet::setRestitutionDirLin(real_t restitutionDirLin) {
  179. sliderConstraint->setRestitutionDirLin(restitutionDirLin);
  180. }
  181. void SliderJointBullet::setDampingDirLin(real_t dampingDirLin) {
  182. sliderConstraint->setDampingDirLin(dampingDirLin);
  183. }
  184. void SliderJointBullet::setSoftnessDirAng(real_t softnessDirAng) {
  185. sliderConstraint->setSoftnessDirAng(softnessDirAng);
  186. }
  187. void SliderJointBullet::setRestitutionDirAng(real_t restitutionDirAng) {
  188. sliderConstraint->setRestitutionDirAng(restitutionDirAng);
  189. }
  190. void SliderJointBullet::setDampingDirAng(real_t dampingDirAng) {
  191. sliderConstraint->setDampingDirAng(dampingDirAng);
  192. }
  193. void SliderJointBullet::setSoftnessLimLin(real_t softnessLimLin) {
  194. sliderConstraint->setSoftnessLimLin(softnessLimLin);
  195. }
  196. void SliderJointBullet::setRestitutionLimLin(real_t restitutionLimLin) {
  197. sliderConstraint->setRestitutionLimLin(restitutionLimLin);
  198. }
  199. void SliderJointBullet::setDampingLimLin(real_t dampingLimLin) {
  200. sliderConstraint->setDampingLimLin(dampingLimLin);
  201. }
  202. void SliderJointBullet::setSoftnessLimAng(real_t softnessLimAng) {
  203. sliderConstraint->setSoftnessLimAng(softnessLimAng);
  204. }
  205. void SliderJointBullet::setRestitutionLimAng(real_t restitutionLimAng) {
  206. sliderConstraint->setRestitutionLimAng(restitutionLimAng);
  207. }
  208. void SliderJointBullet::setDampingLimAng(real_t dampingLimAng) {
  209. sliderConstraint->setDampingLimAng(dampingLimAng);
  210. }
  211. void SliderJointBullet::setSoftnessOrthoLin(real_t softnessOrthoLin) {
  212. sliderConstraint->setSoftnessOrthoLin(softnessOrthoLin);
  213. }
  214. void SliderJointBullet::setRestitutionOrthoLin(real_t restitutionOrthoLin) {
  215. sliderConstraint->setRestitutionOrthoLin(restitutionOrthoLin);
  216. }
  217. void SliderJointBullet::setDampingOrthoLin(real_t dampingOrthoLin) {
  218. sliderConstraint->setDampingOrthoLin(dampingOrthoLin);
  219. }
  220. void SliderJointBullet::setSoftnessOrthoAng(real_t softnessOrthoAng) {
  221. sliderConstraint->setSoftnessOrthoAng(softnessOrthoAng);
  222. }
  223. void SliderJointBullet::setRestitutionOrthoAng(real_t restitutionOrthoAng) {
  224. sliderConstraint->setRestitutionOrthoAng(restitutionOrthoAng);
  225. }
  226. void SliderJointBullet::setDampingOrthoAng(real_t dampingOrthoAng) {
  227. sliderConstraint->setDampingOrthoAng(dampingOrthoAng);
  228. }
  229. void SliderJointBullet::setPoweredLinMotor(bool onOff) {
  230. sliderConstraint->setPoweredLinMotor(onOff);
  231. }
  232. bool SliderJointBullet::getPoweredLinMotor() {
  233. return sliderConstraint->getPoweredLinMotor();
  234. }
  235. void SliderJointBullet::setTargetLinMotorVelocity(real_t targetLinMotorVelocity) {
  236. sliderConstraint->setTargetLinMotorVelocity(targetLinMotorVelocity);
  237. }
  238. real_t SliderJointBullet::getTargetLinMotorVelocity() {
  239. return sliderConstraint->getTargetLinMotorVelocity();
  240. }
  241. void SliderJointBullet::setMaxLinMotorForce(real_t maxLinMotorForce) {
  242. sliderConstraint->setMaxLinMotorForce(maxLinMotorForce);
  243. }
  244. real_t SliderJointBullet::getMaxLinMotorForce() {
  245. return sliderConstraint->getMaxLinMotorForce();
  246. }
  247. void SliderJointBullet::setPoweredAngMotor(bool onOff) {
  248. sliderConstraint->setPoweredAngMotor(onOff);
  249. }
  250. bool SliderJointBullet::getPoweredAngMotor() {
  251. return sliderConstraint->getPoweredAngMotor();
  252. }
  253. void SliderJointBullet::setTargetAngMotorVelocity(real_t targetAngMotorVelocity) {
  254. sliderConstraint->setTargetAngMotorVelocity(targetAngMotorVelocity);
  255. }
  256. real_t SliderJointBullet::getTargetAngMotorVelocity() {
  257. return sliderConstraint->getTargetAngMotorVelocity();
  258. }
  259. void SliderJointBullet::setMaxAngMotorForce(real_t maxAngMotorForce) {
  260. sliderConstraint->setMaxAngMotorForce(maxAngMotorForce);
  261. }
  262. real_t SliderJointBullet::getMaxAngMotorForce() {
  263. return sliderConstraint->getMaxAngMotorForce();
  264. }
  265. real_t SliderJointBullet::getLinearPos() {
  266. return sliderConstraint->getLinearPos();
  267. ;
  268. }
  269. void SliderJointBullet::set_param(PhysicsServer::SliderJointParam p_param, real_t p_value) {
  270. switch (p_param) {
  271. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER: setUpperLinLimit(p_value); break;
  272. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER: setLowerLinLimit(p_value); break;
  273. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS: setSoftnessLimLin(p_value); break;
  274. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION: setRestitutionLimLin(p_value); break;
  275. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING: setDampingLimLin(p_value); break;
  276. case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS: setSoftnessDirLin(p_value); break;
  277. case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION: setRestitutionDirLin(p_value); break;
  278. case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING: setDampingDirLin(p_value); break;
  279. case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS: setSoftnessOrthoLin(p_value); break;
  280. case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION: setRestitutionOrthoLin(p_value); break;
  281. case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING: setDampingOrthoLin(p_value); break;
  282. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER: setUpperAngLimit(p_value); break;
  283. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER: setLowerAngLimit(p_value); break;
  284. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS: setSoftnessLimAng(p_value); break;
  285. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION: setRestitutionLimAng(p_value); break;
  286. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING: setDampingLimAng(p_value); break;
  287. case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS: setSoftnessDirAng(p_value); break;
  288. case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION: setRestitutionDirAng(p_value); break;
  289. case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING: setDampingDirAng(p_value); break;
  290. case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS: setSoftnessOrthoAng(p_value); break;
  291. case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION: setRestitutionOrthoAng(p_value); break;
  292. case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING: setDampingOrthoAng(p_value); break;
  293. }
  294. }
  295. real_t SliderJointBullet::get_param(PhysicsServer::SliderJointParam p_param) const {
  296. switch (p_param) {
  297. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER: return getUpperLinLimit();
  298. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER: return getLowerLinLimit();
  299. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS: return getSoftnessLimLin();
  300. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION: return getRestitutionLimLin();
  301. case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING: return getDampingLimLin();
  302. case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS: return getSoftnessDirLin();
  303. case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION: return getRestitutionDirLin();
  304. case PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING: return getDampingDirLin();
  305. case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS: return getSoftnessOrthoLin();
  306. case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION: return getRestitutionOrthoLin();
  307. case PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING: return getDampingOrthoLin();
  308. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER: return getUpperAngLimit();
  309. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER: return getLowerAngLimit();
  310. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS: return getSoftnessLimAng();
  311. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION: return getRestitutionLimAng();
  312. case PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING: return getDampingLimAng();
  313. case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS: return getSoftnessDirAng();
  314. case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION: return getRestitutionDirAng();
  315. case PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING: return getDampingDirAng();
  316. case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS: return getSoftnessOrthoAng();
  317. case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION: return getRestitutionOrthoAng();
  318. case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING: return getDampingOrthoAng();
  319. default:
  320. return 0;
  321. }
  322. }