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[s+1] = -1;
121  info->m_J2linearAxis[2*s+2] = -1;
122  */
123 
124  btVector3 a2 = body1_trans.getBasis()*getPivotInB();
125 
126  {
127  // btVector3 a2n = -a2;
128  btVector3* angular0 = (btVector3*)(info->m_J2angularAxis);
129  btVector3* angular1 = (btVector3*)(info->m_J2angularAxis+info->rowskip);
130  btVector3* angular2 = (btVector3*)(info->m_J2angularAxis+2*info->rowskip);
131  a2.getSkewSymmetricMatrix(angular0,angular1,angular2);
132  }
133 
134 
135 
136  // set right hand side
137  btScalar currERP = (m_flags & BT_P2P_FLAGS_ERP) ? m_erp : info->erp;
138  btScalar k = info->fps * currERP;
139  int j;
140  for (j=0; j<3; j++)
141  {
142  info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - a1[j] - body0_trans.getOrigin()[j]);
143  //printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]);
144  }
146  {
147  for (j=0; j<3; j++)
148  {
149  info->cfm[j*info->rowskip] = m_cfm;
150  }
151  }
152 
153  btScalar impulseClamp = m_setting.m_impulseClamp;//
154  for (j=0; j<3; j++)
155  {
156  if (m_setting.m_impulseClamp > 0)
157  {
158  info->m_lowerLimit[j*info->rowskip] = -impulseClamp;
159  info->m_upperLimit[j*info->rowskip] = impulseClamp;
160  }
161  }
162  info->m_damping = m_setting.m_damping;
163 
164 }
165 
166 
167 
169 {
170  (void)timeStep;
171 
172 }
173 
176 void btPoint2PointConstraint::setParam(int num, btScalar value, int axis)
177 {
178  if(axis != -1)
179  {
181  }
182  else
183  {
184  switch(num)
185  {
186  case BT_CONSTRAINT_ERP :
188  m_erp = value;
190  break;
191  case BT_CONSTRAINT_CFM :
193  m_cfm = value;
195  break;
196  default:
198  }
199  }
200 }
201 
204 {
205  btScalar retVal(SIMD_INFINITY);
206  if(axis != -1)
207  {
209  }
210  else
211  {
212  switch(num)
213  {
214  case BT_CONSTRAINT_ERP :
217  retVal = m_erp;
218  break;
219  case BT_CONSTRAINT_CFM :
222  retVal = m_cfm;
223  break;
224  default:
226  }
227  }
228  return retVal;
229 }
230