Bullet Collision Detection & Physics Library
btFixedConstraint.cpp
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
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 
17 #include "btFixedConstraint.h"
20 #include <new>
21 
22 
25 {
26  m_pivotInA = frameInA.getOrigin();
27  m_pivotInB = frameInB.getOrigin();
28  m_relTargetAB = frameInA.getRotation()*frameInB.getRotation().inverse();
29 
30 }
31 
33 {
34 }
35 
36 
38 {
39  info->m_numConstraintRows = 6;
40  info->nub = 6;
41 }
42 
44 {
45  //fix the 3 linear degrees of freedom
46 
47 
48  const btVector3& worldPosA = m_rbA.getCenterOfMassTransform().getOrigin();
49  const btMatrix3x3& worldOrnA = m_rbA.getCenterOfMassTransform().getBasis();
50  const btVector3& worldPosB= m_rbB.getCenterOfMassTransform().getOrigin();
51  const btMatrix3x3& worldOrnB = m_rbB.getCenterOfMassTransform().getBasis();
52 
53 
54  info->m_J1linearAxis[0] = 1;
55  info->m_J1linearAxis[info->rowskip+1] = 1;
56  info->m_J1linearAxis[2*info->rowskip+2] = 1;
57 
58  btVector3 a1 = worldOrnA*m_pivotInA;
59  {
60  btVector3* angular0 = (btVector3*)(info->m_J1angularAxis);
61  btVector3* angular1 = (btVector3*)(info->m_J1angularAxis+info->rowskip);
62  btVector3* angular2 = (btVector3*)(info->m_J1angularAxis+2*info->rowskip);
63  btVector3 a1neg = -a1;
64  a1neg.getSkewSymmetricMatrix(angular0,angular1,angular2);
65  }
66 
67  if (info->m_J2linearAxis)
68  {
69  info->m_J2linearAxis[0] = -1;
70  info->m_J2linearAxis[info->rowskip+1] = -1;
71  info->m_J2linearAxis[2*info->rowskip+2] = -1;
72  }
73 
74  btVector3 a2 = worldOrnB*m_pivotInB;
75 
76  {
77  // btVector3 a2n = -a2;
78  btVector3* angular0 = (btVector3*)(info->m_J2angularAxis);
79  btVector3* angular1 = (btVector3*)(info->m_J2angularAxis+info->rowskip);
80  btVector3* angular2 = (btVector3*)(info->m_J2angularAxis+2*info->rowskip);
81  a2.getSkewSymmetricMatrix(angular0,angular1,angular2);
82  }
83 
84  // set right hand side for the linear dofs
85  btScalar k = info->fps * info->erp;
86 
87  btVector3 linearError = k*(a2+worldPosB-a1-worldPosA);
88  int j;
89  for (j=0; j<3; j++)
90  {
91 
92 
93 
94  info->m_constraintError[j*info->rowskip] = linearError[j];
95  //printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]);
96  }
97 
98  //fix the 3 angular degrees of freedom
99 
100  int start_row = 3;
101  int s = info->rowskip;
102  int start_index = start_row * s;
103 
104  // 3 rows to make body rotations equal
105  info->m_J1angularAxis[start_index] = 1;
106  info->m_J1angularAxis[start_index + s + 1] = 1;
107  info->m_J1angularAxis[start_index + s*2+2] = 1;
108  if ( info->m_J2angularAxis)
109  {
110  info->m_J2angularAxis[start_index] = -1;
111  info->m_J2angularAxis[start_index + s+1] = -1;
112  info->m_J2angularAxis[start_index + s*2+2] = -1;
113  }
114 
115  // set right hand side for the angular dofs
116 
117  btVector3 diff;
118  btScalar angle;
119  btMatrix3x3 mrelCur = worldOrnA *worldOrnB.inverse();
120  btQuaternion qrelCur;
121  mrelCur.getRotation(qrelCur);
123  diff*=-angle;
124  for (j=0; j<3; j++)
125  {
126  info->m_constraintError[(3+j)*info->rowskip] = k * diff[j];
127  }
128 
129 }
btMatrix3x3 inverse() const
Return the inverse of the matrix.
Definition: btMatrix3x3.h:1025
btQuaternion getRotation() const
Return a quaternion representing the rotation.
Definition: btTransform.h:122
static void calculateDiffAxisAngleQuaternion(const btQuaternion &orn0, const btQuaternion &orn1a, btVector3 &axis, btScalar &angle)
void getRotation(btQuaternion &q) const
Get the matrix represented as a quaternion.
Definition: btMatrix3x3.h:400
btVector3 & getOrigin()
Return the origin vector translation.
Definition: btTransform.h:117
const btTransform & getCenterOfMassTransform() const
Definition: btRigidBody.h:353
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
btQuaternion inverse() const
Return the inverse of this quaternion.
Definition: btQuaternion.h:446
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:59
btFixedConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB)
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
virtual void getInfo2(btConstraintInfo2 *info)
internal method used by the constraint solver, don't use them directly
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
virtual void getInfo1(btConstraintInfo1 *info)
internal method used by the constraint solver, don't use them directly
TypedConstraint is the baseclass for Bullet constraints and vehicles.
btQuaternion m_relTargetAB
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:48
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition: btQuaternion.h:48
void getSkewSymmetricMatrix(btVector3 *v0, btVector3 *v1, btVector3 *v2) const
Definition: btVector3.h:648
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266