Bullet Collision Detection & Physics Library
btPoint2PointConstraint.cpp
Go to the documentation of this file.
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 
19 #include <new>
20 
21 
22 
23 
24 
26 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA,rbB),m_pivotInA(pivotInA),m_pivotInB(pivotInB),
27 m_flags(0),
28 m_useSolveConstraintObsolete(false)
29 {
30 
31 }
32 
33 
35 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA),m_pivotInA(pivotInA),m_pivotInB(rbA.getCenterOfMassTransform()(pivotInA)),
36 m_flags(0),
37 m_useSolveConstraintObsolete(false)
38 {
39 
40 }
41 
43 {
44 
46  {
48 
49  btVector3 normal(0,0,0);
50 
51  for (int i=0;i<3;i++)
52  {
53  normal[i] = 1;
54  new (&m_jac[i]) btJacobianEntry(
59  normal,
61  m_rbA.getInvMass(),
63  m_rbB.getInvMass());
64  normal[i] = 0;
65  }
66  }
67 
68 
69 }
70 
72 {
73  getInfo1NonVirtual(info);
74 }
75 
77 {
79  {
80  info->m_numConstraintRows = 0;
81  info->nub = 0;
82  } else
83  {
84  info->m_numConstraintRows = 3;
85  info->nub = 3;
86  }
87 }
88 
89 
90 
91 
93 {
95 }
96 
97 void btPoint2PointConstraint::getInfo2NonVirtual (btConstraintInfo2* info, const btTransform& body0_trans, const btTransform& body1_trans)
98 {
100 
101  //retrieve matrices
102 
103  // anchor points in global coordinates with respect to body PORs.
104 
105  // set jacobian
106  info->m_J1linearAxis[0] = 1;
107  info->m_J1linearAxis[info->rowskip+1] = 1;
108  info->m_J1linearAxis[2*info->rowskip+2] = 1;
109 
110  btVector3 a1 = body0_trans.getBasis()*getPivotInA();
111  {
112  btVector3* angular0 = (btVector3*)(info->m_J1angularAxis);
113  btVector3* angular1 = (btVector3*)(info->m_J1angularAxis+info->rowskip);
114  btVector3* angular2 = (btVector3*)(info->m_J1angularAxis+2*info->rowskip);
115  btVector3 a1neg = -a1;
116  a1neg.getSkewSymmetricMatrix(angular0,angular1,angular2);
117  }
118 
119  info->m_J2linearAxis[0] = -1;
120  info->m_J2linearAxis[info->rowskip+1] = -1;
121  info->m_J2linearAxis[2*info->rowskip+2] = -1;
122 
123  btVector3 a2 = body1_trans.getBasis()*getPivotInB();
124 
125  {
126  // btVector3 a2n = -a2;
127  btVector3* angular0 = (btVector3*)(info->m_J2angularAxis);
128  btVector3* angular1 = (btVector3*)(info->m_J2angularAxis+info->rowskip);
129  btVector3* angular2 = (btVector3*)(info->m_J2angularAxis+2*info->rowskip);
130  a2.getSkewSymmetricMatrix(angular0,angular1,angular2);
131  }
132 
133 
134 
135  // set right hand side
136  btScalar currERP = (m_flags & BT_P2P_FLAGS_ERP) ? m_erp : info->erp;
137  btScalar k = info->fps * currERP;
138  int j;
139  for (j=0; j<3; j++)
140  {
141  info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - a1[j] - body0_trans.getOrigin()[j]);
142  //printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]);
143  }
145  {
146  for (j=0; j<3; j++)
147  {
148  info->cfm[j*info->rowskip] = m_cfm;
149  }
150  }
151 
152  btScalar impulseClamp = m_setting.m_impulseClamp;//
153  for (j=0; j<3; j++)
154  {
155  if (m_setting.m_impulseClamp > 0)
156  {
157  info->m_lowerLimit[j*info->rowskip] = -impulseClamp;
158  info->m_upperLimit[j*info->rowskip] = impulseClamp;
159  }
160  }
161  info->m_damping = m_setting.m_damping;
162 
163 }
164 
165 
166 
168 {
169  (void)timeStep;
170 
171 }
172 
175 void btPoint2PointConstraint::setParam(int num, btScalar value, int axis)
176 {
177  if(axis != -1)
178  {
180  }
181  else
182  {
183  switch(num)
184  {
185  case BT_CONSTRAINT_ERP :
187  m_erp = value;
189  break;
190  case BT_CONSTRAINT_CFM :
192  m_cfm = value;
194  break;
195  default:
197  }
198  }
199 }
200 
203 {
204  btScalar retVal(SIMD_INFINITY);
205  if(axis != -1)
206  {
208  }
209  else
210  {
211  switch(num)
212  {
213  case BT_CONSTRAINT_ERP :
216  retVal = m_erp;
217  break;
218  case BT_CONSTRAINT_CFM :
221  retVal = m_cfm;
222  break;
223  default:
225  }
226  }
227  return retVal;
228 }
229 
btTypedConstraint::btConstraintInfo2::m_damping
btScalar m_damping
Definition: btTypedConstraint.h:152
BT_CONSTRAINT_CFM
@ BT_CONSTRAINT_CFM
Definition: btTypedConstraint.h:56
btTypedConstraint
TypedConstraint is the baseclass for Bullet constraints and vehicles.
Definition: btTypedConstraint.h:78
btPoint2PointConstraint::getPivotInA
const btVector3 & getPivotInA() const
Definition: btPoint2PointConstraint.h:104
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:62
btAssertConstrParams
#define btAssertConstrParams(_par)
Definition: btTypedConstraint.h:61
BT_P2P_FLAGS_ERP
@ BT_P2P_FLAGS_ERP
Definition: btPoint2PointConstraint.h:49
btPoint2PointConstraint::m_setting
btConstraintSetting m_setting
Definition: btPoint2PointConstraint.h:75
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
btJacobianEntry
Jacobian entry is an abstraction that allows to describe constraints it can be used in combination wi...
Definition: btJacobianEntry.h:30
btPoint2PointConstraint::getInfo2
virtual void getInfo2(btConstraintInfo2 *info)
internal method used by the constraint solver, don't use them directly
Definition: btPoint2PointConstraint.cpp:92
btTypedConstraint::btConstraintInfo2::m_J2angularAxis
btScalar * m_J2angularAxis
Definition: btTypedConstraint.h:135
btConstraintSetting::m_impulseClamp
btScalar m_impulseClamp
Definition: btPoint2PointConstraint.h:44
btRigidBody.h
btTypedConstraint::btConstraintInfo2::m_J2linearAxis
btScalar * m_J2linearAxis
Definition: btTypedConstraint.h:135
btPoint2PointConstraint::btPoint2PointConstraint
btPoint2PointConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &pivotInA, const btVector3 &pivotInB)
Definition: btPoint2PointConstraint.cpp:25
btTypedConstraint::btConstraintInfo1::m_numConstraintRows
int m_numConstraintRows
Definition: btTypedConstraint.h:121
btPoint2PointConstraint::getPivotInB
const btVector3 & getPivotInB() const
Definition: btPoint2PointConstraint.h:109
btRigidBody::getCenterOfMassTransform
const btTransform & getCenterOfMassTransform() const
Definition: btRigidBody.h:359
btPoint2PointConstraint::m_useSolveConstraintObsolete
bool m_useSolveConstraintObsolete
for backwards compatibility during the transition to 'getInfo/getInfo2'
Definition: btPoint2PointConstraint.h:73
BT_CONSTRAINT_STOP_ERP
@ BT_CONSTRAINT_STOP_ERP
Definition: btTypedConstraint.h:55
btRigidBody::getInvInertiaDiagLocal
const btVector3 & getInvInertiaDiagLocal() const
Definition: btRigidBody.h:297
btAssert
#define btAssert(x)
Definition: btScalar.h:131
btPoint2PointConstraint::m_flags
int m_flags
Definition: btPoint2PointConstraint.h:64
btTypedConstraint::btConstraintInfo2::erp
btScalar erp
Definition: btTypedConstraint.h:129
btPoint2PointConstraint::setParam
virtual void setParam(int num, btScalar value, int axis=-1)
override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0...
Definition: btPoint2PointConstraint.cpp:175
btTransform::getBasis
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
btPoint2PointConstraint::getInfo2NonVirtual
void getInfo2NonVirtual(btConstraintInfo2 *info, const btTransform &body0_trans, const btTransform &body1_trans)
Definition: btPoint2PointConstraint.cpp:97
POINT2POINT_CONSTRAINT_TYPE
@ POINT2POINT_CONSTRAINT_TYPE
Definition: btTypedConstraint.h:38
btTypedConstraint::btConstraintInfo2::m_lowerLimit
btScalar * m_lowerLimit
Definition: btTypedConstraint.h:146
btTypedConstraint::btConstraintInfo2::m_constraintError
btScalar * m_constraintError
Definition: btTypedConstraint.h:143
btMatrix3x3::transpose
btMatrix3x3 transpose() const
Return the transpose of the matrix.
Definition: btMatrix3x3.h:958
BT_CONSTRAINT_STOP_CFM
@ BT_CONSTRAINT_STOP_CFM
Definition: btTypedConstraint.h:57
btRigidBody::getInvMass
btScalar getInvMass() const
Definition: btRigidBody.h:273
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
SIMD_INFINITY
#define SIMD_INFINITY
Definition: btScalar.h:522
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btTypedConstraint::btConstraintInfo1
Definition: btTypedConstraint.h:120
btTransform::getOrigin
btVector3 & getOrigin()
Return the origin vector translation.
Definition: btTransform.h:117
btPoint2PointConstraint::buildJacobian
virtual void buildJacobian()
internal method used by the constraint solver, don't use them directly
Definition: btPoint2PointConstraint.cpp:42
btTypedConstraint::btConstraintInfo2::rowskip
int rowskip
Definition: btTypedConstraint.h:138
btTypedConstraint::m_appliedImpulse
btScalar m_appliedImpulse
Definition: btTypedConstraint.h:104
btTypedConstraint::btConstraintInfo1::nub
int nub
Definition: btTypedConstraint.h:121
BT_CONSTRAINT_ERP
@ BT_CONSTRAINT_ERP
Definition: btTypedConstraint.h:54
btConstraintSetting::m_damping
btScalar m_damping
Definition: btPoint2PointConstraint.h:43
btPoint2PointConstraint::getInfo1
virtual void getInfo1(btConstraintInfo1 *info)
internal method used by the constraint solver, don't use them directly
Definition: btPoint2PointConstraint.cpp:71
btTypedConstraint::btConstraintInfo2::cfm
btScalar * cfm
Definition: btTypedConstraint.h:143
btPoint2PointConstraint::m_cfm
btScalar m_cfm
Definition: btPoint2PointConstraint.h:66
BT_P2P_FLAGS_CFM
@ BT_P2P_FLAGS_CFM
Definition: btPoint2PointConstraint.h:50
btPoint2PointConstraint::m_pivotInA
btVector3 m_pivotInA
Definition: btPoint2PointConstraint.h:61
btTypedConstraint::btConstraintInfo2
Definition: btTypedConstraint.h:126
btPoint2PointConstraint::m_jac
btJacobianEntry m_jac[3]
Definition: btPoint2PointConstraint.h:59
btPoint2PointConstraint::getInfo1NonVirtual
void getInfo1NonVirtual(btConstraintInfo1 *info)
Definition: btPoint2PointConstraint.cpp:76
btTypedConstraint::m_rbB
btRigidBody & m_rbB
Definition: btTypedConstraint.h:103
btRigidBody::getCenterOfMassPosition
const btVector3 & getCenterOfMassPosition() const
Definition: btRigidBody.h:354
btTypedConstraint::btConstraintInfo2::fps
btScalar fps
Definition: btTypedConstraint.h:129
btPoint2PointConstraint::m_pivotInB
btVector3 m_pivotInB
Definition: btPoint2PointConstraint.h:62
btTypedConstraint::btConstraintInfo2::m_J1angularAxis
btScalar * m_J1angularAxis
Definition: btTypedConstraint.h:135
btPoint2PointConstraint::m_erp
btScalar m_erp
Definition: btPoint2PointConstraint.h:65
btVector3::getSkewSymmetricMatrix
void getSkewSymmetricMatrix(btVector3 *v0, btVector3 *v1, btVector3 *v2) const
Definition: btVector3.h:660
btTypedConstraint::btConstraintInfo2::m_upperLimit
btScalar * m_upperLimit
Definition: btTypedConstraint.h:146
btPoint2PointConstraint::getParam
virtual btScalar getParam(int num, int axis=-1) const
return the local value of parameter
Definition: btPoint2PointConstraint.cpp:202
btTypedConstraint::m_rbA
btRigidBody & m_rbA
Definition: btTypedConstraint.h:102
btTypedConstraint::btConstraintInfo2::m_J1linearAxis
btScalar * m_J1linearAxis
Definition: btTypedConstraint.h:135
btPoint2PointConstraint::updateRHS
void updateRHS(btScalar timeStep)
Definition: btPoint2PointConstraint.cpp:167
btPoint2PointConstraint.h