Bullet Collision Detection & Physics Library: btSphereSphereCollisionAlgorithm.cpp Source File

Bullet Collision Detection & Physics Library

btSphereSphereCollisionAlgorithm.cpp
Go to the documentation of this file.
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 #define CLEAR_MANIFOLD 1
16
17 #include "btSphereSphereCollisionAlgorithm.h"
18 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
19 #include "BulletCollision/CollisionShapes/btSphereShape.h"
20 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
21 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
22
23 btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap)
24 : btActivatingCollisionAlgorithm(ci,col0Wrap,col1Wrap),
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
35 btSphereSphereCollisionAlgorithm::~btSphereSphereCollisionAlgorithm()
36 {
37 if (m_ownManifold)
38 {
39 if (m_manifoldPtr)
40 m_dispatcher->releaseManifold(m_manifoldPtr);
41 }
42 }
43
44 void btSphereSphereCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
45 {
46 (void)dispatchInfo;
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
76 btVector3 normalOnSurfaceB(1,0,0);
77 if (len > SIMD_EPSILON)
78 {
79 normalOnSurfaceB = diff / len;
80 }
81
85 btVector3 pos1 = col1Wrap->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB;
86
88
89
90 resultOut->addContactPoint(normalOnSurfaceB,pos1,dist);
91
92 #ifndef CLEAR_MANIFOLD
93 resultOut->refreshContactPoints();
94 #endif //CLEAR_MANIFOLD
95
96 }
97
98 btScalar btSphereSphereCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
99 {
100 (void)col0;
101 (void)col1;
102 (void)dispatchInfo;
103 (void)resultOut;
104
105 //not yet
106 return btScalar(1.);
107 }
btDispatcher::releaseManifold
virtual void releaseManifold(btPersistentManifold *manifold)=0
SIMD_EPSILON
#define SIMD_EPSILON
Definition: btScalar.h:495
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:55
btSphereSphereCollisionAlgorithm::~btSphereSphereCollisionAlgorithm
virtual ~btSphereSphereCollisionAlgorithm()
Definition: btSphereSphereCollisionAlgorithm.cpp:35
btManifoldResult::setPersistentManifold
void setPersistentManifold(btPersistentManifold *manifoldPtr)
Definition: btManifoldResult.h:72
btActivatingCollisionAlgorithm
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
Definition: btActivatingCollisionAlgorithm.h:22
btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm
btSphereSphereCollisionAlgorithm(btPersistentManifold *mf, const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *col0Wrap, const btCollisionObjectWrapper *col1Wrap)
Definition: btSphereSphereCollisionAlgorithm.cpp:23
btManifoldResult::refreshContactPoints
void refreshContactPoints()
Definition: btManifoldResult.h:101
btSphereSphereCollisionAlgorithm.h
btSphereShape
The btSphereShape implements an implicit sphere, centered around a local origin with radius...
Definition: btSphereShape.h:22
btManifoldResult
btManifoldResult is a helper class to manage contact results.
Definition: btManifoldResult.h:39
btCollisionObjectWrapper::getCollisionShape
const btCollisionShape * getCollisionShape() const
Definition: btCollisionObjectWrapper.h:40
btCollisionAlgorithm::m_dispatcher
btDispatcher * m_dispatcher
Definition: btCollisionAlgorithm.h:60
btManifoldResult::addContactPoint
virtual void addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorld, btScalar depth)
Definition: btManifoldResult.cpp:104
btManifoldResult::m_closestPointDistanceThreshold
btScalar m_closestPointDistanceThreshold
Definition: btManifoldResult.h:147
btTransform::getOrigin
btVector3 & getOrigin()
Return the origin vector translation.
Definition: btTransform.h:117
btSphereShape::getRadius
btScalar getRadius() const
Definition: btSphereShape.h:47
btCollisionObjectWrapper::getCollisionObject
const btCollisionObject * getCollisionObject() const
Definition: btCollisionObjectWrapper.h:39
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btSphereSphereCollisionAlgorithm::calculateTimeOfImpact
virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition: btSphereSphereCollisionAlgorithm.cpp:98
btDispatcher::getNewManifold
virtual btPersistentManifold * getNewManifold(const btCollisionObject *b0, const btCollisionObject *b1)=0
btCollisionObjectWrapper.h
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btSphereSphereCollisionAlgorithm::processCollision
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition: btSphereSphereCollisionAlgorithm.cpp:44
btPersistentManifold::clearManifold
void clearManifold()
Definition: btPersistentManifold.h:216
btCollisionDispatcher.h
btCollisionObjectWrapper::getWorldTransform
const btTransform & getWorldTransform() const
Definition: btCollisionObjectWrapper.h:38
btCollisionObject.h
btDispatcherInfo
Definition: btDispatcher.h:30
btCollisionAlgorithmConstructionInfo
Definition: btCollisionAlgorithm.h:32
btSphereShape.h
btSphereSphereCollisionAlgorithm::m_ownManifold
bool m_ownManifold
Definition: btSphereSphereCollisionAlgorithm.h:31
btCollisionObjectWrapper
Definition: btCollisionObjectWrapper.h:17
btSphereSphereCollisionAlgorithm::m_manifoldPtr
btPersistentManifold * m_manifoldPtr
Definition: btSphereSphereCollisionAlgorithm.h:32
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279
btVector3::length
btScalar length() const
Return the length of the vector.
Definition: btVector3.h:263