mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-15 06:00:12 +00:00
This commit is contained in:
parent
37c920db63
commit
3a9c5dcc35
@ -41,34 +41,36 @@ SphereSphereCollisionAlgorithm::~SphereSphereCollisionAlgorithm()
|
|||||||
|
|
||||||
void SphereSphereCollisionAlgorithm::ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo)
|
void SphereSphereCollisionAlgorithm::ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!m_manifoldPtr)
|
if (!m_manifoldPtr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CollisionObject* col0 = static_cast<CollisionObject*>(proxy0->m_clientObject);
|
CollisionObject* col0 = static_cast<CollisionObject*>(proxy0->m_clientObject);
|
||||||
CollisionObject* col1 = static_cast<CollisionObject*>(proxy1->m_clientObject);
|
CollisionObject* col1 = static_cast<CollisionObject*>(proxy1->m_clientObject);
|
||||||
|
|
||||||
SphereShape* sphere0 = (SphereShape*)col0->m_collisionShape;
|
SphereShape* sphere0 = (SphereShape*)col0->m_collisionShape;
|
||||||
SphereShape* sphere1 = (SphereShape*)col1->m_collisionShape;
|
SphereShape* sphere1 = (SphereShape*)col1->m_collisionShape;
|
||||||
|
|
||||||
|
SimdVector3 diff = col0->m_worldTransform.getOrigin()- col1->m_worldTransform.getOrigin();
|
||||||
|
float len = diff.length();
|
||||||
SimdScalar radius0 = sphere0->GetRadius();
|
SimdScalar radius0 = sphere0->GetRadius();
|
||||||
SimdScalar radius1 = sphere1->GetRadius();
|
SimdScalar radius1 = sphere1->GetRadius();
|
||||||
|
|
||||||
SimdVector3 diff = col0->m_worldTransform.getOrigin()-
|
///iff distance positive, don't generate a new contact
|
||||||
col1->m_worldTransform.getOrigin();
|
|
||||||
|
|
||||||
float len = diff.length();
|
|
||||||
if ( len > (radius0+radius1))
|
if ( len > (radius0+radius1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
///distance (negative means penetration)
|
||||||
SimdScalar dist = len - (radius0+radius1);
|
SimdScalar dist = len - (radius0+radius1);
|
||||||
|
|
||||||
SimdVector3 normalOnSurfaceB = diff / len;
|
SimdVector3 normalOnSurfaceB = diff / len;
|
||||||
|
///point on A (worldspace)
|
||||||
SimdVector3 pos0 = col0->m_worldTransform.getOrigin() - radius0 * normalOnSurfaceB;
|
SimdVector3 pos0 = col0->m_worldTransform.getOrigin() - radius0 * normalOnSurfaceB;
|
||||||
|
///point on B (worldspace)
|
||||||
SimdVector3 pos1 = col1->m_worldTransform.getOrigin() + radius1* normalOnSurfaceB;
|
SimdVector3 pos1 = col1->m_worldTransform.getOrigin() + radius1* normalOnSurfaceB;
|
||||||
|
|
||||||
|
/// report a contact. internally this will be kept persistent, and contact reduction is done
|
||||||
ManifoldResult* resultOut = m_dispatcher->GetNewManifoldResult(col0,col1,m_manifoldPtr);
|
ManifoldResult* resultOut = m_dispatcher->GetNewManifoldResult(col0,col1,m_manifoldPtr);
|
||||||
resultOut->AddContactPoint(normalOnSurfaceB,pos1,dist);
|
resultOut->AddContactPoint(normalOnSurfaceB,pos1,dist);
|
||||||
|
m_dispatcher->ReleaseManifoldResult(resultOut);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user