1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4
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:
10
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.
14 */
15
16 #ifndef B3_POINT2POINTCONSTRAINT_H
17 #define B3_POINT2POINTCONSTRAINT_H
18
19 #include "Bullet3Common/b3Vector3.h"
20 //#include "b3JacobianEntry.h"
21 #include "b3TypedConstraint.h"
22
23 class b3RigidBody;
24
25 #ifdef B3_USE_DOUBLE_PRECISION
26 #define b3Point2PointConstraintData b3Point2PointConstraintDoubleData
27 #define b3Point2PointConstraintDataName "b3Point2PointConstraintDoubleData"
28 #else
29 #define b3Point2PointConstraintData b3Point2PointConstraintFloatData
30 #define b3Point2PointConstraintDataName "b3Point2PointConstraintFloatData"
31 #endif //B3_USE_DOUBLE_PRECISION
32
33 struct b3ConstraintSetting
34 {
b3ConstraintSettingb3ConstraintSetting35 b3ConstraintSetting() : m_tau(b3Scalar(0.3)),
36 m_damping(b3Scalar(1.)),
37 m_impulseClamp(b3Scalar(0.))
38 {
39 }
40 b3Scalar m_tau;
41 b3Scalar m_damping;
42 b3Scalar m_impulseClamp;
43 };
44
45 enum b3Point2PointFlags
46 {
47 B3_P2P_FLAGS_ERP = 1,
48 B3_P2P_FLAGS_CFM = 2
49 };
50
51 /// point to point constraint between two rigidbodies each with a pivotpoint that descibes the 'ballsocket' location in local space
B3_ATTRIBUTE_ALIGNED16(class)52 B3_ATTRIBUTE_ALIGNED16(class)
53 b3Point2PointConstraint : public b3TypedConstraint
54 {
55 #ifdef IN_PARALLELL_SOLVER
56 public:
57 #endif
58
59 b3Vector3 m_pivotInA;
60 b3Vector3 m_pivotInB;
61
62 int m_flags;
63 b3Scalar m_erp;
64 b3Scalar m_cfm;
65
66 public:
67 B3_DECLARE_ALIGNED_ALLOCATOR();
68
69 b3ConstraintSetting m_setting;
70
71 b3Point2PointConstraint(int rbA, int rbB, const b3Vector3& pivotInA, const b3Vector3& pivotInB);
72
73 //b3Point2PointConstraint(int rbA,const b3Vector3& pivotInA);
74
75 virtual void getInfo1(b3ConstraintInfo1 * info, const b3RigidBodyData* bodies);
76
77 void getInfo1NonVirtual(b3ConstraintInfo1 * info, const b3RigidBodyData* bodies);
78
79 virtual void getInfo2(b3ConstraintInfo2 * info, const b3RigidBodyData* bodies);
80
81 void getInfo2NonVirtual(b3ConstraintInfo2 * info, const b3Transform& body0_trans, const b3Transform& body1_trans);
82
83 void updateRHS(b3Scalar timeStep);
84
85 void setPivotA(const b3Vector3& pivotA)
86 {
87 m_pivotInA = pivotA;
88 }
89
90 void setPivotB(const b3Vector3& pivotB)
91 {
92 m_pivotInB = pivotB;
93 }
94
95 const b3Vector3& getPivotInA() const
96 {
97 return m_pivotInA;
98 }
99
100 const b3Vector3& getPivotInB() const
101 {
102 return m_pivotInB;
103 }
104
105 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
106 ///If no axis is provided, it uses the default axis for this constraint.
107 virtual void setParam(int num, b3Scalar value, int axis = -1);
108 ///return the local value of parameter
109 virtual b3Scalar getParam(int num, int axis = -1) const;
110
111 // virtual int calculateSerializeBufferSize() const;
112
113 ///fills the dataBuffer and returns the struct name (and 0 on failure)
114 // virtual const char* serialize(void* dataBuffer, b3Serializer* serializer) const;
115 };
116
117 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
118 struct b3Point2PointConstraintFloatData
119 {
120 b3TypedConstraintData m_typeConstraintData;
121 b3Vector3FloatData m_pivotInA;
122 b3Vector3FloatData m_pivotInB;
123 };
124
125 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
126 struct b3Point2PointConstraintDoubleData
127 {
128 b3TypedConstraintData m_typeConstraintData;
129 b3Vector3DoubleData m_pivotInA;
130 b3Vector3DoubleData m_pivotInB;
131 };
132
133 /*
134 B3_FORCE_INLINE int b3Point2PointConstraint::calculateSerializeBufferSize() const
135 {
136 return sizeof(b3Point2PointConstraintData);
137
138 }
139
140 ///fills the dataBuffer and returns the struct name (and 0 on failure)
141 B3_FORCE_INLINE const char* b3Point2PointConstraint::serialize(void* dataBuffer, b3Serializer* serializer) const
142 {
143 b3Point2PointConstraintData* p2pData = (b3Point2PointConstraintData*)dataBuffer;
144
145 b3TypedConstraint::serialize(&p2pData->m_typeConstraintData,serializer);
146 m_pivotInA.serialize(p2pData->m_pivotInA);
147 m_pivotInB.serialize(p2pData->m_pivotInB);
148
149 return b3Point2PointConstraintDataName;
150 }
151 */
152
153 #endif //B3_POINT2POINTCONSTRAINT_H
154