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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btSphereTriangleCollisionAlgorithm.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
16#include "btSphereTriangleCollisionAlgorithm.h"
17#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
18#include "BulletCollision/CollisionShapes/btSphereShape.h"
19#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
20#include "SphereTriangleDetector.h"
21#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
22
23btSphereTriangleCollisionAlgorithm::btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool swapped)
24 : btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap),
25 m_ownManifold(false),
26 m_manifoldPtr(mf),
27 m_swapped(swapped)
28{
29 if (!m_manifoldPtr)
30 {
31 m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(), body1Wrap->getCollisionObject());
32 m_ownManifold = true;
33 }
34}
35
36btSphereTriangleCollisionAlgorithm::~btSphereTriangleCollisionAlgorithm()
37{
38 if (m_ownManifold)
39 {
40 if (m_manifoldPtr)
41 m_dispatcher->releaseManifold(m_manifoldPtr);
42 }
43}
44
45 void btSphereTriangleCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* col0Wrap, const btCollisionObjectWrapper* col1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
46{
47 if (!m_manifoldPtr)
48 return;
49
50 const btCollisionObjectWrapper* sphereObjWrap = m_swapped ? col1Wrap : col0Wrap;
51 const btCollisionObjectWrapper* triObjWrap = m_swapped ? col0Wrap : col1Wrap;
52
53 btSphereShape* sphere = (btSphereShape*)sphereObjWrap->getCollisionShape();
54 btTriangleShape* triangle = (btTriangleShape*)triObjWrap->getCollisionShape();
55
57 resultOut->setPersistentManifold(m_manifoldPtr);
58 SphereTriangleDetector detector(sphere, triangle, m_manifoldPtr->getContactBreakingThreshold() + resultOut->m_closestPointDistanceThreshold);
59
60 btDiscreteCollisionDetectorInterface::ClosestPointInput input;
61 input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);
62 input.m_transformA = sphereObjWrap->getWorldTransform();
63 input.m_transformB = triObjWrap->getWorldTransform();
64
65 bool swapResults = m_swapped;
66
67 detector.getClosestPoints(input, *resultOut, dispatchInfo.m_debugDraw, swapResults);
68
69 if (m_ownManifold)
70 resultOut->refreshContactPoints();
71}
72
73 btScalar btSphereTriangleCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0, btCollisionObject* col1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
74{
75 (void)resultOut;
76 (void)dispatchInfo;
77 (void)col0;
78 (void)col1;
79
80 //not yet
81 return btScalar(1.);
82}
SphereTriangleDetector.h
btCollisionDispatcher.h
btCollisionObjectWrapper.h
btCollisionObject.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
BT_LARGE_FLOAT
#define BT_LARGE_FLOAT
Definition: btScalar.h:316
btSphereShape.h
btSphereTriangleCollisionAlgorithm.h
btActivatingCollisionAlgorithm
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
Definition: btActivatingCollisionAlgorithm.h:23
btCollisionAlgorithm::m_dispatcher
btDispatcher * m_dispatcher
Definition: btCollisionAlgorithm.h:56
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:51
btDispatcher::releaseManifold
virtual void releaseManifold(btPersistentManifold *manifold)=0
btDispatcher::getNewManifold
virtual btPersistentManifold * getNewManifold(const btCollisionObject *b0, const btCollisionObject *b1)=0
btManifoldResult
btManifoldResult is a helper class to manage contact results.
Definition: btManifoldResult.h:48
btManifoldResult::setPersistentManifold
void setPersistentManifold(btPersistentManifold *manifoldPtr)
Definition: btManifoldResult.h:77
btManifoldResult::m_closestPointDistanceThreshold
btScalar m_closestPointDistanceThreshold
Definition: btManifoldResult.h:152
btManifoldResult::refreshContactPoints
void refreshContactPoints()
Definition: btManifoldResult.h:105
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:65
btPersistentManifold::getContactBreakingThreshold
btScalar getContactBreakingThreshold() const
Definition: btPersistentManifold.cpp:242
btSphereShape
The btSphereShape implements an implicit sphere, centered around a local origin with radius.
Definition: btSphereShape.h:25
btSphereTriangleCollisionAlgorithm::btSphereTriangleCollisionAlgorithm
btSphereTriangleCollisionAlgorithm(btPersistentManifold *mf, const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool swapped)
Definition: btSphereTriangleCollisionAlgorithm.cpp:23
btSphereTriangleCollisionAlgorithm::calculateTimeOfImpact
virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition: btSphereTriangleCollisionAlgorithm.cpp:73
btSphereTriangleCollisionAlgorithm::m_ownManifold
bool m_ownManifold
Definition: btSphereTriangleCollisionAlgorithm.h:30
btSphereTriangleCollisionAlgorithm::~btSphereTriangleCollisionAlgorithm
virtual ~btSphereTriangleCollisionAlgorithm()
Definition: btSphereTriangleCollisionAlgorithm.cpp:36
btSphereTriangleCollisionAlgorithm::m_manifoldPtr
btPersistentManifold * m_manifoldPtr
Definition: btSphereTriangleCollisionAlgorithm.h:31
btSphereTriangleCollisionAlgorithm::processCollision
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition: btSphereTriangleCollisionAlgorithm.cpp:45
btSphereTriangleCollisionAlgorithm::m_swapped
bool m_swapped
Definition: btSphereTriangleCollisionAlgorithm.h:32
btTriangleShape
Definition: btTriangleShape.h:24
SphereTriangleDetector
sphere-triangle to match the btDiscreteCollisionDetectorInterface
Definition: SphereTriangleDetector.h:26
SphereTriangleDetector::getClosestPoints
virtual void getClosestPoints(const ClosestPointInput &input, Result &output, class btIDebugDraw *debugDraw, bool swapResults=false)
Definition: SphereTriangleDetector.cpp:28
btCollisionAlgorithmConstructionInfo
Definition: btCollisionAlgorithm.h:33
btCollisionObjectWrapper
Definition: btCollisionObjectWrapper.h:18
btCollisionObjectWrapper::getCollisionShape
const btCollisionShape * getCollisionShape() const
Definition: btCollisionObjectWrapper.h:46
btCollisionObjectWrapper::getCollisionObject
const btCollisionObject * getCollisionObject() const
Definition: btCollisionObjectWrapper.h:45
btCollisionObjectWrapper::getWorldTransform
const btTransform & getWorldTransform() const
Definition: btCollisionObjectWrapper.h:44
btDiscreteCollisionDetectorInterface::ClosestPointInput
Definition: btDiscreteCollisionDetectorInterface.h:40
btDiscreteCollisionDetectorInterface::ClosestPointInput::m_transformB
btTransform m_transformB
Definition: btDiscreteCollisionDetectorInterface.h:47
btDiscreteCollisionDetectorInterface::ClosestPointInput::m_transformA
btTransform m_transformA
Definition: btDiscreteCollisionDetectorInterface.h:46
btDiscreteCollisionDetectorInterface::ClosestPointInput::m_maximumDistanceSquared
btScalar m_maximumDistanceSquared
Definition: btDiscreteCollisionDetectorInterface.h:48
btDispatcherInfo
Definition: btDispatcher.h:31
btDispatcherInfo::m_debugDraw
class btIDebugDraw * m_debugDraw
Definition: btDispatcher.h:58