2017-08-01 12:30:58 +00:00
|
|
|
/*
|
|
|
|
This source file is part of GIMPACT Library.
|
|
|
|
|
|
|
|
For the latest info, see http://gimpact.sourceforge.net/
|
|
|
|
|
|
|
|
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
|
|
|
email: projectileman@yahoo.com
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
/*
|
2019-06-11 11:18:05 +00:00
|
|
|
Author: Francisco Leon Najera
|
2017-08-01 12:30:58 +00:00
|
|
|
Concave-Concave Collision
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BulletCollision/CollisionDispatch/btManifoldResult.h"
|
|
|
|
#include "LinearMath/btIDebugDraw.h"
|
|
|
|
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
|
|
|
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
|
|
|
#include "btGImpactCollisionAlgorithm.h"
|
|
|
|
#include "btContactProcessing.h"
|
|
|
|
#include "LinearMath/btQuickprof.h"
|
|
|
|
|
|
|
|
//! Class for accessing the plane equation
|
|
|
|
class btPlaneShape : public btStaticPlaneShape
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
btPlaneShape(const btVector3& v, float f)
|
2019-01-03 13:26:51 +00:00
|
|
|
: btStaticPlaneShape(v, f)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void get_plane_equation(btVector4& equation)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
equation[0] = m_planeNormal[0];
|
|
|
|
equation[1] = m_planeNormal[1];
|
|
|
|
equation[2] = m_planeNormal[2];
|
|
|
|
equation[3] = m_planeConstant;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void get_plane_equation_transformed(const btTransform& trans, btVector4& equation) const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btVector3 normal = trans.getBasis() * m_planeNormal;
|
|
|
|
equation[0] = normal[0];
|
|
|
|
equation[1] = normal[1];
|
|
|
|
equation[2] = normal[2];
|
|
|
|
equation[3] = normal.dot(trans * (m_planeConstant * m_planeNormal));
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef TRI_COLLISION_PROFILING
|
|
|
|
|
|
|
|
btClock g_triangle_clock;
|
|
|
|
|
|
|
|
float g_accum_triangle_collision_time = 0;
|
|
|
|
int g_count_triangle_collision = 0;
|
|
|
|
|
|
|
|
void bt_begin_gim02_tri_time()
|
|
|
|
{
|
|
|
|
g_triangle_clock.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void bt_end_gim02_tri_time()
|
|
|
|
{
|
|
|
|
g_accum_triangle_collision_time += g_triangle_clock.getTimeMicroseconds();
|
|
|
|
g_count_triangle_collision++;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //TRI_COLLISION_PROFILING
|
2017-08-01 12:30:58 +00:00
|
|
|
//! Retrieving shapes shapes
|
|
|
|
/*!
|
|
|
|
Declared here due of insuficent space on Pool allocators
|
|
|
|
*/
|
|
|
|
//!@{
|
|
|
|
class GIM_ShapeRetriever
|
|
|
|
{
|
|
|
|
public:
|
2019-01-03 13:26:51 +00:00
|
|
|
const btGImpactShapeInterface* m_gim_shape;
|
2017-08-01 12:30:58 +00:00
|
|
|
btTriangleShapeEx m_trishape;
|
|
|
|
btTetrahedronShapeEx m_tetrashape;
|
|
|
|
|
|
|
|
public:
|
|
|
|
class ChildShapeRetriever
|
|
|
|
{
|
|
|
|
public:
|
2019-01-03 13:26:51 +00:00
|
|
|
GIM_ShapeRetriever* m_parent;
|
|
|
|
virtual const btCollisionShape* getChildShape(int index)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_parent->m_gim_shape->getChildShape(index);
|
|
|
|
}
|
|
|
|
virtual ~ChildShapeRetriever() {}
|
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
class TriangleShapeRetriever : public ChildShapeRetriever
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual btCollisionShape* getChildShape(int index)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_parent->m_gim_shape->getBulletTriangle(index, m_parent->m_trishape);
|
2017-08-01 12:30:58 +00:00
|
|
|
return &m_parent->m_trishape;
|
|
|
|
}
|
|
|
|
virtual ~TriangleShapeRetriever() {}
|
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
class TetraShapeRetriever : public ChildShapeRetriever
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual btCollisionShape* getChildShape(int index)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_parent->m_gim_shape->getBulletTetrahedron(index, m_parent->m_tetrashape);
|
2017-08-01 12:30:58 +00:00
|
|
|
return &m_parent->m_tetrashape;
|
|
|
|
}
|
|
|
|
};
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
public:
|
|
|
|
ChildShapeRetriever m_child_retriever;
|
|
|
|
TriangleShapeRetriever m_tri_retriever;
|
2019-01-03 13:26:51 +00:00
|
|
|
TetraShapeRetriever m_tetra_retriever;
|
|
|
|
ChildShapeRetriever* m_current_retriever;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
GIM_ShapeRetriever(const btGImpactShapeInterface* gim_shape)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_gim_shape = gim_shape;
|
|
|
|
//select retriever
|
2019-01-03 13:26:51 +00:00
|
|
|
if (m_gim_shape->needsRetrieveTriangles())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_current_retriever = &m_tri_retriever;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
else if (m_gim_shape->needsRetrieveTetrahedrons())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_current_retriever = &m_tetra_retriever;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_current_retriever = &m_child_retriever;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_current_retriever->m_parent = this;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionShape* getChildShape(int index)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_current_retriever->getChildShape(index);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//!@}
|
|
|
|
|
|
|
|
#ifdef TRI_COLLISION_PROFILING
|
|
|
|
|
|
|
|
//! Gets the average time in miliseconds of tree collisions
|
|
|
|
float btGImpactCollisionAlgorithm::getAverageTreeCollisionTime()
|
|
|
|
{
|
|
|
|
return btGImpactBoxSet::getAverageTreeCollisionTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets the average time in miliseconds of triangle collisions
|
|
|
|
float btGImpactCollisionAlgorithm::getAverageTriangleCollisionTime()
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if (g_count_triangle_collision == 0) return 0;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
float avgtime = g_accum_triangle_collision_time;
|
|
|
|
avgtime /= (float)g_count_triangle_collision;
|
|
|
|
|
|
|
|
g_accum_triangle_collision_time = 0;
|
|
|
|
g_count_triangle_collision = 0;
|
|
|
|
|
|
|
|
return avgtime;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //TRI_COLLISION_PROFILING
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btGImpactCollisionAlgorithm::btGImpactCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
|
|
|
|
: btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_manifoldPtr = NULL;
|
|
|
|
m_convex_algorithm = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
btGImpactCollisionAlgorithm::~btGImpactCollisionAlgorithm()
|
|
|
|
{
|
|
|
|
clearCache();
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void btGImpactCollisionAlgorithm::addContactPoint(const btCollisionObjectWrapper* body0Wrap,
|
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btVector3& point,
|
|
|
|
const btVector3& normal,
|
|
|
|
btScalar distance)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_resultOut->setShapeIdentifiersA(m_part0, m_triface0);
|
|
|
|
m_resultOut->setShapeIdentifiersB(m_part1, m_triface1);
|
|
|
|
checkManifold(body0Wrap, body1Wrap);
|
|
|
|
m_resultOut->addContactPoint(normal, point, distance);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::shape_vs_shape_collision(
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionObjectWrapper* body0Wrap,
|
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btCollisionShape* shape0,
|
|
|
|
const btCollisionShape* shape1)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btCollisionAlgorithm* algor = newAlgorithm(body0Wrap, body1Wrap);
|
2017-08-01 12:30:58 +00:00
|
|
|
// post : checkManifold is called
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
m_resultOut->setShapeIdentifiersA(m_part0, m_triface0);
|
|
|
|
m_resultOut->setShapeIdentifiersB(m_part1, m_triface1);
|
|
|
|
|
|
|
|
algor->processCollision(body0Wrap, body1Wrap, *m_dispatchInfo, m_resultOut);
|
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
algor->~btCollisionAlgorithm();
|
|
|
|
m_dispatcher->freeCollisionAlgorithm(algor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::convex_vs_convex_collision(
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionObjectWrapper* body0Wrap,
|
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btCollisionShape* shape0,
|
|
|
|
const btCollisionShape* shape1)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_resultOut->setShapeIdentifiersA(m_part0, m_triface0);
|
|
|
|
m_resultOut->setShapeIdentifiersB(m_part1, m_triface1);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btCollisionObjectWrapper ob0(body0Wrap, shape0, body0Wrap->getCollisionObject(), body0Wrap->getWorldTransform(), m_part0, m_triface0);
|
|
|
|
btCollisionObjectWrapper ob1(body1Wrap, shape1, body1Wrap->getCollisionObject(), body1Wrap->getWorldTransform(), m_part1, m_triface1);
|
|
|
|
checkConvexAlgorithm(&ob0, &ob1);
|
|
|
|
m_convex_algorithm->processCollision(&ob0, &ob1, *m_dispatchInfo, m_resultOut);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::gimpact_vs_gimpact_find_pairs(
|
2019-01-03 13:26:51 +00:00
|
|
|
const btTransform& trans0,
|
|
|
|
const btTransform& trans1,
|
|
|
|
const btGImpactShapeInterface* shape0,
|
|
|
|
const btGImpactShapeInterface* shape1, btPairSet& pairset)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if (shape0->hasBoxSet() && shape1->hasBoxSet())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btGImpactBoxSet::find_collision(shape0->getBoxSet(), trans0, shape1->getBoxSet(), trans1, pairset);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
btAABB boxshape0;
|
|
|
|
btAABB boxshape1;
|
|
|
|
int i = shape0->getNumChildShapes();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
while (i--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
shape0->getChildAabb(i, trans0, boxshape0.m_min, boxshape0.m_max);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
int j = shape1->getNumChildShapes();
|
2019-01-03 13:26:51 +00:00
|
|
|
while (j--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
shape1->getChildAabb(i, trans1, boxshape1.m_min, boxshape1.m_max);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (boxshape1.has_collision(boxshape0))
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
pairset.push_pair(i, j);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::gimpact_vs_shape_find_pairs(
|
2019-01-03 13:26:51 +00:00
|
|
|
const btTransform& trans0,
|
|
|
|
const btTransform& trans1,
|
|
|
|
const btGImpactShapeInterface* shape0,
|
|
|
|
const btCollisionShape* shape1,
|
|
|
|
btAlignedObjectArray<int>& collided_primitives)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btAABB boxshape;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (shape0->hasBoxSet())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btTransform trans1to0 = trans0.inverse();
|
|
|
|
trans1to0 *= trans1;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
shape1->getAabb(trans1to0, boxshape.m_min, boxshape.m_max);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
shape0->getBoxSet()->boxQuery(boxshape, collided_primitives);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
shape1->getAabb(trans1, boxshape.m_min, boxshape.m_max);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
btAABB boxshape0;
|
|
|
|
int i = shape0->getNumChildShapes();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
while (i--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
shape0->getChildAabb(i, trans0, boxshape0.m_min, boxshape0.m_max);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (boxshape.has_collision(boxshape0))
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
collided_primitives.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void btGImpactCollisionAlgorithm::collide_gjk_triangles(const btCollisionObjectWrapper* body0Wrap,
|
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btGImpactMeshShapePart* shape0,
|
|
|
|
const btGImpactMeshShapePart* shape1,
|
|
|
|
const int* pairs, int pair_count)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btTriangleShapeEx tri0;
|
|
|
|
btTriangleShapeEx tri1;
|
|
|
|
|
|
|
|
shape0->lockChildShapes();
|
|
|
|
shape1->lockChildShapes();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
const int* pair_pointer = pairs;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
while (pair_count--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_triface0 = *(pair_pointer);
|
2019-01-03 13:26:51 +00:00
|
|
|
m_triface1 = *(pair_pointer + 1);
|
|
|
|
pair_pointer += 2;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
shape0->getBulletTriangle(m_triface0, tri0);
|
|
|
|
shape1->getBulletTriangle(m_triface1, tri1);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
//collide two convex shapes
|
2019-01-03 13:26:51 +00:00
|
|
|
if (tri0.overlap_test_conservative(tri1))
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
convex_vs_convex_collision(body0Wrap, body1Wrap, &tri0, &tri1);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shape0->unlockChildShapes();
|
|
|
|
shape1->unlockChildShapes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::collide_sat_triangles(const btCollisionObjectWrapper* body0Wrap,
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btGImpactMeshShapePart* shape0,
|
|
|
|
const btGImpactMeshShapePart* shape1,
|
|
|
|
const int* pairs, int pair_count)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btTransform orgtrans0 = body0Wrap->getWorldTransform();
|
|
|
|
btTransform orgtrans1 = body1Wrap->getWorldTransform();
|
|
|
|
|
|
|
|
btPrimitiveTriangle ptri0;
|
|
|
|
btPrimitiveTriangle ptri1;
|
|
|
|
GIM_TRIANGLE_CONTACT contact_data;
|
|
|
|
|
|
|
|
shape0->lockChildShapes();
|
|
|
|
shape1->lockChildShapes();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
const int* pair_pointer = pairs;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
while (pair_count--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_triface0 = *(pair_pointer);
|
2019-01-03 13:26:51 +00:00
|
|
|
m_triface1 = *(pair_pointer + 1);
|
|
|
|
pair_pointer += 2;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
shape0->getPrimitiveTriangle(m_triface0, ptri0);
|
|
|
|
shape1->getPrimitiveTriangle(m_triface1, ptri1);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#ifdef TRI_COLLISION_PROFILING
|
2017-08-01 12:30:58 +00:00
|
|
|
bt_begin_gim02_tri_time();
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
ptri0.applyTransform(orgtrans0);
|
|
|
|
ptri1.applyTransform(orgtrans1);
|
|
|
|
|
|
|
|
//build planes
|
|
|
|
ptri0.buildTriPlane();
|
|
|
|
ptri1.buildTriPlane();
|
|
|
|
// test conservative
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (ptri0.overlap_test_conservative(ptri1))
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if (ptri0.find_triangle_collision_clip_method(ptri1, contact_data))
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
int j = contact_data.m_point_count;
|
2019-01-03 13:26:51 +00:00
|
|
|
while (j--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
addContactPoint(body0Wrap, body1Wrap,
|
2019-01-03 13:26:51 +00:00
|
|
|
contact_data.m_points[j],
|
|
|
|
contact_data.m_separating_normal,
|
|
|
|
-contact_data.m_penetration_depth);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#ifdef TRI_COLLISION_PROFILING
|
2017-08-01 12:30:58 +00:00
|
|
|
bt_end_gim02_tri_time();
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shape0->unlockChildShapes();
|
|
|
|
shape1->unlockChildShapes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::gimpact_vs_gimpact(
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionObjectWrapper* body0Wrap,
|
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btGImpactShapeInterface* shape0,
|
|
|
|
const btGImpactShapeInterface* shape1)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if (shape0->getGImpactShapeType() == CONST_GIMPACT_TRIMESH_SHAPE)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btGImpactMeshShape* meshshape0 = static_cast<const btGImpactMeshShape*>(shape0);
|
2017-08-01 12:30:58 +00:00
|
|
|
m_part0 = meshshape0->getMeshPartCount();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
while (m_part0--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpact_vs_gimpact(body0Wrap, body1Wrap, meshshape0->getMeshPart(m_part0), shape1);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (shape1->getGImpactShapeType() == CONST_GIMPACT_TRIMESH_SHAPE)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btGImpactMeshShape* meshshape1 = static_cast<const btGImpactMeshShape*>(shape1);
|
2017-08-01 12:30:58 +00:00
|
|
|
m_part1 = meshshape1->getMeshPartCount();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
while (m_part1--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpact_vs_gimpact(body0Wrap, body1Wrap, shape0, meshshape1->getMeshPart(m_part1));
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
btTransform orgtrans0 = body0Wrap->getWorldTransform();
|
|
|
|
btTransform orgtrans1 = body1Wrap->getWorldTransform();
|
|
|
|
|
|
|
|
btPairSet pairset;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpact_vs_gimpact_find_pairs(orgtrans0, orgtrans1, shape0, shape1, pairset);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (pairset.size() == 0) return;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (shape0->getGImpactShapeType() == CONST_GIMPACT_TRIMESH_SHAPE_PART &&
|
2017-08-01 12:30:58 +00:00
|
|
|
shape1->getGImpactShapeType() == CONST_GIMPACT_TRIMESH_SHAPE_PART)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btGImpactMeshShapePart* shapepart0 = static_cast<const btGImpactMeshShapePart*>(shape0);
|
|
|
|
const btGImpactMeshShapePart* shapepart1 = static_cast<const btGImpactMeshShapePart*>(shape1);
|
|
|
|
//specialized function
|
|
|
|
#ifdef BULLET_TRIANGLE_COLLISION
|
|
|
|
collide_gjk_triangles(body0Wrap, body1Wrap, shapepart0, shapepart1, &pairset[0].m_index1, pairset.size());
|
|
|
|
#else
|
|
|
|
collide_sat_triangles(body0Wrap, body1Wrap, shapepart0, shapepart1, &pairset[0].m_index1, pairset.size());
|
|
|
|
#endif
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//general function
|
|
|
|
|
|
|
|
shape0->lockChildShapes();
|
|
|
|
shape1->lockChildShapes();
|
|
|
|
|
|
|
|
GIM_ShapeRetriever retriever0(shape0);
|
|
|
|
GIM_ShapeRetriever retriever1(shape1);
|
|
|
|
|
|
|
|
bool child_has_transform0 = shape0->childrenHasTransform();
|
|
|
|
bool child_has_transform1 = shape1->childrenHasTransform();
|
|
|
|
|
|
|
|
int i = pairset.size();
|
2019-01-03 13:26:51 +00:00
|
|
|
while (i--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
GIM_PAIR* pair = &pairset[i];
|
2017-08-01 12:30:58 +00:00
|
|
|
m_triface0 = pair->m_index1;
|
|
|
|
m_triface1 = pair->m_index2;
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionShape* colshape0 = retriever0.getChildShape(m_triface0);
|
|
|
|
const btCollisionShape* colshape1 = retriever1.getChildShape(m_triface1);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
btTransform tr0 = body0Wrap->getWorldTransform();
|
|
|
|
btTransform tr1 = body1Wrap->getWorldTransform();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (child_has_transform0)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
tr0 = orgtrans0 * shape0->getChildTransform(m_triface0);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (child_has_transform1)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
tr1 = orgtrans1 * shape1->getChildTransform(m_triface1);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btCollisionObjectWrapper ob0(body0Wrap, colshape0, body0Wrap->getCollisionObject(), tr0, m_part0, m_triface0);
|
|
|
|
btCollisionObjectWrapper ob1(body1Wrap, colshape1, body1Wrap->getCollisionObject(), tr1, m_part1, m_triface1);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
//collide two convex shapes
|
2019-01-03 13:26:51 +00:00
|
|
|
convex_vs_convex_collision(&ob0, &ob1, colshape0, colshape1);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shape0->unlockChildShapes();
|
|
|
|
shape1->unlockChildShapes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::gimpact_vs_shape(const btCollisionObjectWrapper* body0Wrap,
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btGImpactShapeInterface* shape0,
|
|
|
|
const btCollisionShape* shape1, bool swapped)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if (shape0->getGImpactShapeType() == CONST_GIMPACT_TRIMESH_SHAPE)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btGImpactMeshShape* meshshape0 = static_cast<const btGImpactMeshShape*>(shape0);
|
2017-08-01 12:30:58 +00:00
|
|
|
int& part = swapped ? m_part1 : m_part0;
|
|
|
|
part = meshshape0->getMeshPartCount();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
while (part--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
gimpact_vs_shape(body0Wrap,
|
2019-01-03 13:26:51 +00:00
|
|
|
body1Wrap,
|
|
|
|
meshshape0->getMeshPart(part),
|
|
|
|
shape1, swapped);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#ifdef GIMPACT_VS_PLANE_COLLISION
|
|
|
|
if (shape0->getGImpactShapeType() == CONST_GIMPACT_TRIMESH_SHAPE_PART &&
|
2017-08-01 12:30:58 +00:00
|
|
|
shape1->getShapeType() == STATIC_PLANE_PROXYTYPE)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btGImpactMeshShapePart* shapepart = static_cast<const btGImpactMeshShapePart*>(shape0);
|
|
|
|
const btStaticPlaneShape* planeshape = static_cast<const btStaticPlaneShape*>(shape1);
|
|
|
|
gimpacttrimeshpart_vs_plane_collision(body0Wrap, body1Wrap, shapepart, planeshape, swapped);
|
2017-08-01 12:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (shape1->isCompound())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCompoundShape* compoundshape = static_cast<const btCompoundShape*>(shape1);
|
|
|
|
gimpact_vs_compoundshape(body0Wrap, body1Wrap, shape0, compoundshape, swapped);
|
2017-08-01 12:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
else if (shape1->isConcave())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btConcaveShape* concaveshape = static_cast<const btConcaveShape*>(shape1);
|
|
|
|
gimpact_vs_concave(body0Wrap, body1Wrap, shape0, concaveshape, swapped);
|
2017-08-01 12:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
btTransform orgtrans0 = body0Wrap->getWorldTransform();
|
|
|
|
|
|
|
|
btTransform orgtrans1 = body1Wrap->getWorldTransform();
|
|
|
|
|
|
|
|
btAlignedObjectArray<int> collided_results;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpact_vs_shape_find_pairs(orgtrans0, orgtrans1, shape0, shape1, collided_results);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (collided_results.size() == 0) return;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
shape0->lockChildShapes();
|
|
|
|
|
|
|
|
GIM_ShapeRetriever retriever0(shape0);
|
|
|
|
|
|
|
|
bool child_has_transform0 = shape0->childrenHasTransform();
|
|
|
|
|
|
|
|
int i = collided_results.size();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
while (i--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
int child_index = collided_results[i];
|
2019-01-03 13:26:51 +00:00
|
|
|
if (swapped)
|
|
|
|
m_triface1 = child_index;
|
|
|
|
else
|
|
|
|
m_triface0 = child_index;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionShape* colshape0 = retriever0.getChildShape(child_index);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
btTransform tr0 = body0Wrap->getWorldTransform();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (child_has_transform0)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
tr0 = orgtrans0 * shape0->getChildTransform(child_index);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btCollisionObjectWrapper ob0(body0Wrap, colshape0, body0Wrap->getCollisionObject(), body0Wrap->getWorldTransform(), m_part0, m_triface0);
|
2019-06-11 11:18:05 +00:00
|
|
|
const btCollisionObjectWrapper* prevObj;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
if (m_resultOut->getBody0Wrap()->getCollisionObject() == ob0.getCollisionObject())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-06-11 11:18:05 +00:00
|
|
|
prevObj = m_resultOut->getBody0Wrap();
|
2017-08-01 12:30:58 +00:00
|
|
|
m_resultOut->setBody0Wrap(&ob0);
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-06-11 11:18:05 +00:00
|
|
|
prevObj = m_resultOut->getBody1Wrap();
|
2017-08-01 12:30:58 +00:00
|
|
|
m_resultOut->setBody1Wrap(&ob0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//collide two shapes
|
2019-01-03 13:26:51 +00:00
|
|
|
if (swapped)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
shape_vs_shape_collision(body1Wrap, &ob0, shape1, colshape0);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
shape_vs_shape_collision(&ob0, body1Wrap, colshape0, shape1);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-06-11 11:18:05 +00:00
|
|
|
|
|
|
|
if (m_resultOut->getBody0Wrap()->getCollisionObject() == ob0.getCollisionObject())
|
|
|
|
{
|
|
|
|
m_resultOut->setBody0Wrap(prevObj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_resultOut->setBody1Wrap(prevObj);
|
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shape0->unlockChildShapes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::gimpact_vs_compoundshape(const btCollisionObjectWrapper* body0Wrap,
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btGImpactShapeInterface* shape0,
|
|
|
|
const btCompoundShape* shape1, bool swapped)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btTransform orgtrans1 = body1Wrap->getWorldTransform();
|
|
|
|
|
|
|
|
int i = shape1->getNumChildShapes();
|
2019-01-03 13:26:51 +00:00
|
|
|
while (i--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionShape* colshape1 = shape1->getChildShape(i);
|
|
|
|
btTransform childtrans1 = orgtrans1 * shape1->getChildTransform(i);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btCollisionObjectWrapper ob1(body1Wrap, colshape1, body1Wrap->getCollisionObject(), childtrans1, -1, i);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
const btCollisionObjectWrapper* tmp = 0;
|
2019-01-03 13:26:51 +00:00
|
|
|
if (m_resultOut->getBody0Wrap()->getCollisionObject() == ob1.getCollisionObject())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
tmp = m_resultOut->getBody0Wrap();
|
|
|
|
m_resultOut->setBody0Wrap(&ob1);
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
tmp = m_resultOut->getBody1Wrap();
|
|
|
|
m_resultOut->setBody1Wrap(&ob1);
|
|
|
|
}
|
|
|
|
//collide child shape
|
|
|
|
gimpact_vs_shape(body0Wrap, &ob1,
|
2019-01-03 13:26:51 +00:00
|
|
|
shape0, colshape1, swapped);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (m_resultOut->getBody0Wrap()->getCollisionObject() == ob1.getCollisionObject())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_resultOut->setBody0Wrap(tmp);
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_resultOut->setBody1Wrap(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::gimpacttrimeshpart_vs_plane_collision(
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionObjectWrapper* body0Wrap,
|
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btGImpactMeshShapePart* shape0,
|
|
|
|
const btStaticPlaneShape* shape1, bool swapped)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btTransform orgtrans0 = body0Wrap->getWorldTransform();
|
|
|
|
btTransform orgtrans1 = body1Wrap->getWorldTransform();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
const btPlaneShape* planeshape = static_cast<const btPlaneShape*>(shape1);
|
2017-08-01 12:30:58 +00:00
|
|
|
btVector4 plane;
|
2019-01-03 13:26:51 +00:00
|
|
|
planeshape->get_plane_equation_transformed(orgtrans1, plane);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
//test box against plane
|
|
|
|
|
|
|
|
btAABB tribox;
|
2019-01-03 13:26:51 +00:00
|
|
|
shape0->getAabb(orgtrans0, tribox.m_min, tribox.m_max);
|
2017-08-01 12:30:58 +00:00
|
|
|
tribox.increment_margin(planeshape->getMargin());
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (tribox.plane_classify(plane) != BT_CONST_COLLIDE_PLANE) return;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
shape0->lockChildShapes();
|
|
|
|
|
|
|
|
btScalar margin = shape0->getMargin() + planeshape->getMargin();
|
|
|
|
|
|
|
|
btVector3 vertex;
|
|
|
|
int vi = shape0->getVertexCount();
|
2019-01-03 13:26:51 +00:00
|
|
|
while (vi--)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
shape0->getVertex(vi, vertex);
|
2017-08-01 12:30:58 +00:00
|
|
|
vertex = orgtrans0(vertex);
|
|
|
|
|
|
|
|
btScalar distance = vertex.dot(plane) - plane[3] - margin;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (distance < 0.0) //add contact
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if (swapped)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
addContactPoint(body1Wrap, body0Wrap,
|
2019-01-03 13:26:51 +00:00
|
|
|
vertex,
|
|
|
|
-plane,
|
|
|
|
distance);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addContactPoint(body0Wrap, body1Wrap,
|
2019-01-03 13:26:51 +00:00
|
|
|
vertex,
|
|
|
|
plane,
|
|
|
|
distance);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shape0->unlockChildShapes();
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
class btGImpactTriangleCallback : public btTriangleCallback
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-03 13:26:51 +00:00
|
|
|
btGImpactCollisionAlgorithm* algorithm;
|
|
|
|
const btCollisionObjectWrapper* body0Wrap;
|
|
|
|
const btCollisionObjectWrapper* body1Wrap;
|
|
|
|
const btGImpactShapeInterface* gimpactshape0;
|
2017-08-01 12:30:58 +00:00
|
|
|
bool swapped;
|
|
|
|
btScalar margin;
|
|
|
|
|
|
|
|
virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btTriangleShapeEx tri1(triangle[0], triangle[1], triangle[2]);
|
2017-08-01 12:30:58 +00:00
|
|
|
tri1.setMargin(margin);
|
2019-01-03 13:26:51 +00:00
|
|
|
if (swapped)
|
|
|
|
{
|
|
|
|
algorithm->setPart0(partId);
|
|
|
|
algorithm->setFace0(triangleIndex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
algorithm->setPart1(partId);
|
|
|
|
algorithm->setFace1(triangleIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
btCollisionObjectWrapper ob1Wrap(body1Wrap, &tri1, body1Wrap->getCollisionObject(), body1Wrap->getWorldTransform(), partId, triangleIndex);
|
|
|
|
const btCollisionObjectWrapper* tmp = 0;
|
|
|
|
|
|
|
|
if (algorithm->internalGetResultOut()->getBody0Wrap()->getCollisionObject() == ob1Wrap.getCollisionObject())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
tmp = algorithm->internalGetResultOut()->getBody0Wrap();
|
|
|
|
algorithm->internalGetResultOut()->setBody0Wrap(&ob1Wrap);
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
tmp = algorithm->internalGetResultOut()->getBody1Wrap();
|
|
|
|
algorithm->internalGetResultOut()->setBody1Wrap(&ob1Wrap);
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
algorithm->gimpact_vs_shape(
|
2019-01-03 13:26:51 +00:00
|
|
|
body0Wrap, &ob1Wrap, gimpactshape0, &tri1, swapped);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (algorithm->internalGetResultOut()->getBody0Wrap()->getCollisionObject() == ob1Wrap.getCollisionObject())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
algorithm->internalGetResultOut()->setBody0Wrap(tmp);
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
algorithm->internalGetResultOut()->setBody1Wrap(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void btGImpactCollisionAlgorithm::gimpact_vs_concave(
|
2019-01-03 13:26:51 +00:00
|
|
|
const btCollisionObjectWrapper* body0Wrap,
|
|
|
|
const btCollisionObjectWrapper* body1Wrap,
|
|
|
|
const btGImpactShapeInterface* shape0,
|
|
|
|
const btConcaveShape* shape1, bool swapped)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
//create the callback
|
|
|
|
btGImpactTriangleCallback tricallback;
|
|
|
|
tricallback.algorithm = this;
|
|
|
|
tricallback.body0Wrap = body0Wrap;
|
|
|
|
tricallback.body1Wrap = body1Wrap;
|
|
|
|
tricallback.gimpactshape0 = shape0;
|
|
|
|
tricallback.swapped = swapped;
|
|
|
|
tricallback.margin = shape1->getMargin();
|
|
|
|
|
|
|
|
//getting the trimesh AABB
|
|
|
|
btTransform gimpactInConcaveSpace;
|
|
|
|
|
|
|
|
gimpactInConcaveSpace = body1Wrap->getWorldTransform().inverse() * body0Wrap->getWorldTransform();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btVector3 minAABB, maxAABB;
|
|
|
|
shape0->getAabb(gimpactInConcaveSpace, minAABB, maxAABB);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
shape1->processAllTriangles(&tricallback, minAABB, maxAABB);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void btGImpactCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
clearCache();
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
m_resultOut = resultOut;
|
2017-08-01 12:30:58 +00:00
|
|
|
m_dispatchInfo = &dispatchInfo;
|
2019-01-03 13:26:51 +00:00
|
|
|
const btGImpactShapeInterface* gimpactshape0;
|
|
|
|
const btGImpactShapeInterface* gimpactshape1;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (body0Wrap->getCollisionShape()->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpactshape0 = static_cast<const btGImpactShapeInterface*>(body0Wrap->getCollisionShape());
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
if (body1Wrap->getCollisionShape()->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpactshape1 = static_cast<const btGImpactShapeInterface*>(body1Wrap->getCollisionShape());
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpact_vs_gimpact(body0Wrap, body1Wrap, gimpactshape0, gimpactshape1);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpact_vs_shape(body0Wrap, body1Wrap, gimpactshape0, body1Wrap->getCollisionShape(), false);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
else if (body1Wrap->getCollisionShape()->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpactshape1 = static_cast<const btGImpactShapeInterface*>(body1Wrap->getCollisionShape());
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
gimpact_vs_shape(body1Wrap, body0Wrap, gimpactshape1, body0Wrap->getCollisionShape(), true);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
// Ensure that gContactProcessedCallback is called for concave shapes.
|
|
|
|
if (getLastManifold())
|
|
|
|
{
|
|
|
|
m_resultOut->refreshContactPoints();
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btScalar btGImpactCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return 1.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////// REGISTERING ALGORITHM //////////////////////////////////////////////
|
|
|
|
|
|
|
|
//! Use this function for register the algorithm externally
|
2019-01-03 13:26:51 +00:00
|
|
|
void btGImpactCollisionAlgorithm::registerAlgorithm(btCollisionDispatcher* dispatcher)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
static btGImpactCollisionAlgorithm::CreateFunc s_gimpact_cf;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
for (i = 0; i < MAX_BROADPHASE_COLLISION_TYPES; i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
dispatcher->registerCollisionCreateFunc(GIMPACT_SHAPE_PROXYTYPE, i, &s_gimpact_cf);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
for (i = 0; i < MAX_BROADPHASE_COLLISION_TYPES; i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
dispatcher->registerCollisionCreateFunc(i, GIMPACT_SHAPE_PROXYTYPE, &s_gimpact_cf);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|