2017-08-01 12:30:58 +00:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
2022-01-06 22:37:49 +00:00
|
|
|
Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
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.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BT_MANIFOLD_RESULT_H
|
|
|
|
#define BT_MANIFOLD_RESULT_H
|
|
|
|
|
|
|
|
class btCollisionObject;
|
|
|
|
struct btCollisionObjectWrapper;
|
|
|
|
|
|
|
|
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
|
|
|
class btManifoldPoint;
|
|
|
|
|
|
|
|
#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
|
|
|
|
|
|
|
|
#include "LinearMath/btTransform.h"
|
|
|
|
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
|
|
|
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
typedef bool (*ContactAddedCallback)(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper* colObj1Wrap, int partId1, int index1);
|
|
|
|
extern ContactAddedCallback gContactAddedCallback;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
//#define DEBUG_PART_INDEX 1
|
|
|
|
|
|
|
|
/// These callbacks are used to customize the algorith that combine restitution, friction, damping, Stiffness
|
2019-01-03 13:26:51 +00:00
|
|
|
typedef btScalar (*CalculateCombinedCallback)(const btCollisionObject* body0, const btCollisionObject* body1);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
extern CalculateCombinedCallback gCalculateCombinedRestitutionCallback;
|
|
|
|
extern CalculateCombinedCallback gCalculateCombinedFrictionCallback;
|
|
|
|
extern CalculateCombinedCallback gCalculateCombinedRollingFrictionCallback;
|
|
|
|
extern CalculateCombinedCallback gCalculateCombinedSpinningFrictionCallback;
|
|
|
|
extern CalculateCombinedCallback gCalculateCombinedContactDampingCallback;
|
|
|
|
extern CalculateCombinedCallback gCalculateCombinedContactStiffnessCallback;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
///btManifoldResult is a helper class to manage contact results.
|
|
|
|
class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
btPersistentManifold* m_manifoldPtr;
|
|
|
|
|
|
|
|
const btCollisionObjectWrapper* m_body0Wrap;
|
|
|
|
const btCollisionObjectWrapper* m_body1Wrap;
|
2019-01-03 13:26:51 +00:00
|
|
|
int m_partId0;
|
2017-08-01 12:30:58 +00:00
|
|
|
int m_partId1;
|
|
|
|
int m_index0;
|
|
|
|
int m_index1;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
public:
|
2017-08-01 12:30:58 +00:00
|
|
|
btManifoldResult()
|
|
|
|
:
|
|
|
|
#ifdef DEBUG_PART_INDEX
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
m_partId0(-1),
|
|
|
|
m_partId1(-1),
|
|
|
|
m_index0(-1),
|
|
|
|
m_index1(-1)
|
|
|
|
#endif //DEBUG_PART_INDEX
|
|
|
|
m_closestPointDistanceThreshold(0)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btManifoldResult(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual ~btManifoldResult(){};
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void setPersistentManifold(btPersistentManifold* manifoldPtr)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_manifoldPtr = manifoldPtr;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
const btPersistentManifold* getPersistentManifold() const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_manifoldPtr;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
btPersistentManifold* getPersistentManifold()
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_manifoldPtr;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void setShapeIdentifiersA(int partId0, int index0)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_partId0 = partId0;
|
|
|
|
m_index0 = index0;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void setShapeIdentifiersB(int partId1, int index1)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_partId1 = partId1;
|
|
|
|
m_index1 = index1;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void addContactPoint(const btVector3& normalOnBInWorld, const btVector3& pointInWorld, btScalar depth);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
SIMD_FORCE_INLINE void refreshContactPoints()
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btAssert(m_manifoldPtr);
|
|
|
|
if (!m_manifoldPtr->getNumContacts())
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
|
|
|
|
|
|
|
|
if (isSwapped)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_manifoldPtr->refreshContactPoints(m_body1Wrap->getCollisionObject()->getWorldTransform(), m_body0Wrap->getCollisionObject()->getWorldTransform());
|
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_manifoldPtr->refreshContactPoints(m_body0Wrap->getCollisionObject()->getWorldTransform(), m_body1Wrap->getCollisionObject()->getWorldTransform());
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const btCollisionObjectWrapper* getBody0Wrap() const
|
|
|
|
{
|
|
|
|
return m_body0Wrap;
|
|
|
|
}
|
|
|
|
const btCollisionObjectWrapper* getBody1Wrap() const
|
|
|
|
{
|
|
|
|
return m_body1Wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBody0Wrap(const btCollisionObjectWrapper* obj0Wrap)
|
|
|
|
{
|
|
|
|
m_body0Wrap = obj0Wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBody1Wrap(const btCollisionObjectWrapper* obj1Wrap)
|
|
|
|
{
|
|
|
|
m_body1Wrap = obj1Wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
const btCollisionObject* getBody0Internal() const
|
|
|
|
{
|
|
|
|
return m_body0Wrap->getCollisionObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
const btCollisionObject* getBody1Internal() const
|
|
|
|
{
|
|
|
|
return m_body1Wrap->getCollisionObject();
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btScalar m_closestPointDistanceThreshold;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
/// in the future we can let the user override the methods to combine restitution and friction
|
2019-01-03 13:26:51 +00:00
|
|
|
static btScalar calculateCombinedRestitution(const btCollisionObject* body0, const btCollisionObject* body1);
|
|
|
|
static btScalar calculateCombinedFriction(const btCollisionObject* body0, const btCollisionObject* body1);
|
|
|
|
static btScalar calculateCombinedRollingFriction(const btCollisionObject* body0, const btCollisionObject* body1);
|
|
|
|
static btScalar calculateCombinedSpinningFriction(const btCollisionObject* body0, const btCollisionObject* body1);
|
|
|
|
static btScalar calculateCombinedContactDamping(const btCollisionObject* body0, const btCollisionObject* body1);
|
|
|
|
static btScalar calculateCombinedContactStiffness(const btCollisionObject* body0, const btCollisionObject* body1);
|
2017-08-01 12:30:58 +00:00
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //BT_MANIFOLD_RESULT_H
|