godot_generic_6dof_joint_3d.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /**************************************************************************/
  2. /* godot_generic_6dof_joint_3d.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. /*
  31. Adapted to Godot from the Bullet library.
  32. */
  33. /*
  34. Bullet Continuous Collision Detection and Physics Library
  35. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  36. This software is provided 'as-is', without any express or implied warranty.
  37. In no event will the authors be held liable for any damages arising from the use of this software.
  38. Permission is granted to anyone to use this software for any purpose,
  39. including commercial applications, and to alter it and redistribute it freely,
  40. subject to the following restrictions:
  41. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  42. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  43. 3. This notice may not be removed or altered from any source distribution.
  44. */
  45. /*
  46. 2007-09-09
  47. GodotGeneric6DOFJoint3D Refactored by Francisco Le?n
  48. email: projectileman@yahoo.com
  49. http://gimpact.sf.net
  50. */
  51. #include "godot_generic_6dof_joint_3d.h"
  52. #define GENERIC_D6_DISABLE_WARMSTARTING 1
  53. //////////////////////////// GodotG6DOFRotationalLimitMotor3D ////////////////////////////////////
  54. int GodotG6DOFRotationalLimitMotor3D::testLimitValue(real_t test_value) {
  55. if (m_loLimit > m_hiLimit) {
  56. m_currentLimit = 0; //Free from violation
  57. return 0;
  58. }
  59. if (test_value < m_loLimit) {
  60. m_currentLimit = 1; //low limit violation
  61. m_currentLimitError = test_value - m_loLimit;
  62. return 1;
  63. } else if (test_value > m_hiLimit) {
  64. m_currentLimit = 2; //High limit violation
  65. m_currentLimitError = test_value - m_hiLimit;
  66. return 2;
  67. };
  68. m_currentLimit = 0; //Free from violation
  69. return 0;
  70. }
  71. real_t GodotG6DOFRotationalLimitMotor3D::solveAngularLimits(
  72. real_t timeStep, Vector3 &axis, real_t jacDiagABInv,
  73. GodotBody3D *body0, GodotBody3D *body1, bool p_body0_dynamic, bool p_body1_dynamic) {
  74. if (!needApplyTorques()) {
  75. return 0.0f;
  76. }
  77. real_t target_velocity = m_targetVelocity;
  78. real_t maxMotorForce = m_maxMotorForce;
  79. //current error correction
  80. if (m_currentLimit != 0) {
  81. target_velocity = -m_ERP * m_currentLimitError / (timeStep);
  82. maxMotorForce = m_maxLimitForce;
  83. }
  84. maxMotorForce *= timeStep;
  85. // current velocity difference
  86. Vector3 vel_diff = body0->get_angular_velocity();
  87. if (body1) {
  88. vel_diff -= body1->get_angular_velocity();
  89. }
  90. real_t rel_vel = axis.dot(vel_diff);
  91. // correction velocity
  92. real_t motor_relvel = m_limitSoftness * (target_velocity - m_damping * rel_vel);
  93. if (Math::is_zero_approx(motor_relvel)) {
  94. return 0.0f; //no need for applying force
  95. }
  96. // correction impulse
  97. real_t unclippedMotorImpulse = (1 + m_bounce) * motor_relvel * jacDiagABInv;
  98. // clip correction impulse
  99. real_t clippedMotorImpulse;
  100. ///@todo: should clip against accumulated impulse
  101. if (unclippedMotorImpulse > 0.0f) {
  102. clippedMotorImpulse = unclippedMotorImpulse > maxMotorForce ? maxMotorForce : unclippedMotorImpulse;
  103. } else {
  104. clippedMotorImpulse = unclippedMotorImpulse < -maxMotorForce ? -maxMotorForce : unclippedMotorImpulse;
  105. }
  106. // sort with accumulated impulses
  107. real_t lo = real_t(-1e30);
  108. real_t hi = real_t(1e30);
  109. real_t oldaccumImpulse = m_accumulatedImpulse;
  110. real_t sum = oldaccumImpulse + clippedMotorImpulse;
  111. m_accumulatedImpulse = sum > hi ? real_t(0.) : (sum < lo ? real_t(0.) : sum);
  112. clippedMotorImpulse = m_accumulatedImpulse - oldaccumImpulse;
  113. Vector3 motorImp = clippedMotorImpulse * axis;
  114. if (p_body0_dynamic) {
  115. body0->apply_torque_impulse(motorImp);
  116. }
  117. if (body1 && p_body1_dynamic) {
  118. body1->apply_torque_impulse(-motorImp);
  119. }
  120. return clippedMotorImpulse;
  121. }
  122. //////////////////////////// GodotG6DOFTranslationalLimitMotor3D ////////////////////////////////////
  123. real_t GodotG6DOFTranslationalLimitMotor3D::solveLinearAxis(
  124. real_t timeStep,
  125. real_t jacDiagABInv,
  126. GodotBody3D *body1, const Vector3 &pointInA,
  127. GodotBody3D *body2, const Vector3 &pointInB,
  128. bool p_body1_dynamic, bool p_body2_dynamic,
  129. int limit_index,
  130. const Vector3 &axis_normal_on_a,
  131. const Vector3 &anchorPos) {
  132. ///find relative velocity
  133. // Vector3 rel_pos1 = pointInA - body1->get_transform().origin;
  134. // Vector3 rel_pos2 = pointInB - body2->get_transform().origin;
  135. Vector3 rel_pos1 = anchorPos - body1->get_transform().origin;
  136. Vector3 rel_pos2 = anchorPos - body2->get_transform().origin;
  137. Vector3 vel1 = body1->get_velocity_in_local_point(rel_pos1);
  138. Vector3 vel2 = body2->get_velocity_in_local_point(rel_pos2);
  139. Vector3 vel = vel1 - vel2;
  140. real_t rel_vel = axis_normal_on_a.dot(vel);
  141. /// apply displacement correction
  142. //positional error (zeroth order error)
  143. real_t depth = -(pointInA - pointInB).dot(axis_normal_on_a);
  144. real_t lo = real_t(-1e30);
  145. real_t hi = real_t(1e30);
  146. real_t minLimit = m_lowerLimit[limit_index];
  147. real_t maxLimit = m_upperLimit[limit_index];
  148. //handle the limits
  149. if (minLimit < maxLimit) {
  150. {
  151. if (depth > maxLimit) {
  152. depth -= maxLimit;
  153. lo = real_t(0.);
  154. } else {
  155. if (depth < minLimit) {
  156. depth -= minLimit;
  157. hi = real_t(0.);
  158. } else {
  159. return 0.0f;
  160. }
  161. }
  162. }
  163. }
  164. real_t normalImpulse = m_limitSoftness[limit_index] * (m_restitution[limit_index] * depth / timeStep - m_damping[limit_index] * rel_vel) * jacDiagABInv;
  165. real_t oldNormalImpulse = m_accumulatedImpulse[limit_index];
  166. real_t sum = oldNormalImpulse + normalImpulse;
  167. m_accumulatedImpulse[limit_index] = sum > hi ? real_t(0.) : (sum < lo ? real_t(0.) : sum);
  168. normalImpulse = m_accumulatedImpulse[limit_index] - oldNormalImpulse;
  169. Vector3 impulse_vector = axis_normal_on_a * normalImpulse;
  170. if (p_body1_dynamic) {
  171. body1->apply_impulse(impulse_vector, rel_pos1);
  172. }
  173. if (p_body2_dynamic) {
  174. body2->apply_impulse(-impulse_vector, rel_pos2);
  175. }
  176. return normalImpulse;
  177. }
  178. //////////////////////////// GodotGeneric6DOFJoint3D ////////////////////////////////////
  179. GodotGeneric6DOFJoint3D::GodotGeneric6DOFJoint3D(GodotBody3D *rbA, GodotBody3D *rbB, const Transform3D &frameInA, const Transform3D &frameInB, bool useLinearReferenceFrameA) :
  180. GodotJoint3D(_arr, 2),
  181. m_frameInA(frameInA),
  182. m_frameInB(frameInB),
  183. m_useLinearReferenceFrameA(useLinearReferenceFrameA) {
  184. A = rbA;
  185. B = rbB;
  186. A->add_constraint(this, 0);
  187. B->add_constraint(this, 1);
  188. }
  189. void GodotGeneric6DOFJoint3D::calculateAngleInfo() {
  190. Basis relative_frame = m_calculatedTransformB.basis.inverse() * m_calculatedTransformA.basis;
  191. m_calculatedAxisAngleDiff = relative_frame.get_euler(EulerOrder::XYZ);
  192. // in euler angle mode we do not actually constrain the angular velocity
  193. // along the axes axis[0] and axis[2] (although we do use axis[1]) :
  194. //
  195. // to get constrain w2-w1 along ...not
  196. // ------ --------------------- ------
  197. // d(angle[0])/dt = 0 ax[1] x ax[2] ax[0]
  198. // d(angle[1])/dt = 0 ax[1]
  199. // d(angle[2])/dt = 0 ax[0] x ax[1] ax[2]
  200. //
  201. // constraining w2-w1 along an axis 'a' means that a'*(w2-w1)=0.
  202. // to prove the result for angle[0], write the expression for angle[0] from
  203. // GetInfo1 then take the derivative. to prove this for angle[2] it is
  204. // easier to take the euler rate expression for d(angle[2])/dt with respect
  205. // to the components of w and set that to 0.
  206. Vector3 axis0 = m_calculatedTransformB.basis.get_column(0);
  207. Vector3 axis2 = m_calculatedTransformA.basis.get_column(2);
  208. m_calculatedAxis[1] = axis2.cross(axis0);
  209. m_calculatedAxis[0] = m_calculatedAxis[1].cross(axis2);
  210. m_calculatedAxis[2] = axis0.cross(m_calculatedAxis[1]);
  211. /*
  212. if(m_debugDrawer)
  213. {
  214. char buff[300];
  215. sprintf(buff,"\n X: %.2f ; Y: %.2f ; Z: %.2f ",
  216. m_calculatedAxisAngleDiff[0],
  217. m_calculatedAxisAngleDiff[1],
  218. m_calculatedAxisAngleDiff[2]);
  219. m_debugDrawer->reportErrorWarning(buff);
  220. }
  221. */
  222. }
  223. void GodotGeneric6DOFJoint3D::calculateTransforms() {
  224. m_calculatedTransformA = A->get_transform() * m_frameInA;
  225. m_calculatedTransformB = B->get_transform() * m_frameInB;
  226. calculateAngleInfo();
  227. }
  228. void GodotGeneric6DOFJoint3D::buildLinearJacobian(
  229. GodotJacobianEntry3D &jacLinear, const Vector3 &normalWorld,
  230. const Vector3 &pivotAInW, const Vector3 &pivotBInW) {
  231. memnew_placement(
  232. &jacLinear,
  233. GodotJacobianEntry3D(
  234. A->get_principal_inertia_axes().transposed(),
  235. B->get_principal_inertia_axes().transposed(),
  236. pivotAInW - A->get_transform().origin - A->get_center_of_mass(),
  237. pivotBInW - B->get_transform().origin - B->get_center_of_mass(),
  238. normalWorld,
  239. A->get_inv_inertia(),
  240. A->get_inv_mass(),
  241. B->get_inv_inertia(),
  242. B->get_inv_mass()));
  243. }
  244. void GodotGeneric6DOFJoint3D::buildAngularJacobian(
  245. GodotJacobianEntry3D &jacAngular, const Vector3 &jointAxisW) {
  246. memnew_placement(
  247. &jacAngular,
  248. GodotJacobianEntry3D(
  249. jointAxisW,
  250. A->get_principal_inertia_axes().transposed(),
  251. B->get_principal_inertia_axes().transposed(),
  252. A->get_inv_inertia(),
  253. B->get_inv_inertia()));
  254. }
  255. bool GodotGeneric6DOFJoint3D::testAngularLimitMotor(int axis_index) {
  256. real_t angle = m_calculatedAxisAngleDiff[axis_index];
  257. //test limits
  258. m_angularLimits[axis_index].testLimitValue(angle);
  259. return m_angularLimits[axis_index].needApplyTorques();
  260. }
  261. bool GodotGeneric6DOFJoint3D::setup(real_t p_timestep) {
  262. dynamic_A = (A->get_mode() > PhysicsServer3D::BODY_MODE_KINEMATIC);
  263. dynamic_B = (B->get_mode() > PhysicsServer3D::BODY_MODE_KINEMATIC);
  264. if (!dynamic_A && !dynamic_B) {
  265. return false;
  266. }
  267. // Clear accumulated impulses for the next simulation step
  268. m_linearLimits.m_accumulatedImpulse = Vector3(real_t(0.), real_t(0.), real_t(0.));
  269. int i;
  270. for (i = 0; i < 3; i++) {
  271. m_angularLimits[i].m_accumulatedImpulse = real_t(0.);
  272. }
  273. //calculates transform
  274. calculateTransforms();
  275. // const Vector3& pivotAInW = m_calculatedTransformA.origin;
  276. // const Vector3& pivotBInW = m_calculatedTransformB.origin;
  277. calcAnchorPos();
  278. Vector3 pivotAInW = m_AnchorPos;
  279. Vector3 pivotBInW = m_AnchorPos;
  280. // not used here
  281. // Vector3 rel_pos1 = pivotAInW - A->get_transform().origin;
  282. // Vector3 rel_pos2 = pivotBInW - B->get_transform().origin;
  283. Vector3 normalWorld;
  284. //linear part
  285. for (i = 0; i < 3; i++) {
  286. if (m_linearLimits.enable_limit[i] && m_linearLimits.isLimited(i)) {
  287. if (m_useLinearReferenceFrameA) {
  288. normalWorld = m_calculatedTransformA.basis.get_column(i);
  289. } else {
  290. normalWorld = m_calculatedTransformB.basis.get_column(i);
  291. }
  292. buildLinearJacobian(
  293. m_jacLinear[i], normalWorld,
  294. pivotAInW, pivotBInW);
  295. }
  296. }
  297. // angular part
  298. for (i = 0; i < 3; i++) {
  299. //calculates error angle
  300. if (m_angularLimits[i].m_enableLimit && testAngularLimitMotor(i)) {
  301. normalWorld = this->getAxis(i);
  302. // Create angular atom
  303. buildAngularJacobian(m_jacAng[i], normalWorld);
  304. }
  305. }
  306. return true;
  307. }
  308. void GodotGeneric6DOFJoint3D::solve(real_t p_timestep) {
  309. m_timeStep = p_timestep;
  310. //calculateTransforms();
  311. int i;
  312. // linear
  313. Vector3 pointInA = m_calculatedTransformA.origin;
  314. Vector3 pointInB = m_calculatedTransformB.origin;
  315. real_t jacDiagABInv;
  316. Vector3 linear_axis;
  317. for (i = 0; i < 3; i++) {
  318. if (m_linearLimits.enable_limit[i] && m_linearLimits.isLimited(i)) {
  319. jacDiagABInv = real_t(1.) / m_jacLinear[i].getDiagonal();
  320. if (m_useLinearReferenceFrameA) {
  321. linear_axis = m_calculatedTransformA.basis.get_column(i);
  322. } else {
  323. linear_axis = m_calculatedTransformB.basis.get_column(i);
  324. }
  325. m_linearLimits.solveLinearAxis(
  326. m_timeStep,
  327. jacDiagABInv,
  328. A, pointInA,
  329. B, pointInB,
  330. dynamic_A, dynamic_B,
  331. i, linear_axis, m_AnchorPos);
  332. }
  333. }
  334. // angular
  335. Vector3 angular_axis;
  336. real_t angularJacDiagABInv;
  337. for (i = 0; i < 3; i++) {
  338. if (m_angularLimits[i].m_enableLimit && m_angularLimits[i].needApplyTorques()) {
  339. // get axis
  340. angular_axis = getAxis(i);
  341. angularJacDiagABInv = real_t(1.) / m_jacAng[i].getDiagonal();
  342. m_angularLimits[i].solveAngularLimits(m_timeStep, angular_axis, angularJacDiagABInv, A, B, dynamic_A, dynamic_B);
  343. }
  344. }
  345. }
  346. void GodotGeneric6DOFJoint3D::updateRHS(real_t timeStep) {
  347. (void)timeStep;
  348. }
  349. Vector3 GodotGeneric6DOFJoint3D::getAxis(int axis_index) const {
  350. return m_calculatedAxis[axis_index];
  351. }
  352. real_t GodotGeneric6DOFJoint3D::getAngle(int axis_index) const {
  353. return m_calculatedAxisAngleDiff[axis_index];
  354. }
  355. void GodotGeneric6DOFJoint3D::calcAnchorPos() {
  356. real_t imA = A->get_inv_mass();
  357. real_t imB = B->get_inv_mass();
  358. real_t weight;
  359. if (imB == real_t(0.0)) {
  360. weight = real_t(1.0);
  361. } else {
  362. weight = imA / (imA + imB);
  363. }
  364. const Vector3 &pA = m_calculatedTransformA.origin;
  365. const Vector3 &pB = m_calculatedTransformB.origin;
  366. m_AnchorPos = pA * weight + pB * (real_t(1.0) - weight);
  367. }
  368. void GodotGeneric6DOFJoint3D::set_param(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param, real_t p_value) {
  369. ERR_FAIL_INDEX(p_axis, 3);
  370. switch (p_param) {
  371. case PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT: {
  372. m_linearLimits.m_lowerLimit[p_axis] = p_value;
  373. } break;
  374. case PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT: {
  375. m_linearLimits.m_upperLimit[p_axis] = p_value;
  376. } break;
  377. case PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS: {
  378. m_linearLimits.m_limitSoftness[p_axis] = p_value;
  379. } break;
  380. case PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION: {
  381. m_linearLimits.m_restitution[p_axis] = p_value;
  382. } break;
  383. case PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING: {
  384. m_linearLimits.m_damping[p_axis] = p_value;
  385. } break;
  386. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT: {
  387. m_angularLimits[p_axis].m_loLimit = p_value;
  388. } break;
  389. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT: {
  390. m_angularLimits[p_axis].m_hiLimit = p_value;
  391. } break;
  392. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS: {
  393. m_angularLimits[p_axis].m_limitSoftness = p_value;
  394. } break;
  395. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING: {
  396. m_angularLimits[p_axis].m_damping = p_value;
  397. } break;
  398. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION: {
  399. m_angularLimits[p_axis].m_bounce = p_value;
  400. } break;
  401. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_FORCE_LIMIT: {
  402. m_angularLimits[p_axis].m_maxLimitForce = p_value;
  403. } break;
  404. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP: {
  405. m_angularLimits[p_axis].m_ERP = p_value;
  406. } break;
  407. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY: {
  408. m_angularLimits[p_axis].m_targetVelocity = p_value;
  409. } break;
  410. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT: {
  411. m_angularLimits[p_axis].m_maxLimitForce = p_value;
  412. } break;
  413. case PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY: {
  414. // Not implemented in GodotPhysics3D backend
  415. } break;
  416. case PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT: {
  417. // Not implemented in GodotPhysics3D backend
  418. } break;
  419. case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS: {
  420. // Not implemented in GodotPhysics3D backend
  421. } break;
  422. case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING: {
  423. // Not implemented in GodotPhysics3D backend
  424. } break;
  425. case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT: {
  426. // Not implemented in GodotPhysics3D backend
  427. } break;
  428. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS: {
  429. // Not implemented in GodotPhysics3D backend
  430. } break;
  431. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING: {
  432. // Not implemented in GodotPhysics3D backend
  433. } break;
  434. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT: {
  435. // Not implemented in GodotPhysics3D backend
  436. } break;
  437. case PhysicsServer3D::G6DOF_JOINT_MAX:
  438. break; // Can't happen, but silences warning
  439. }
  440. }
  441. real_t GodotGeneric6DOFJoint3D::get_param(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisParam p_param) const {
  442. ERR_FAIL_INDEX_V(p_axis, 3, 0);
  443. switch (p_param) {
  444. case PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT: {
  445. return m_linearLimits.m_lowerLimit[p_axis];
  446. } break;
  447. case PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT: {
  448. return m_linearLimits.m_upperLimit[p_axis];
  449. } break;
  450. case PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS: {
  451. return m_linearLimits.m_limitSoftness[p_axis];
  452. } break;
  453. case PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION: {
  454. return m_linearLimits.m_restitution[p_axis];
  455. } break;
  456. case PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING: {
  457. return m_linearLimits.m_damping[p_axis];
  458. } break;
  459. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT: {
  460. return m_angularLimits[p_axis].m_loLimit;
  461. } break;
  462. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT: {
  463. return m_angularLimits[p_axis].m_hiLimit;
  464. } break;
  465. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS: {
  466. return m_angularLimits[p_axis].m_limitSoftness;
  467. } break;
  468. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING: {
  469. return m_angularLimits[p_axis].m_damping;
  470. } break;
  471. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION: {
  472. return m_angularLimits[p_axis].m_bounce;
  473. } break;
  474. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_FORCE_LIMIT: {
  475. return m_angularLimits[p_axis].m_maxLimitForce;
  476. } break;
  477. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP: {
  478. return m_angularLimits[p_axis].m_ERP;
  479. } break;
  480. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY: {
  481. return m_angularLimits[p_axis].m_targetVelocity;
  482. } break;
  483. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT: {
  484. return m_angularLimits[p_axis].m_maxMotorForce;
  485. } break;
  486. case PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY: {
  487. // Not implemented in GodotPhysics3D backend
  488. } break;
  489. case PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT: {
  490. // Not implemented in GodotPhysics3D backend
  491. } break;
  492. case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS: {
  493. // Not implemented in GodotPhysics3D backend
  494. } break;
  495. case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING: {
  496. // Not implemented in GodotPhysics3D backend
  497. } break;
  498. case PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT: {
  499. // Not implemented in GodotPhysics3D backend
  500. } break;
  501. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS: {
  502. // Not implemented in GodotPhysics3D backend
  503. } break;
  504. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING: {
  505. // Not implemented in GodotPhysics3D backend
  506. } break;
  507. case PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT: {
  508. // Not implemented in GodotPhysics3D backend
  509. } break;
  510. case PhysicsServer3D::G6DOF_JOINT_MAX:
  511. break; // Can't happen, but silences warning
  512. }
  513. return 0;
  514. }
  515. void GodotGeneric6DOFJoint3D::set_flag(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag, bool p_value) {
  516. ERR_FAIL_INDEX(p_axis, 3);
  517. switch (p_flag) {
  518. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT: {
  519. m_linearLimits.enable_limit[p_axis] = p_value;
  520. } break;
  521. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT: {
  522. m_angularLimits[p_axis].m_enableLimit = p_value;
  523. } break;
  524. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_MOTOR: {
  525. m_angularLimits[p_axis].m_enableMotor = p_value;
  526. } break;
  527. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR: {
  528. // Not implemented in GodotPhysics3D backend
  529. } break;
  530. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING: {
  531. // Not implemented in GodotPhysics3D backend
  532. } break;
  533. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING: {
  534. // Not implemented in GodotPhysics3D backend
  535. } break;
  536. case PhysicsServer3D::G6DOF_JOINT_FLAG_MAX:
  537. break; // Can't happen, but silences warning
  538. }
  539. }
  540. bool GodotGeneric6DOFJoint3D::get_flag(Vector3::Axis p_axis, PhysicsServer3D::G6DOFJointAxisFlag p_flag) const {
  541. ERR_FAIL_INDEX_V(p_axis, 3, 0);
  542. switch (p_flag) {
  543. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT: {
  544. return m_linearLimits.enable_limit[p_axis];
  545. } break;
  546. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT: {
  547. return m_angularLimits[p_axis].m_enableLimit;
  548. } break;
  549. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_MOTOR: {
  550. return m_angularLimits[p_axis].m_enableMotor;
  551. } break;
  552. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR: {
  553. // Not implemented in GodotPhysics3D backend
  554. } break;
  555. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING: {
  556. // Not implemented in GodotPhysics3D backend
  557. } break;
  558. case PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING: {
  559. // Not implemented in GodotPhysics3D backend
  560. } break;
  561. case PhysicsServer3D::G6DOF_JOINT_FLAG_MAX:
  562. break; // Can't happen, but silences warning
  563. }
  564. return false;
  565. }