Bullet Collision Detection & Physics Library: btJacobianEntry.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btJacobianEntry.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_JACOBIAN_ENTRY_H
17#define BT_JACOBIAN_ENTRY_H
18
19#include "LinearMath/btMatrix3x3.h"
20
21//notes:
22// Another memory optimization would be to store m_1MinvJt in the remaining 3 w components
23// which makes the btJacobianEntry memory layout 16 bytes
24// if you only are interested in angular part, just feed massInvA and massInvB zero
25
29 ATTRIBUTE_ALIGNED16(class)
30 btJacobianEntry
31{
32public:
33 btJacobianEntry(){};
34 //constraint between two different rigidbodies
35 btJacobianEntry(
36 const btMatrix3x3& world2A,
37 const btMatrix3x3& world2B,
38 const btVector3& rel_pos1, const btVector3& rel_pos2,
39 const btVector3& jointAxis,
40 const btVector3& inertiaInvA,
41 const btScalar massInvA,
42 const btVector3& inertiaInvB,
43 const btScalar massInvB)
44 : m_linearJointAxis(jointAxis)
45 {
46 m_aJ = world2A * (rel_pos1.cross(m_linearJointAxis));
47 m_bJ = world2B * (rel_pos2.cross(-m_linearJointAxis));
48 m_0MinvJt = inertiaInvA * m_aJ;
49 m_1MinvJt = inertiaInvB * m_bJ;
50 m_Adiag = massInvA + m_0MinvJt.dot(m_aJ) + massInvB + m_1MinvJt.dot(m_bJ);
51
52 btAssert(m_Adiag > btScalar(0.0));
53 }
54
55 //angular constraint between two different rigidbodies
56 btJacobianEntry(const btVector3& jointAxis,
57 const btMatrix3x3& world2A,
58 const btMatrix3x3& world2B,
59 const btVector3& inertiaInvA,
60 const btVector3& inertiaInvB)
61 : m_linearJointAxis(btVector3(btScalar(0.), btScalar(0.), btScalar(0.)))
62 {
63 m_aJ = world2A * jointAxis;
64 m_bJ = world2B * -jointAxis;
65 m_0MinvJt = inertiaInvA * m_aJ;
66 m_1MinvJt = inertiaInvB * m_bJ;
67 m_Adiag = m_0MinvJt.dot(m_aJ) + m_1MinvJt.dot(m_bJ);
68
69 btAssert(m_Adiag > btScalar(0.0));
70 }
71
72 //angular constraint between two different rigidbodies
73 btJacobianEntry(const btVector3& axisInA,
74 const btVector3& axisInB,
75 const btVector3& inertiaInvA,
76 const btVector3& inertiaInvB)
77 : m_linearJointAxis(btVector3(btScalar(0.), btScalar(0.), btScalar(0.))), m_aJ(axisInA), m_bJ(-axisInB)
78 {
79 m_0MinvJt = inertiaInvA * m_aJ;
80 m_1MinvJt = inertiaInvB * m_bJ;
81 m_Adiag = m_0MinvJt.dot(m_aJ) + m_1MinvJt.dot(m_bJ);
82
83 btAssert(m_Adiag > btScalar(0.0));
84 }
85
86 //constraint on one rigidbody
87 btJacobianEntry(
88 const btMatrix3x3& world2A,
89 const btVector3& rel_pos1, const btVector3& rel_pos2,
90 const btVector3& jointAxis,
91 const btVector3& inertiaInvA,
92 const btScalar massInvA)
93 : m_linearJointAxis(jointAxis)
94 {
95 m_aJ = world2A * (rel_pos1.cross(jointAxis));
96 m_bJ = world2A * (rel_pos2.cross(-jointAxis));
97 m_0MinvJt = inertiaInvA * m_aJ;
98 m_1MinvJt = btVector3(btScalar(0.), btScalar(0.), btScalar(0.));
99 m_Adiag = massInvA + m_0MinvJt.dot(m_aJ);
100
101 btAssert(m_Adiag > btScalar(0.0));
102 }
103
104 btScalar getDiagonal() const { return m_Adiag; }
105
106 // for two constraints on the same rigidbody (for example vehicle friction)
107 btScalar getNonDiagonal(const btJacobianEntry& jacB, const btScalar massInvA) const
108 {
109 const btJacobianEntry& jacA = *this;
110 btScalar lin = massInvA * jacA.m_linearJointAxis.dot(jacB.m_linearJointAxis);
111 btScalar ang = jacA.m_0MinvJt.dot(jacB.m_aJ);
112 return lin + ang;
113 }
114
115 // for two constraints on sharing two same rigidbodies (for example two contact points between two rigidbodies)
116 btScalar getNonDiagonal(const btJacobianEntry& jacB, const btScalar massInvA, const btScalar massInvB) const
117 {
118 const btJacobianEntry& jacA = *this;
119 btVector3 lin = jacA.m_linearJointAxis * jacB.m_linearJointAxis;
120 btVector3 ang0 = jacA.m_0MinvJt * jacB.m_aJ;
121 btVector3 ang1 = jacA.m_1MinvJt * jacB.m_bJ;
122 btVector3 lin0 = massInvA * lin;
123 btVector3 lin1 = massInvB * lin;
124 btVector3 sum = ang0 + ang1 + lin0 + lin1;
125 return sum[0] + sum[1] + sum[2];
126 }
127
128 btScalar getRelativeVelocity(const btVector3& linvelA, const btVector3& angvelA, const btVector3& linvelB, const btVector3& angvelB)
129 {
130 btVector3 linrel = linvelA - linvelB;
131 btVector3 angvela = angvelA * m_aJ;
132 btVector3 angvelb = angvelB * m_bJ;
133 linrel *= m_linearJointAxis;
134 angvela += angvelb;
135 angvela += linrel;
136 btScalar rel_vel2 = angvela[0] + angvela[1] + angvela[2];
137 return rel_vel2 + SIMD_EPSILON;
138 }
139 //private:
140
141 btVector3 m_linearJointAxis;
142 btVector3 m_aJ;
143 btVector3 m_bJ;
144 btVector3 m_0MinvJt;
145 btVector3 m_1MinvJt;
146 //Optimization: can be stored in the w/last component of one of the vectors
147 btScalar m_Adiag;
148};
149
150#endif //BT_JACOBIAN_ENTRY_H
btMatrix3x3.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
SIMD_EPSILON
#define SIMD_EPSILON
Definition: btScalar.h:543
btAssert
#define btAssert(x)
Definition: btScalar.h:153
sum
static T sum(const btAlignedObjectArray< T > &items)
Definition: btSoftBodyHelpers.cpp:95
btJacobianEntry
Jacobian entry is an abstraction that allows to describe constraints it can be used in combination wi...
Definition: btJacobianEntry.h:31
btJacobianEntry::btJacobianEntry
btJacobianEntry(const btMatrix3x3 &world2A, const btVector3 &rel_pos1, const btVector3 &rel_pos2, const btVector3 &jointAxis, const btVector3 &inertiaInvA, const btScalar massInvA)
Definition: btJacobianEntry.h:87
btJacobianEntry::btJacobianEntry
btJacobianEntry(const btVector3 &axisInA, const btVector3 &axisInB, const btVector3 &inertiaInvA, const btVector3 &inertiaInvB)
Definition: btJacobianEntry.h:73
btJacobianEntry::m_aJ
btVector3 m_aJ
Definition: btJacobianEntry.h:142
btJacobianEntry::getDiagonal
btScalar getDiagonal() const
Definition: btJacobianEntry.h:104
btJacobianEntry::m_0MinvJt
btVector3 m_0MinvJt
Definition: btJacobianEntry.h:144
btJacobianEntry::m_linearJointAxis
btVector3 m_linearJointAxis
Definition: btJacobianEntry.h:141
btJacobianEntry::m_Adiag
btScalar m_Adiag
Definition: btJacobianEntry.h:147
btJacobianEntry::m_bJ
btVector3 m_bJ
Definition: btJacobianEntry.h:143
btJacobianEntry::btJacobianEntry
btJacobianEntry(const btMatrix3x3 &world2A, const btMatrix3x3 &world2B, const btVector3 &rel_pos1, const btVector3 &rel_pos2, const btVector3 &jointAxis, const btVector3 &inertiaInvA, const btScalar massInvA, const btVector3 &inertiaInvB, const btScalar massInvB)
Definition: btJacobianEntry.h:35
btJacobianEntry::getNonDiagonal
btScalar getNonDiagonal(const btJacobianEntry &jacB, const btScalar massInvA) const
Definition: btJacobianEntry.h:107
btJacobianEntry::btJacobianEntry
btJacobianEntry()
Definition: btJacobianEntry.h:33
btJacobianEntry::btJacobianEntry
btJacobianEntry(const btVector3 &jointAxis, const btMatrix3x3 &world2A, const btMatrix3x3 &world2B, const btVector3 &inertiaInvA, const btVector3 &inertiaInvB)
Definition: btJacobianEntry.h:56
btJacobianEntry::m_1MinvJt
btVector3 m_1MinvJt
Definition: btJacobianEntry.h:145
btJacobianEntry::getRelativeVelocity
btScalar getRelativeVelocity(const btVector3 &linvelA, const btVector3 &angvelA, const btVector3 &linvelB, const btVector3 &angvelB)
Definition: btJacobianEntry.h:128
btJacobianEntry::getNonDiagonal
btScalar getNonDiagonal(const btJacobianEntry &jacB, const btScalar massInvA, const btScalar massInvB) const
Definition: btJacobianEntry.h:116
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btVector3::cross
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
Definition: btVector3.h:380
btVector3::dot
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:229