1 /*************************************************************************/ 2 /* cone_twist_joint_sw.h */ 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 31 /* 32 Adapted to Godot from the Bullet library. 33 */ 34 35 /* 36 Bullet Continuous Collision Detection and Physics Library 37 ConeTwistJointSW is Copyright (c) 2007 Starbreeze Studios 38 39 This software is provided 'as-is', without any express or implied warranty. 40 In no event will the authors be held liable for any damages arising from the use of this software. 41 Permission is granted to anyone to use this software for any purpose, 42 including commercial applications, and to alter it and redistribute it freely, 43 subject to the following restrictions: 44 45 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. 46 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 47 3. This notice may not be removed or altered from any source distribution. 48 49 Written by: Marcus Hennix 50 */ 51 52 #ifndef CONE_TWIST_JOINT_SW_H 53 #define CONE_TWIST_JOINT_SW_H 54 55 #include "servers/physics/joints/jacobian_entry_sw.h" 56 #include "servers/physics/joints_sw.h" 57 58 ///ConeTwistJointSW can be used to simulate ragdoll joints (upper arm, leg etc) 59 class ConeTwistJointSW : public JointSW { 60 #ifdef IN_PARALLELL_SOLVER 61 public: 62 #endif 63 64 union { 65 struct { 66 BodySW *A; 67 BodySW *B; 68 }; 69 70 BodySW *_arr[2]; 71 }; 72 73 JacobianEntrySW m_jac[3]; //3 orthogonal linear constraints 74 75 real_t m_appliedImpulse; 76 Transform m_rbAFrame; 77 Transform m_rbBFrame; 78 79 real_t m_limitSoftness; 80 real_t m_biasFactor; 81 real_t m_relaxationFactor; 82 83 real_t m_swingSpan1; 84 real_t m_swingSpan2; 85 real_t m_twistSpan; 86 87 Vector3 m_swingAxis; 88 Vector3 m_twistAxis; 89 90 real_t m_kSwing; 91 real_t m_kTwist; 92 93 real_t m_twistLimitSign; 94 real_t m_swingCorrection; 95 real_t m_twistCorrection; 96 97 real_t m_accSwingLimitImpulse; 98 real_t m_accTwistLimitImpulse; 99 100 bool m_angularOnly; 101 bool m_solveTwistLimit; 102 bool m_solveSwingLimit; 103 104 public: get_type()105 virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_CONE_TWIST; } 106 107 virtual bool setup(float p_step); 108 virtual void solve(float p_step); 109 110 ConeTwistJointSW(BodySW *rbA, BodySW *rbB, const Transform &rbAFrame, const Transform &rbBFrame); 111 setAngularOnly(bool angularOnly)112 void setAngularOnly(bool angularOnly) { 113 m_angularOnly = angularOnly; 114 } 115 116 void setLimit(real_t _swingSpan1, real_t _swingSpan2, real_t _twistSpan, real_t _softness = 0.8f, real_t _biasFactor = 0.3f, real_t _relaxationFactor = 1.0f) { 117 m_swingSpan1 = _swingSpan1; 118 m_swingSpan2 = _swingSpan2; 119 m_twistSpan = _twistSpan; 120 121 m_limitSoftness = _softness; 122 m_biasFactor = _biasFactor; 123 m_relaxationFactor = _relaxationFactor; 124 } 125 getSolveTwistLimit()126 inline int getSolveTwistLimit() { 127 return m_solveTwistLimit; 128 } 129 getSolveSwingLimit()130 inline int getSolveSwingLimit() { 131 return m_solveTwistLimit; 132 } 133 getTwistLimitSign()134 inline real_t getTwistLimitSign() { 135 return m_twistLimitSign; 136 } 137 138 void set_param(PhysicsServer::ConeTwistJointParam p_param, float p_value); 139 float get_param(PhysicsServer::ConeTwistJointParam p_param) const; 140 }; 141 142 #endif // CONE_TWIST_JOINT_SW_H 143