angular-only hinge updated
[blender.git] / extern / bullet2 / src / BulletDynamics / ConstraintSolver / btContactConstraint.h
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 CONTACT_CONSTRAINT_H
17 #define CONTACT_CONSTRAINT_H
18
19 //todo: make into a proper class working with the iterative constraint solver
20
21 class btRigidBody;
22 #include "LinearMath/btVector3.h"
23 #include "LinearMath/btScalar.h"
24 struct btContactSolverInfo;
25 class btManifoldPoint;
26
27 enum {
28         DEFAULT_CONTACT_SOLVER_TYPE=0,
29         CONTACT_SOLVER_TYPE1,
30         CONTACT_SOLVER_TYPE2,
31         USER_CONTACT_SOLVER_TYPE1,
32         MAX_CONTACT_SOLVER_TYPES
33 };
34
35
36 typedef float (*ContactSolverFunc)(btRigidBody& body1,
37                                                                          btRigidBody& body2,
38                                                                          class btManifoldPoint& contactPoint,
39                                                                          const btContactSolverInfo& info);
40
41 ///stores some extra information to each contact point. It is not in the contact point, because that want to keep the collision detection independent from the constraint solver.
42 struct btConstraintPersistentData
43 {
44         inline btConstraintPersistentData()
45         :m_appliedImpulse(0.f),
46         m_prevAppliedImpulse(0.f),
47         m_accumulatedTangentImpulse0(0.f),
48         m_accumulatedTangentImpulse1(0.f),
49         m_jacDiagABInv(0.f),
50         m_persistentLifeTime(0),
51         m_restitution(0.f),
52         m_friction(0.f),
53         m_penetration(0.f),
54         m_contactSolverFunc(0),
55         m_frictionSolverFunc(0)
56         {
57         }
58         
59                                         
60                                 /// total applied impulse during most recent frame
61                         float   m_appliedImpulse;
62                         float   m_prevAppliedImpulse;
63                         float   m_accumulatedTangentImpulse0;
64                         float   m_accumulatedTangentImpulse1;
65                         
66                         float   m_jacDiagABInv;
67                         float   m_jacDiagABInvTangent0;
68                         float   m_jacDiagABInvTangent1;
69                         int             m_persistentLifeTime;
70                         float   m_restitution;
71                         float   m_friction;
72                         float   m_penetration;
73                         btVector3       m_frictionWorldTangential0;
74                         btVector3       m_frictionWorldTangential1;
75
76                         btVector3       m_frictionAngularComponent0A;
77                         btVector3       m_frictionAngularComponent0B;
78                         btVector3       m_frictionAngularComponent1A;
79                         btVector3       m_frictionAngularComponent1B;
80
81                         //some data doesn't need to be persistent over frames: todo: clean/reuse this
82                         btVector3       m_angularComponentA;
83                         btVector3       m_angularComponentB;
84                 
85                         ContactSolverFunc       m_contactSolverFunc;
86                         ContactSolverFunc       m_frictionSolverFunc;
87
88 };
89
90 ///bilateral constraint between two dynamic objects
91 ///positive distance = separation, negative distance = penetration
92 void resolveSingleBilateral(btRigidBody& body1, const btVector3& pos1,
93                       btRigidBody& body2, const btVector3& pos2,
94                       btScalar distance, const btVector3& normal,btScalar& impulse ,float timeStep);
95
96
97 ///contact constraint resolution:
98 ///calculate and apply impulse to satisfy non-penetration and non-negative relative velocity constraint
99 ///positive distance = separation, negative distance = penetration
100 float resolveSingleCollision(
101         btRigidBody& body1,
102         btRigidBody& body2,
103                 btManifoldPoint& contactPoint,
104                  const btContactSolverInfo& info);
105
106 float resolveSingleFriction(
107         btRigidBody& body1,
108         btRigidBody& body2,
109         btManifoldPoint& contactPoint,
110         const btContactSolverInfo& solverInfo
111                 );
112
113 #endif //CONTACT_CONSTRAINT_H