Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp @ 5738

Last change on this file since 5738 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
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
17#include "btTypedConstraint.h"
18#include "BulletDynamics/Dynamics/btRigidBody.h"
19
20static btRigidBody s_fixed(0, 0,0);
21
22#define DEFAULT_DEBUGDRAW_SIZE btScalar(0.3f)
23
24btTypedConstraint::btTypedConstraint(btTypedConstraintType type)
25:m_userConstraintType(-1),
26m_userConstraintId(-1),
27m_constraintType (type),
28m_rbA(s_fixed),
29m_rbB(s_fixed),
30m_appliedImpulse(btScalar(0.)),
31m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE)
32{
33        s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
34}
35btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA)
36:m_userConstraintType(-1),
37m_userConstraintId(-1),
38m_constraintType (type),
39m_rbA(rbA),
40m_rbB(s_fixed),
41m_appliedImpulse(btScalar(0.)),
42m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE)
43{
44                s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
45
46}
47
48
49btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA,btRigidBody& rbB)
50:m_userConstraintType(-1),
51m_userConstraintId(-1),
52m_constraintType (type),
53m_rbA(rbA),
54m_rbB(rbB),
55m_appliedImpulse(btScalar(0.)),
56m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE)
57{
58                s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
59
60}
61
62
63//-----------------------------------------------------------------------------
64
65btScalar 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
Note: See TracBrowser for help on using the repository browser.