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 TYPED_CONSTRAINT_H |
---|
17 | #define TYPED_CONSTRAINT_H |
---|
18 | |
---|
19 | class btRigidBody; |
---|
20 | #include "LinearMath/btScalar.h" |
---|
21 | #include "btSolverConstraint.h" |
---|
22 | struct btSolverBody; |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | enum btTypedConstraintType |
---|
28 | { |
---|
29 | POINT2POINT_CONSTRAINT_TYPE, |
---|
30 | HINGE_CONSTRAINT_TYPE, |
---|
31 | CONETWIST_CONSTRAINT_TYPE, |
---|
32 | D6_CONSTRAINT_TYPE, |
---|
33 | SLIDER_CONSTRAINT_TYPE |
---|
34 | }; |
---|
35 | |
---|
36 | ///TypedConstraint is the baseclass for Bullet constraints and vehicles |
---|
37 | class btTypedConstraint |
---|
38 | { |
---|
39 | int m_userConstraintType; |
---|
40 | int m_userConstraintId; |
---|
41 | |
---|
42 | btTypedConstraintType m_constraintType; |
---|
43 | |
---|
44 | btTypedConstraint& operator=(btTypedConstraint& other) |
---|
45 | { |
---|
46 | btAssert(0); |
---|
47 | (void) other; |
---|
48 | return *this; |
---|
49 | } |
---|
50 | |
---|
51 | protected: |
---|
52 | btRigidBody& m_rbA; |
---|
53 | btRigidBody& m_rbB; |
---|
54 | btScalar m_appliedImpulse; |
---|
55 | btScalar m_dbgDrawSize; |
---|
56 | |
---|
57 | |
---|
58 | public: |
---|
59 | |
---|
60 | btTypedConstraint(btTypedConstraintType type); |
---|
61 | virtual ~btTypedConstraint() {}; |
---|
62 | btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA); |
---|
63 | btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA,btRigidBody& rbB); |
---|
64 | |
---|
65 | struct btConstraintInfo1 { |
---|
66 | int m_numConstraintRows,nub; |
---|
67 | }; |
---|
68 | |
---|
69 | struct btConstraintInfo2 { |
---|
70 | // integrator parameters: frames per second (1/stepsize), default error |
---|
71 | // reduction parameter (0..1). |
---|
72 | btScalar fps,erp; |
---|
73 | |
---|
74 | // for the first and second body, pointers to two (linear and angular) |
---|
75 | // n*3 jacobian sub matrices, stored by rows. these matrices will have |
---|
76 | // been initialized to 0 on entry. if the second body is zero then the |
---|
77 | // J2xx pointers may be 0. |
---|
78 | btScalar *m_J1linearAxis,*m_J1angularAxis,*m_J2linearAxis,*m_J2angularAxis; |
---|
79 | |
---|
80 | // elements to jump from one row to the next in J's |
---|
81 | int rowskip; |
---|
82 | |
---|
83 | // right hand sides of the equation J*v = c + cfm * lambda. cfm is the |
---|
84 | // "constraint force mixing" vector. c is set to zero on entry, cfm is |
---|
85 | // set to a constant value (typically very small or zero) value on entry. |
---|
86 | btScalar *m_constraintError,*cfm; |
---|
87 | |
---|
88 | // lo and hi limits for variables (set to -/+ infinity on entry). |
---|
89 | btScalar *m_lowerLimit,*m_upperLimit; |
---|
90 | |
---|
91 | // findex vector for variables. see the LCP solver interface for a |
---|
92 | // description of what this does. this is set to -1 on entry. |
---|
93 | // note that the returned indexes are relative to the first index of |
---|
94 | // the constraint. |
---|
95 | int *findex; |
---|
96 | }; |
---|
97 | |
---|
98 | |
---|
99 | virtual void buildJacobian() = 0; |
---|
100 | |
---|
101 | virtual void setupSolverConstraint(btConstraintArray& ca, int solverBodyA,int solverBodyB, btScalar timeStep) |
---|
102 | { |
---|
103 | } |
---|
104 | virtual void getInfo1 (btConstraintInfo1* info)=0; |
---|
105 | |
---|
106 | virtual void getInfo2 (btConstraintInfo2* info)=0; |
---|
107 | |
---|
108 | virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) = 0; |
---|
109 | |
---|
110 | btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact); |
---|
111 | |
---|
112 | const btRigidBody& getRigidBodyA() const |
---|
113 | { |
---|
114 | return m_rbA; |
---|
115 | } |
---|
116 | const btRigidBody& getRigidBodyB() const |
---|
117 | { |
---|
118 | return m_rbB; |
---|
119 | } |
---|
120 | |
---|
121 | btRigidBody& getRigidBodyA() |
---|
122 | { |
---|
123 | return m_rbA; |
---|
124 | } |
---|
125 | btRigidBody& getRigidBodyB() |
---|
126 | { |
---|
127 | return m_rbB; |
---|
128 | } |
---|
129 | |
---|
130 | int getUserConstraintType() const |
---|
131 | { |
---|
132 | return m_userConstraintType ; |
---|
133 | } |
---|
134 | |
---|
135 | void setUserConstraintType(int userConstraintType) |
---|
136 | { |
---|
137 | m_userConstraintType = userConstraintType; |
---|
138 | }; |
---|
139 | |
---|
140 | void setUserConstraintId(int uid) |
---|
141 | { |
---|
142 | m_userConstraintId = uid; |
---|
143 | } |
---|
144 | |
---|
145 | int getUserConstraintId() const |
---|
146 | { |
---|
147 | return m_userConstraintId; |
---|
148 | } |
---|
149 | |
---|
150 | int getUid() const |
---|
151 | { |
---|
152 | return m_userConstraintId; |
---|
153 | } |
---|
154 | |
---|
155 | btScalar getAppliedImpulse() const |
---|
156 | { |
---|
157 | return m_appliedImpulse; |
---|
158 | } |
---|
159 | |
---|
160 | btTypedConstraintType getConstraintType () const |
---|
161 | { |
---|
162 | return m_constraintType; |
---|
163 | } |
---|
164 | |
---|
165 | void setDbgDrawSize(btScalar dbgDrawSize) |
---|
166 | { |
---|
167 | m_dbgDrawSize = dbgDrawSize; |
---|
168 | } |
---|
169 | btScalar getDbgDrawSize() |
---|
170 | { |
---|
171 | return m_dbgDrawSize; |
---|
172 | } |
---|
173 | |
---|
174 | }; |
---|
175 | |
---|
176 | #endif //TYPED_CONSTRAINT_H |
---|