Bullet Collision Detection & Physics Library
btSphereSphereCollisionAlgorithm.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
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#define CLEAR_MANIFOLD 1
16
22
25 m_ownManifold(false),
26 m_manifoldPtr(mf)
27{
28 if (!m_manifoldPtr)
29 {
30 m_manifoldPtr = m_dispatcher->getNewManifold(col0Wrap->getCollisionObject(), col1Wrap->getCollisionObject());
31 m_ownManifold = true;
32 }
33}
34
36{
37 if (m_ownManifold)
38 {
39 if (m_manifoldPtr)
41 }
42}
43
45{
47
48 if (!m_manifoldPtr)
49 return;
50
51 resultOut->setPersistentManifold(m_manifoldPtr);
52
53 btSphereShape* sphere0 = (btSphereShape*)col0Wrap->getCollisionShape();
54 btSphereShape* sphere1 = (btSphereShape*)col1Wrap->getCollisionShape();
55
56 btVector3 diff = col0Wrap->getWorldTransform().getOrigin() - col1Wrap->getWorldTransform().getOrigin();
57 btScalar len = diff.length();
58 btScalar radius0 = sphere0->getRadius();
59 btScalar radius1 = sphere1->getRadius();
60
61#ifdef CLEAR_MANIFOLD
62 m_manifoldPtr->clearManifold(); //don't do this, it disables warmstarting
63#endif
64
66 if (len > (radius0 + radius1 + resultOut->m_closestPointDistanceThreshold))
67 {
68#ifndef CLEAR_MANIFOLD
69 resultOut->refreshContactPoints();
70#endif //CLEAR_MANIFOLD
71 return;
72 }
74 btScalar dist = len - (radius0 + radius1);
75
77 if (len > SIMD_EPSILON)
78 {
79 normalOnSurfaceB = diff / len;
80 }
81
85 btVector3 pos1 = col1Wrap->getWorldTransform().getOrigin() + radius1 * normalOnSurfaceB;
86
88
89 resultOut->addContactPoint(normalOnSurfaceB, pos1, dist);
90
91#ifndef CLEAR_MANIFOLD
92 resultOut->refreshContactPoints();
93#endif //CLEAR_MANIFOLD
94}
95
97{
98 (void)col0;
99 (void)col1;
102
103 //not yet
104 return btScalar(1.);
105}
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define SIMD_EPSILON
Definition btScalar.h:543
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
btCollisionObject can be used to manage collision detection objects.
virtual void releaseManifold(btPersistentManifold *manifold)=0
virtual btPersistentManifold * getNewManifold(const btCollisionObject *b0, const btCollisionObject *b1)=0
btManifoldResult is a helper class to manage contact results.
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
The btSphereShape implements an implicit sphere, centered around a local origin with radius.
virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btSphereSphereCollisionAlgorithm(btPersistentManifold *mf, const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *col0Wrap, const btCollisionObjectWrapper *col1Wrap)
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btScalar length() const
Return the length of the vector.
Definition btVector3.h:257