Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp @ 9351

Last change on this file since 9351 was 8351, checked in by rgrieder, 14 years ago

Merged kicklib2 branch back to trunk (includes former branches ois_update, mac_osx and kicklib).

Notes for updating

Linux:
You don't need an extra package for CEGUILua and Tolua, it's already shipped with CEGUI.
However you do need to make sure that the OgreRenderer is installed too with CEGUI 0.7 (may be a separate package).
Also, Orxonox now recognises if you install the CgProgramManager (a separate package available on newer Ubuntu on Debian systems).

Windows:
Download the new dependency packages versioned 6.0 and use these. If you have problems with that or if you don't like the in game console problem mentioned below, you can download the new 4.3 version of the packages (only available for Visual Studio 2005/2008).

Key new features:

  • *Support for Mac OS X*
  • Visual Studio 2010 support
  • Bullet library update to 2.77
  • OIS library update to 1.3
  • Support for CEGUI 0.7 —> Support for Arch Linux and even SuSE
  • Improved install target
  • Compiles now with GCC 4.6
  • Ogre Cg Shader plugin activated for Linux if available
  • And of course lots of bug fixes

There are also some regressions:

  • No support for CEGUI 0.5, Ogre 1.4 and boost 1.35 - 1.39 any more
  • In game console is not working in main menu for CEGUI 0.7
  • Tolua (just the C lib, not the application) and CEGUILua libraries are no longer in our repository. —> You will need to get these as well when compiling Orxonox
  • And of course lots of new bugs we don't yet know about
  • Property svn:eol-style set to native
File size: 4.9 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 "btSubSimplexConvexCast.h"
18#include "BulletCollision/CollisionShapes/btConvexShape.h"
19
20#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
21#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
22#include "btPointCollector.h"
23#include "LinearMath/btTransformUtil.h"
24
25btSubsimplexConvexCast::btSubsimplexConvexCast (const btConvexShape* convexA,const btConvexShape* convexB,btSimplexSolverInterface* simplexSolver)
26:m_simplexSolver(simplexSolver),
27m_convexA(convexA),m_convexB(convexB)
28{
29}
30
31///Typically the conservative advancement reaches solution in a few iterations, clip it to 32 for degenerate cases.
32///See discussion about this here http://continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=565
33#ifdef BT_USE_DOUBLE_PRECISION
34#define MAX_ITERATIONS 64
35#else
36#define MAX_ITERATIONS 32
37#endif
38bool    btSubsimplexConvexCast::calcTimeOfImpact(
39                const btTransform& fromA,
40                const btTransform& toA,
41                const btTransform& fromB,
42                const btTransform& toB,
43                CastResult& result)
44{
45
46        m_simplexSolver->reset();
47
48        btVector3 linVelA,linVelB;
49        linVelA = toA.getOrigin()-fromA.getOrigin();
50        linVelB = toB.getOrigin()-fromB.getOrigin();
51
52        btScalar lambda = btScalar(0.);
53
54        btTransform interpolatedTransA = fromA;
55        btTransform interpolatedTransB = fromB;
56
57        ///take relative motion
58        btVector3 r = (linVelA-linVelB);
59        btVector3 v;
60       
61        btVector3 supVertexA = fromA(m_convexA->localGetSupportingVertex(-r*fromA.getBasis()));
62        btVector3 supVertexB = fromB(m_convexB->localGetSupportingVertex(r*fromB.getBasis()));
63        v = supVertexA-supVertexB;
64        int maxIter = MAX_ITERATIONS;
65
66        btVector3 n;
67        n.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
68        bool hasResult = false;
69        btVector3 c;
70
71        btScalar lastLambda = lambda;
72
73
74        btScalar dist2 = v.length2();
75#ifdef BT_USE_DOUBLE_PRECISION
76        btScalar epsilon = btScalar(0.0001);
77#else
78        btScalar epsilon = btScalar(0.0001);
79#endif //BT_USE_DOUBLE_PRECISION
80        btVector3       w,p;
81        btScalar VdotR;
82       
83        while ( (dist2 > epsilon) && maxIter--)
84        {
85                supVertexA = interpolatedTransA(m_convexA->localGetSupportingVertex(-v*interpolatedTransA.getBasis()));
86                supVertexB = interpolatedTransB(m_convexB->localGetSupportingVertex(v*interpolatedTransB.getBasis()));
87                w = supVertexA-supVertexB;
88
89                btScalar VdotW = v.dot(w);
90
91                if (lambda > btScalar(1.0))
92                {
93                        return false;
94                }
95
96                if ( VdotW > btScalar(0.))
97                {
98                        VdotR = v.dot(r);
99
100                        if (VdotR >= -(SIMD_EPSILON*SIMD_EPSILON))
101                                return false;
102                        else
103                        {
104                                lambda = lambda - VdotW / VdotR;
105                                //interpolate to next lambda
106                                //      x = s + lambda * r;
107                                interpolatedTransA.getOrigin().setInterpolate3(fromA.getOrigin(),toA.getOrigin(),lambda);
108                                interpolatedTransB.getOrigin().setInterpolate3(fromB.getOrigin(),toB.getOrigin(),lambda);
109                                //m_simplexSolver->reset();
110                                //check next line
111                                 w = supVertexA-supVertexB;
112                                lastLambda = lambda;
113                                n = v;
114                                hasResult = true;
115                        }
116                } 
117                ///Just like regular GJK only add the vertex if it isn't already (close) to current vertex, it would lead to divisions by zero and NaN etc.
118                if (!m_simplexSolver->inSimplex(w))
119                        m_simplexSolver->addVertex( w, supVertexA , supVertexB);
120
121                if (m_simplexSolver->closest(v))
122                {
123                        dist2 = v.length2();
124                        hasResult = true;
125                        //todo: check this normal for validity
126                        //n=v;
127                        //printf("V=%f , %f, %f\n",v[0],v[1],v[2]);
128                        //printf("DIST2=%f\n",dist2);
129                        //printf("numverts = %i\n",m_simplexSolver->numVertices());
130                } else
131                {
132                        dist2 = btScalar(0.);
133                } 
134        }
135
136        //int numiter = MAX_ITERATIONS - maxIter;
137//      printf("number of iterations: %d", numiter);
138       
139        //don't report a time of impact when moving 'away' from the hitnormal
140       
141
142        result.m_fraction = lambda;
143        if (n.length2() >= (SIMD_EPSILON*SIMD_EPSILON))
144                result.m_normal = n.normalized();
145        else
146                result.m_normal = btVector3(btScalar(0.0), btScalar(0.0), btScalar(0.0));
147
148        //don't report time of impact for motion away from the contact normal (or causes minor penetration)
149        if (result.m_normal.dot(r)>=-result.m_allowedPenetration)
150                return false;
151
152        btVector3 hitA,hitB;
153        m_simplexSolver->compute_points(hitA,hitB);
154        result.m_hitPoint=hitB;
155        return true;
156}
157
158
159
160
Note: See TracBrowser for help on using the repository browser.