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 | |
---|
17 | #include "btTypedConstraint.h" |
---|
18 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
19 | |
---|
20 | static btRigidBody s_fixed(0, 0,0); |
---|
21 | |
---|
22 | #define DEFAULT_DEBUGDRAW_SIZE btScalar(0.3f) |
---|
23 | |
---|
24 | btTypedConstraint::btTypedConstraint(btTypedConstraintType type) |
---|
25 | :m_userConstraintType(-1), |
---|
26 | m_userConstraintId(-1), |
---|
27 | m_constraintType (type), |
---|
28 | m_rbA(s_fixed), |
---|
29 | m_rbB(s_fixed), |
---|
30 | m_appliedImpulse(btScalar(0.)), |
---|
31 | m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE) |
---|
32 | { |
---|
33 | s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.))); |
---|
34 | } |
---|
35 | btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA) |
---|
36 | :m_userConstraintType(-1), |
---|
37 | m_userConstraintId(-1), |
---|
38 | m_constraintType (type), |
---|
39 | m_rbA(rbA), |
---|
40 | m_rbB(s_fixed), |
---|
41 | m_appliedImpulse(btScalar(0.)), |
---|
42 | m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE) |
---|
43 | { |
---|
44 | s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.))); |
---|
45 | |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA,btRigidBody& rbB) |
---|
50 | :m_userConstraintType(-1), |
---|
51 | m_userConstraintId(-1), |
---|
52 | m_constraintType (type), |
---|
53 | m_rbA(rbA), |
---|
54 | m_rbB(rbB), |
---|
55 | m_appliedImpulse(btScalar(0.)), |
---|
56 | m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE) |
---|
57 | { |
---|
58 | s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.))); |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | //----------------------------------------------------------------------------- |
---|
64 | |
---|
65 | btScalar btTypedConstraint::getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact) |
---|
66 | { |
---|
67 | if(lowLim > uppLim) |
---|
68 | { |
---|
69 | return btScalar(1.0f); |
---|
70 | } |
---|
71 | else if(lowLim == uppLim) |
---|
72 | { |
---|
73 | return btScalar(0.0f); |
---|
74 | } |
---|
75 | btScalar lim_fact = btScalar(1.0f); |
---|
76 | btScalar delta_max = vel / timeFact; |
---|
77 | if(delta_max < btScalar(0.0f)) |
---|
78 | { |
---|
79 | if((pos >= lowLim) && (pos < (lowLim - delta_max))) |
---|
80 | { |
---|
81 | lim_fact = (lowLim - pos) / delta_max; |
---|
82 | } |
---|
83 | else if(pos < lowLim) |
---|
84 | { |
---|
85 | lim_fact = btScalar(0.0f); |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | lim_fact = btScalar(1.0f); |
---|
90 | } |
---|
91 | } |
---|
92 | else if(delta_max > btScalar(0.0f)) |
---|
93 | { |
---|
94 | if((pos <= uppLim) && (pos > (uppLim - delta_max))) |
---|
95 | { |
---|
96 | lim_fact = (uppLim - pos) / delta_max; |
---|
97 | } |
---|
98 | else if(pos > uppLim) |
---|
99 | { |
---|
100 | lim_fact = btScalar(0.0f); |
---|
101 | } |
---|
102 | else |
---|
103 | { |
---|
104 | lim_fact = btScalar(1.0f); |
---|
105 | } |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | lim_fact = btScalar(0.0f); |
---|
110 | } |
---|
111 | return lim_fact; |
---|
112 | } // btTypedConstraint::getMotorFactor() |
---|
113 | |
---|
114 | |
---|