File indexing completed on 2025-08-03 03:50:00
0001 /* 0002 * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com 0003 * 0004 * This software is provided 'as-is', without any express or implied 0005 * warranty. In no event will the authors be held liable for any damages 0006 * arising from the use of this software. 0007 * Permission is granted to anyone to use this software for any purpose, 0008 * including commercial applications, and to alter it and redistribute it 0009 * freely, subject to the following restrictions: 0010 * 1. The origin of this software must not be misrepresented; you must not 0011 * claim that you wrote the original software. If you use this software 0012 * in a product, an acknowledgment in the product documentation would be 0013 * appreciated but is not required. 0014 * 2. Altered source versions must be plainly marked as such, and must not be 0015 * misrepresented as being the original software. 0016 * 3. This notice may not be removed or altered from any source distribution. 0017 */ 0018 0019 #ifndef B2_WELD_JOINT_H 0020 #define B2_WELD_JOINT_H 0021 0022 #include <Box2D/Dynamics/Joints/b2Joint.h> 0023 0024 /// Weld joint definition. You need to specify local anchor points 0025 /// where they are attached and the relative body angle. The position 0026 /// of the anchor points is important for computing the reaction torque. 0027 struct b2WeldJointDef : public b2JointDef 0028 { 0029 b2WeldJointDef() 0030 { 0031 type = e_weldJoint; 0032 localAnchorA.Set(0.0f, 0.0f); 0033 localAnchorB.Set(0.0f, 0.0f); 0034 referenceAngle = 0.0f; 0035 } 0036 0037 /// Initialize the bodies, anchors, and reference angle using a world 0038 /// anchor point. 0039 void Initialize(b2Body* body1, b2Body* body2, const b2Vec2& anchor); 0040 0041 /// The local anchor point relative to body1's origin. 0042 b2Vec2 localAnchorA; 0043 0044 /// The local anchor point relative to body2's origin. 0045 b2Vec2 localAnchorB; 0046 0047 /// The body2 angle minus body1 angle in the reference state (radians). 0048 qreal referenceAngle; 0049 }; 0050 0051 /// A weld joint essentially glues two bodies together. A weld joint may 0052 /// distort somewhat because the island constraint solver is approximate. 0053 class b2WeldJoint : public b2Joint 0054 { 0055 public: 0056 b2Vec2 GetAnchorA() const override; 0057 b2Vec2 GetAnchorB() const override; 0058 0059 b2Vec2 GetReactionForce(qreal inv_dt) const override; 0060 qreal GetReactionTorque(qreal inv_dt) const override; 0061 0062 protected: 0063 0064 friend class b2Joint; 0065 0066 b2WeldJoint(const b2WeldJointDef* def); 0067 0068 void InitVelocityConstraints(const b2TimeStep& step) override; 0069 void SolveVelocityConstraints(const b2TimeStep& step) override; 0070 0071 bool SolvePositionConstraints(qreal baumgarte) override; 0072 0073 b2Vec2 m_localAnchorA; 0074 b2Vec2 m_localAnchorB; 0075 qreal m_referenceAngle; 0076 0077 b2Vec3 m_impulse; 0078 0079 b2Mat33 m_mass; 0080 }; 0081 0082 #endif