2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 #ifndef BT_POINT2POINTCONSTRAINT_H
17 #define BT_POINT2POINTCONSTRAINT_H
19 #include "LinearMath/btVector3.h"
20 #include "btJacobianEntry.h"
21 #include "btTypedConstraint.h"
25 #ifdef BT_USE_DOUBLE_PRECISION
26 #define btPoint2PointConstraintData2 btPoint2PointConstraintDoubleData2
27 #define btPoint2PointConstraintDataName "btPoint2PointConstraintDoubleData2"
29 #define btPoint2PointConstraintData2 btPoint2PointConstraintFloatData
30 #define btPoint2PointConstraintDataName "btPoint2PointConstraintFloatData"
31 #endif //BT_USE_DOUBLE_PRECISION
33 struct btConstraintSetting
35 btConstraintSetting() : m_tau(btScalar(0.3)),
36 m_damping(btScalar(1.)),
37 m_impulseClamp(btScalar(0.))
42 btScalar m_impulseClamp;
45 enum btPoint2PointFlags
51 /// point to point constraint between two rigidbodies each with a pivotpoint that descibes the 'ballsocket' location in local space
52 ATTRIBUTE_ALIGNED16(class)
53 btPoint2PointConstraint : public btTypedConstraint
55 #ifdef IN_PARALLELL_SOLVER
58 btJacobianEntry m_jac[3]; //3 orthogonal linear constraints
68 BT_DECLARE_ALIGNED_ALLOCATOR();
70 ///for backwards compatibility during the transition to 'getInfo/getInfo2'
71 bool m_useSolveConstraintObsolete;
73 btConstraintSetting m_setting;
75 btPoint2PointConstraint(btRigidBody & rbA, btRigidBody & rbB, const btVector3& pivotInA, const btVector3& pivotInB);
77 btPoint2PointConstraint(btRigidBody & rbA, const btVector3& pivotInA);
79 virtual void buildJacobian();
81 virtual void getInfo1(btConstraintInfo1 * info);
83 void getInfo1NonVirtual(btConstraintInfo1 * info);
85 virtual void getInfo2(btConstraintInfo2 * info);
87 void getInfo2NonVirtual(btConstraintInfo2 * info, const btTransform& body0_trans, const btTransform& body1_trans);
89 void updateRHS(btScalar timeStep);
91 void setPivotA(const btVector3& pivotA)
96 void setPivotB(const btVector3& pivotB)
101 const btVector3& getPivotInA() const
106 const btVector3& getPivotInB() const
111 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
112 ///If no axis is provided, it uses the default axis for this constraint.
113 virtual void setParam(int num, btScalar value, int axis = -1);
114 ///return the local value of parameter
115 virtual btScalar getParam(int num, int axis = -1) const;
117 virtual int getFlags() const
122 virtual int calculateSerializeBufferSize() const;
124 ///fills the dataBuffer and returns the struct name (and 0 on failure)
125 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
128 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
129 struct btPoint2PointConstraintFloatData
131 btTypedConstraintData m_typeConstraintData;
132 btVector3FloatData m_pivotInA;
133 btVector3FloatData m_pivotInB;
136 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
137 struct btPoint2PointConstraintDoubleData2
139 btTypedConstraintDoubleData m_typeConstraintData;
140 btVector3DoubleData m_pivotInA;
141 btVector3DoubleData m_pivotInB;
144 #ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
145 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
146 ///this structure is not used, except for loading pre-2.82 .bullet files
147 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
148 struct btPoint2PointConstraintDoubleData
150 btTypedConstraintData m_typeConstraintData;
151 btVector3DoubleData m_pivotInA;
152 btVector3DoubleData m_pivotInB;
154 #endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION
156 SIMD_FORCE_INLINE int btPoint2PointConstraint::calculateSerializeBufferSize() const
158 return sizeof(btPoint2PointConstraintData2);
161 ///fills the dataBuffer and returns the struct name (and 0 on failure)
162 SIMD_FORCE_INLINE const char* btPoint2PointConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
164 btPoint2PointConstraintData2* p2pData = (btPoint2PointConstraintData2*)dataBuffer;
166 btTypedConstraint::serialize(&p2pData->m_typeConstraintData, serializer);
167 m_pivotInA.serialize(p2pData->m_pivotInA);
168 m_pivotInB.serialize(p2pData->m_pivotInB);
170 return btPoint2PointConstraintDataName;
173 #endif //BT_POINT2POINTCONSTRAINT_H