fix more warnings in BulletCollision, and fix CMakeLists for Linux
This commit is contained in:
@@ -5,8 +5,7 @@ INCLUDE_DIRECTORIES(
|
|||||||
${BULLET_PHYSICS_SOURCE_DIR}/btgui
|
${BULLET_PHYSICS_SOURCE_DIR}/btgui
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/btgui/lua-5.2.3/src
|
${BULLET_PHYSICS_SOURCE_DIR}/btgui/lua-5.2.3/src
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
SET(App_AllBullet2Demos_SRCS
|
SET(App_AllBullet2Demos_SRCS
|
||||||
main.cpp
|
main.cpp
|
||||||
BulletDemoInterface.h
|
BulletDemoInterface.h
|
||||||
@@ -93,7 +92,13 @@ ELSE(WIN32)
|
|||||||
MESSAGE(${COCOA})
|
MESSAGE(${COCOA})
|
||||||
link_libraries(${COCOA})
|
link_libraries(${COCOA})
|
||||||
ELSE(APPLE)
|
ELSE(APPLE)
|
||||||
LINK_LIBRARIES( pthread GLEW)
|
ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1")
|
||||||
|
ADD_DEFINITIONS("-DGLEW_STATIC")
|
||||||
|
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
|
||||||
|
INCLUDE_DIRECTORIES(
|
||||||
|
${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows
|
||||||
|
)
|
||||||
|
LINK_LIBRARIES( pthread dl)
|
||||||
ENDIF(APPLE)
|
ENDIF(APPLE)
|
||||||
ENDIF(WIN32)
|
ENDIF(WIN32)
|
||||||
|
|
||||||
|
|||||||
@@ -106,5 +106,5 @@ if os.is("Linux") then
|
|||||||
initX11()
|
initX11()
|
||||||
end
|
end
|
||||||
if os.is("MacOSX") then
|
if os.is("MacOSX") then
|
||||||
links{"Cocoa.framework"}
|
links{"Cocoa.framework"}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -50,7 +50,16 @@ ELSE(WIN32)
|
|||||||
MESSAGE(${COCOA})
|
MESSAGE(${COCOA})
|
||||||
link_libraries(${COCOA})
|
link_libraries(${COCOA})
|
||||||
ELSE(APPLE)
|
ELSE(APPLE)
|
||||||
LINK_LIBRARIES( GLEW X11 pthread dl)
|
SET(App_Bullet3_OpenCL_Demos_SRCS ${App_Bullet3_OpenCL_Demos_SRCS} ${App_Bullet3_OpenCL_Demos_Common_SRCS} ../../btgui/OpenGLWindow/GlewWindows/glew.c)
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(
|
||||||
|
${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows
|
||||||
|
)
|
||||||
|
ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1")
|
||||||
|
ADD_DEFINITIONS("-DGLEW_STATIC")
|
||||||
|
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
|
||||||
|
|
||||||
|
LINK_LIBRARIES( X11 pthread dl)
|
||||||
ENDIF(APPLE)
|
ENDIF(APPLE)
|
||||||
ENDIF(WIN32)
|
ENDIF(WIN32)
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,15 @@ ELSE(WIN32)
|
|||||||
MESSAGE(${COCOA})
|
MESSAGE(${COCOA})
|
||||||
link_libraries(${COCOA})
|
link_libraries(${COCOA})
|
||||||
ELSE(APPLE)
|
ELSE(APPLE)
|
||||||
LINK_LIBRARIES( GLEW X11 pthread dl Xext)
|
|
||||||
|
INCLUDE_DIRECTORIES(
|
||||||
|
${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows
|
||||||
|
)
|
||||||
|
ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1")
|
||||||
|
ADD_DEFINITIONS("-DGLEW_STATIC")
|
||||||
|
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
|
||||||
|
|
||||||
|
LINK_LIBRARIES( X11 pthread dl Xext)
|
||||||
ENDIF(APPLE)
|
ENDIF(APPLE)
|
||||||
ENDIF(WIN32)
|
ENDIF(WIN32)
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,14 @@ ENDIF(APPLE)
|
|||||||
|
|
||||||
#no Linux detection?
|
#no Linux detection?
|
||||||
IF(NOT WIN32 AND NOT APPLE)
|
IF(NOT WIN32 AND NOT APPLE)
|
||||||
SET(OpenGLWindow_SRCS ${OpenGLWindowLinux_CPP} ${OpenGLWindowCommon_CPP} )
|
INCLUDE_DIRECTORIES(
|
||||||
|
${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows
|
||||||
|
)
|
||||||
|
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||||
|
ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1")
|
||||||
|
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
|
||||||
|
|
||||||
|
SET(OpenGLWindow_SRCS ${OpenGLWindowLinux_CPP} ${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows/glew.c ${OpenGLWindowCommon_CPP} )
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ static DBVT_INLINE btDbvtVolume merge( const btDbvtVolume& a,
|
|||||||
const btDbvtVolume& b)
|
const btDbvtVolume& b)
|
||||||
{
|
{
|
||||||
#if (DBVT_MERGE_IMPL==DBVT_IMPL_SSE)
|
#if (DBVT_MERGE_IMPL==DBVT_IMPL_SSE)
|
||||||
ATTRIBUTE_ALIGNED16(char locals[sizeof(btDbvtAabbMm)]);
|
ATTRIBUTE_ALIGNED16( char locals[sizeof(btDbvtAabbMm)]);
|
||||||
btDbvtVolume& res=*(btDbvtVolume*)locals;
|
btDbvtVolume* ptr = (btDbvtVolume*) locals;
|
||||||
|
btDbvtVolume& res=*ptr;
|
||||||
#else
|
#else
|
||||||
btDbvtVolume res;
|
btDbvtVolume res;
|
||||||
#endif
|
#endif
|
||||||
@@ -250,7 +251,8 @@ static btDbvtVolume bounds( const tNodeArray& leaves)
|
|||||||
{
|
{
|
||||||
#if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
|
#if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
|
||||||
ATTRIBUTE_ALIGNED16(char locals[sizeof(btDbvtVolume)]);
|
ATTRIBUTE_ALIGNED16(char locals[sizeof(btDbvtVolume)]);
|
||||||
btDbvtVolume& volume=*(btDbvtVolume*)locals;
|
btDbvtVolume* ptr = (btDbvtVolume*) locals;
|
||||||
|
btDbvtVolume& volume=*ptr;
|
||||||
volume=leaves[0]->volume;
|
volume=leaves[0]->volume;
|
||||||
#else
|
#else
|
||||||
btDbvtVolume volume=leaves[0]->volume;
|
btDbvtVolume volume=leaves[0]->volume;
|
||||||
|
|||||||
@@ -31,11 +31,10 @@ btCollisionObject::btCollisionObject()
|
|||||||
m_activationState1(1),
|
m_activationState1(1),
|
||||||
m_deactivationTime(btScalar(0.)),
|
m_deactivationTime(btScalar(0.)),
|
||||||
m_friction(btScalar(0.5)),
|
m_friction(btScalar(0.5)),
|
||||||
m_rollingFriction(0.0f),
|
|
||||||
m_restitution(btScalar(0.)),
|
m_restitution(btScalar(0.)),
|
||||||
|
m_rollingFriction(0.0f),
|
||||||
m_internalType(CO_COLLISION_OBJECT),
|
m_internalType(CO_COLLISION_OBJECT),
|
||||||
m_userObjectPointer(0),
|
m_userObjectPointer(0),
|
||||||
m_userIndex(-1),
|
|
||||||
m_hitFraction(btScalar(1.)),
|
m_hitFraction(btScalar(1.)),
|
||||||
m_ccdSweptSphereRadius(btScalar(0.)),
|
m_ccdSweptSphereRadius(btScalar(0.)),
|
||||||
m_ccdMotionThreshold(btScalar(0.)),
|
m_ccdMotionThreshold(btScalar(0.)),
|
||||||
|
|||||||
@@ -1,43 +1,43 @@
|
|||||||
#ifndef BT_COLLISION_OBJECT_WRAPPER_H
|
#ifndef BT_COLLISION_OBJECT_WRAPPER_H
|
||||||
#define BT_COLLISION_OBJECT_WRAPPER_H
|
#define BT_COLLISION_OBJECT_WRAPPER_H
|
||||||
|
|
||||||
///btCollisionObjectWrapperis an internal data structure.
|
///btCollisionObjectWrapperis an internal data structure.
|
||||||
///Most users can ignore this and use btCollisionObject and btCollisionShape instead
|
///Most users can ignore this and use btCollisionObject and btCollisionShape instead
|
||||||
class btCollisionShape;
|
class btCollisionShape;
|
||||||
class btCollisionObject;
|
class btCollisionObject;
|
||||||
class btTransform;
|
class btTransform;
|
||||||
#include "LinearMath/btScalar.h" // for SIMD_FORCE_INLINE definition
|
#include "LinearMath/btScalar.h" // for SIMD_FORCE_INLINE definition
|
||||||
|
|
||||||
#define BT_DECLARE_STACK_ONLY_OBJECT \
|
#define BT_DECLARE_STACK_ONLY_OBJECT \
|
||||||
private: \
|
private: \
|
||||||
void* operator new(size_t size); \
|
void* operator new(size_t size); \
|
||||||
void operator delete(void*);
|
void operator delete(void*);
|
||||||
|
|
||||||
struct btCollisionObjectWrapper;
|
struct btCollisionObjectWrapper;
|
||||||
struct btCollisionObjectWrapper
|
struct btCollisionObjectWrapper
|
||||||
{
|
{
|
||||||
BT_DECLARE_STACK_ONLY_OBJECT
|
BT_DECLARE_STACK_ONLY_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
btCollisionObjectWrapper(const btCollisionObjectWrapper&); // not implemented. Not allowed.
|
btCollisionObjectWrapper(const btCollisionObjectWrapper&); // not implemented. Not allowed.
|
||||||
btCollisionObjectWrapper* operator=(const btCollisionObjectWrapper&);
|
btCollisionObjectWrapper* operator=(const btCollisionObjectWrapper&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const btCollisionObjectWrapper* m_parent;
|
const btCollisionObjectWrapper* m_parent;
|
||||||
const btCollisionShape* m_shape;
|
const btCollisionShape* m_shape;
|
||||||
const btCollisionObject* m_collisionObject;
|
const btCollisionObject* m_collisionObject;
|
||||||
const btTransform& m_worldTransform;
|
const btTransform& m_worldTransform;
|
||||||
int m_partId;
|
int m_partId;
|
||||||
int m_index;
|
int m_index;
|
||||||
|
|
||||||
btCollisionObjectWrapper(const btCollisionObjectWrapper* parent, const btCollisionShape* shape, const btCollisionObject* collisionObject, const btTransform& worldTransform, int partId, int index)
|
btCollisionObjectWrapper(const btCollisionObjectWrapper* parent, const btCollisionShape* shape, const btCollisionObject* collisionObject, const btTransform& worldTransform, int partId, int index)
|
||||||
: m_parent(parent), m_shape(shape), m_collisionObject(collisionObject), m_worldTransform(worldTransform),
|
: m_parent(parent), m_shape(shape), m_collisionObject(collisionObject), m_worldTransform(worldTransform),
|
||||||
m_partId(partId), m_index(index)
|
m_partId(partId), m_index(index)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
SIMD_FORCE_INLINE const btTransform& getWorldTransform() const { return m_worldTransform; }
|
SIMD_FORCE_INLINE const btTransform& getWorldTransform() const { return m_worldTransform; }
|
||||||
SIMD_FORCE_INLINE const btCollisionObject* getCollisionObject() const { return m_collisionObject; }
|
SIMD_FORCE_INLINE const btCollisionObject* getCollisionObject() const { return m_collisionObject; }
|
||||||
SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const { return m_shape; }
|
SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const { return m_shape; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //BT_COLLISION_OBJECT_WRAPPER_H
|
#endif //BT_COLLISION_OBJECT_WRAPPER_H
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ void btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
|
|||||||
btGjkConvexCast gjkConvexCaster(castShape,convexShape,&simplexSolver);
|
btGjkConvexCast gjkConvexCaster(castShape,convexShape,&simplexSolver);
|
||||||
|
|
||||||
//btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
|
//btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
|
||||||
bool condition = true;
|
|
||||||
btConvexCast* convexCasterPtr = 0;
|
btConvexCast* convexCasterPtr = 0;
|
||||||
//use kF_UseSubSimplexConvexCastRaytest by default
|
//use kF_UseSubSimplexConvexCastRaytest by default
|
||||||
if (resultCallback.m_flags & btTriangleRaycastCallback::kF_UseGjkConvexCastRaytest)
|
if (resultCallback.m_flags & btTriangleRaycastCallback::kF_UseGjkConvexCastRaytest)
|
||||||
@@ -1245,7 +1245,10 @@ public:
|
|||||||
void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color)
|
void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color)
|
||||||
{
|
{
|
||||||
// Draw a small simplex at the center of the object
|
// Draw a small simplex at the center of the object
|
||||||
getDebugDrawer()->drawTransform(worldTransform,1);
|
if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawFrames)
|
||||||
|
{
|
||||||
|
getDebugDrawer()->drawTransform(worldTransform,1);
|
||||||
|
}
|
||||||
|
|
||||||
if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
|
if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public:
|
|||||||
|
|
||||||
//backup
|
//backup
|
||||||
btTransform orgTrans = m_compoundColObjWrap->getWorldTransform();
|
btTransform orgTrans = m_compoundColObjWrap->getWorldTransform();
|
||||||
btTransform orgInterpolationTrans = m_compoundColObjWrap->getWorldTransform();
|
|
||||||
const btTransform& childTrans = compoundShape->getChildTransform(index);
|
const btTransform& childTrans = compoundShape->getChildTransform(index);
|
||||||
btTransform newChildWorldTrans = orgTrans*childTrans ;
|
btTransform newChildWorldTrans = orgTrans*childTrans ;
|
||||||
|
|
||||||
@@ -294,7 +294,7 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
|
|||||||
btManifoldArray manifoldArray;
|
btManifoldArray manifoldArray;
|
||||||
const btCollisionShape* childShape = 0;
|
const btCollisionShape* childShape = 0;
|
||||||
btTransform orgTrans;
|
btTransform orgTrans;
|
||||||
btTransform orgInterpolationTrans;
|
|
||||||
btTransform newChildWorldTrans;
|
btTransform newChildWorldTrans;
|
||||||
btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
|
btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
|
||||||
|
|
||||||
@@ -304,8 +304,8 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
|
|||||||
{
|
{
|
||||||
childShape = compoundShape->getChildShape(i);
|
childShape = compoundShape->getChildShape(i);
|
||||||
//if not longer overlapping, remove the algorithm
|
//if not longer overlapping, remove the algorithm
|
||||||
orgTrans = colObjWrap->getWorldTransform();
|
orgTrans = colObjWrap->getWorldTransform();
|
||||||
orgInterpolationTrans = colObjWrap->getWorldTransform();
|
|
||||||
const btTransform& childTrans = compoundShape->getChildTransform(i);
|
const btTransform& childTrans = compoundShape->getChildTransform(i);
|
||||||
newChildWorldTrans = orgTrans*childTrans ;
|
newChildWorldTrans = orgTrans*childTrans ;
|
||||||
|
|
||||||
|
|||||||
@@ -1,427 +1,426 @@
|
|||||||
/*
|
/*
|
||||||
Bullet Continuous Collision Detection and Physics Library
|
Bullet Continuous Collision Detection and Physics Library
|
||||||
Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
|
Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty.
|
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.
|
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,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it freely,
|
including commercial applications, and to alter it and redistribute it freely,
|
||||||
subject to the following restrictions:
|
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.
|
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.
|
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.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "btCompoundCompoundCollisionAlgorithm.h"
|
#include "btCompoundCompoundCollisionAlgorithm.h"
|
||||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||||
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
||||||
#include "LinearMath/btIDebugDraw.h"
|
#include "LinearMath/btIDebugDraw.h"
|
||||||
#include "LinearMath/btAabbUtil2.h"
|
#include "LinearMath/btAabbUtil2.h"
|
||||||
#include "BulletCollision/CollisionDispatch/btManifoldResult.h"
|
#include "BulletCollision/CollisionDispatch/btManifoldResult.h"
|
||||||
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
||||||
|
|
||||||
|
|
||||||
btShapePairCallback gCompoundCompoundChildShapePairCallback = 0;
|
btShapePairCallback gCompoundCompoundChildShapePairCallback = 0;
|
||||||
|
|
||||||
btCompoundCompoundCollisionAlgorithm::btCompoundCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
|
btCompoundCompoundCollisionAlgorithm::btCompoundCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
|
||||||
:btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,isSwapped)
|
:btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,isSwapped)
|
||||||
{
|
{
|
||||||
|
|
||||||
void* ptr = btAlignedAlloc(sizeof(btHashedSimplePairCache),16);
|
void* ptr = btAlignedAlloc(sizeof(btHashedSimplePairCache),16);
|
||||||
m_childCollisionAlgorithmCache= new(ptr) btHashedSimplePairCache();
|
m_childCollisionAlgorithmCache= new(ptr) btHashedSimplePairCache();
|
||||||
|
|
||||||
const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
|
const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
|
||||||
btAssert (col0ObjWrap->getCollisionShape()->isCompound());
|
btAssert (col0ObjWrap->getCollisionShape()->isCompound());
|
||||||
|
|
||||||
const btCollisionObjectWrapper* col1ObjWrap = body1Wrap;
|
const btCollisionObjectWrapper* col1ObjWrap = body1Wrap;
|
||||||
btAssert (col1ObjWrap->getCollisionShape()->isCompound());
|
btAssert (col1ObjWrap->getCollisionShape()->isCompound());
|
||||||
|
|
||||||
const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
|
const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
|
||||||
m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
|
m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
|
||||||
|
|
||||||
const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
|
const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
|
||||||
m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
|
m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
btCompoundCompoundCollisionAlgorithm::~btCompoundCompoundCollisionAlgorithm()
|
btCompoundCompoundCollisionAlgorithm::~btCompoundCompoundCollisionAlgorithm()
|
||||||
{
|
{
|
||||||
removeChildAlgorithms();
|
removeChildAlgorithms();
|
||||||
m_childCollisionAlgorithmCache->~btHashedSimplePairCache();
|
m_childCollisionAlgorithmCache->~btHashedSimplePairCache();
|
||||||
btAlignedFree(m_childCollisionAlgorithmCache);
|
btAlignedFree(m_childCollisionAlgorithmCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
void btCompoundCompoundCollisionAlgorithm::getAllContactManifolds(btManifoldArray& manifoldArray)
|
void btCompoundCompoundCollisionAlgorithm::getAllContactManifolds(btManifoldArray& manifoldArray)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
|
btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
|
||||||
for (i=0;i<pairs.size();i++)
|
for (i=0;i<pairs.size();i++)
|
||||||
{
|
{
|
||||||
if (pairs[i].m_userPointer)
|
if (pairs[i].m_userPointer)
|
||||||
{
|
{
|
||||||
|
|
||||||
((btCollisionAlgorithm*)pairs[i].m_userPointer)->getAllContactManifolds(manifoldArray);
|
((btCollisionAlgorithm*)pairs[i].m_userPointer)->getAllContactManifolds(manifoldArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void btCompoundCompoundCollisionAlgorithm::removeChildAlgorithms()
|
void btCompoundCompoundCollisionAlgorithm::removeChildAlgorithms()
|
||||||
{
|
{
|
||||||
btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
|
btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
|
||||||
|
|
||||||
int numChildren = pairs.size();
|
int numChildren = pairs.size();
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<numChildren;i++)
|
for (i=0;i<numChildren;i++)
|
||||||
{
|
{
|
||||||
if (pairs[i].m_userPointer)
|
if (pairs[i].m_userPointer)
|
||||||
{
|
{
|
||||||
btCollisionAlgorithm* algo = (btCollisionAlgorithm*) pairs[i].m_userPointer;
|
btCollisionAlgorithm* algo = (btCollisionAlgorithm*) pairs[i].m_userPointer;
|
||||||
algo->~btCollisionAlgorithm();
|
algo->~btCollisionAlgorithm();
|
||||||
m_dispatcher->freeCollisionAlgorithm(algo);
|
m_dispatcher->freeCollisionAlgorithm(algo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_childCollisionAlgorithmCache->removeAllPairs();
|
m_childCollisionAlgorithmCache->removeAllPairs();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct btCompoundCompoundLeafCallback : btDbvt::ICollide
|
struct btCompoundCompoundLeafCallback : btDbvt::ICollide
|
||||||
{
|
{
|
||||||
int m_numOverlapPairs;
|
int m_numOverlapPairs;
|
||||||
|
|
||||||
|
|
||||||
const btCollisionObjectWrapper* m_compound0ColObjWrap;
|
const btCollisionObjectWrapper* m_compound0ColObjWrap;
|
||||||
const btCollisionObjectWrapper* m_compound1ColObjWrap;
|
const btCollisionObjectWrapper* m_compound1ColObjWrap;
|
||||||
btDispatcher* m_dispatcher;
|
btDispatcher* m_dispatcher;
|
||||||
const btDispatcherInfo& m_dispatchInfo;
|
const btDispatcherInfo& m_dispatchInfo;
|
||||||
btManifoldResult* m_resultOut;
|
btManifoldResult* m_resultOut;
|
||||||
|
|
||||||
|
|
||||||
class btHashedSimplePairCache* m_childCollisionAlgorithmCache;
|
class btHashedSimplePairCache* m_childCollisionAlgorithmCache;
|
||||||
|
|
||||||
btPersistentManifold* m_sharedManifold;
|
btPersistentManifold* m_sharedManifold;
|
||||||
|
|
||||||
btCompoundCompoundLeafCallback (const btCollisionObjectWrapper* compound1ObjWrap,
|
btCompoundCompoundLeafCallback (const btCollisionObjectWrapper* compound1ObjWrap,
|
||||||
const btCollisionObjectWrapper* compound0ObjWrap,
|
const btCollisionObjectWrapper* compound0ObjWrap,
|
||||||
btDispatcher* dispatcher,
|
btDispatcher* dispatcher,
|
||||||
const btDispatcherInfo& dispatchInfo,
|
const btDispatcherInfo& dispatchInfo,
|
||||||
btManifoldResult* resultOut,
|
btManifoldResult* resultOut,
|
||||||
btHashedSimplePairCache* childAlgorithmsCache,
|
btHashedSimplePairCache* childAlgorithmsCache,
|
||||||
btPersistentManifold* sharedManifold)
|
btPersistentManifold* sharedManifold)
|
||||||
:m_compound0ColObjWrap(compound1ObjWrap),m_compound1ColObjWrap(compound0ObjWrap),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
|
:m_numOverlapPairs(0),m_compound0ColObjWrap(compound1ObjWrap),m_compound1ColObjWrap(compound0ObjWrap),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
|
||||||
m_childCollisionAlgorithmCache(childAlgorithmsCache),
|
m_childCollisionAlgorithmCache(childAlgorithmsCache),
|
||||||
m_sharedManifold(sharedManifold),
|
m_sharedManifold(sharedManifold)
|
||||||
m_numOverlapPairs(0)
|
{
|
||||||
{
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Process(const btDbvtNode* leaf0,const btDbvtNode* leaf1)
|
||||||
void Process(const btDbvtNode* leaf0,const btDbvtNode* leaf1)
|
{
|
||||||
{
|
m_numOverlapPairs++;
|
||||||
m_numOverlapPairs++;
|
|
||||||
|
|
||||||
|
int childIndex0 = leaf0->dataAsInt;
|
||||||
int childIndex0 = leaf0->dataAsInt;
|
int childIndex1 = leaf1->dataAsInt;
|
||||||
int childIndex1 = leaf1->dataAsInt;
|
|
||||||
|
|
||||||
|
btAssert(childIndex0>=0);
|
||||||
btAssert(childIndex0>=0);
|
btAssert(childIndex1>=0);
|
||||||
btAssert(childIndex1>=0);
|
|
||||||
|
|
||||||
|
const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(m_compound0ColObjWrap->getCollisionShape());
|
||||||
const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(m_compound0ColObjWrap->getCollisionShape());
|
btAssert(childIndex0<compoundShape0->getNumChildShapes());
|
||||||
btAssert(childIndex0<compoundShape0->getNumChildShapes());
|
|
||||||
|
const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(m_compound1ColObjWrap->getCollisionShape());
|
||||||
const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(m_compound1ColObjWrap->getCollisionShape());
|
btAssert(childIndex1<compoundShape1->getNumChildShapes());
|
||||||
btAssert(childIndex1<compoundShape1->getNumChildShapes());
|
|
||||||
|
const btCollisionShape* childShape0 = compoundShape0->getChildShape(childIndex0);
|
||||||
const btCollisionShape* childShape0 = compoundShape0->getChildShape(childIndex0);
|
const btCollisionShape* childShape1 = compoundShape1->getChildShape(childIndex1);
|
||||||
const btCollisionShape* childShape1 = compoundShape1->getChildShape(childIndex1);
|
|
||||||
|
//backup
|
||||||
//backup
|
btTransform orgTrans0 = m_compound0ColObjWrap->getWorldTransform();
|
||||||
btTransform orgTrans0 = m_compound0ColObjWrap->getWorldTransform();
|
const btTransform& childTrans0 = compoundShape0->getChildTransform(childIndex0);
|
||||||
const btTransform& childTrans0 = compoundShape0->getChildTransform(childIndex0);
|
btTransform newChildWorldTrans0 = orgTrans0*childTrans0 ;
|
||||||
btTransform newChildWorldTrans0 = orgTrans0*childTrans0 ;
|
|
||||||
|
btTransform orgTrans1 = m_compound1ColObjWrap->getWorldTransform();
|
||||||
btTransform orgTrans1 = m_compound1ColObjWrap->getWorldTransform();
|
const btTransform& childTrans1 = compoundShape1->getChildTransform(childIndex1);
|
||||||
const btTransform& childTrans1 = compoundShape1->getChildTransform(childIndex1);
|
btTransform newChildWorldTrans1 = orgTrans1*childTrans1 ;
|
||||||
btTransform newChildWorldTrans1 = orgTrans1*childTrans1 ;
|
|
||||||
|
|
||||||
|
//perform an AABB check first
|
||||||
//perform an AABB check first
|
btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
|
||||||
btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
|
childShape0->getAabb(newChildWorldTrans0,aabbMin0,aabbMax0);
|
||||||
childShape0->getAabb(newChildWorldTrans0,aabbMin0,aabbMax0);
|
childShape1->getAabb(newChildWorldTrans1,aabbMin1,aabbMax1);
|
||||||
childShape1->getAabb(newChildWorldTrans1,aabbMin1,aabbMax1);
|
|
||||||
|
if (gCompoundCompoundChildShapePairCallback)
|
||||||
if (gCompoundCompoundChildShapePairCallback)
|
{
|
||||||
{
|
if (!gCompoundCompoundChildShapePairCallback(childShape0,childShape1))
|
||||||
if (!gCompoundCompoundChildShapePairCallback(childShape0,childShape1))
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
|
||||||
if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
|
{
|
||||||
{
|
btCollisionObjectWrapper compoundWrap0(this->m_compound0ColObjWrap,childShape0, m_compound0ColObjWrap->getCollisionObject(),newChildWorldTrans0,-1,childIndex0);
|
||||||
btCollisionObjectWrapper compoundWrap0(this->m_compound0ColObjWrap,childShape0, m_compound0ColObjWrap->getCollisionObject(),newChildWorldTrans0,-1,childIndex0);
|
btCollisionObjectWrapper compoundWrap1(this->m_compound1ColObjWrap,childShape1,m_compound1ColObjWrap->getCollisionObject(),newChildWorldTrans1,-1,childIndex1);
|
||||||
btCollisionObjectWrapper compoundWrap1(this->m_compound1ColObjWrap,childShape1,m_compound1ColObjWrap->getCollisionObject(),newChildWorldTrans1,-1,childIndex1);
|
|
||||||
|
|
||||||
|
btSimplePair* pair = m_childCollisionAlgorithmCache->findPair(childIndex0,childIndex1);
|
||||||
btSimplePair* pair = m_childCollisionAlgorithmCache->findPair(childIndex0,childIndex1);
|
|
||||||
|
btCollisionAlgorithm* colAlgo = 0;
|
||||||
btCollisionAlgorithm* colAlgo = 0;
|
|
||||||
|
if (pair)
|
||||||
if (pair)
|
{
|
||||||
{
|
colAlgo = (btCollisionAlgorithm*)pair->m_userPointer;
|
||||||
colAlgo = (btCollisionAlgorithm*)pair->m_userPointer;
|
|
||||||
|
} else
|
||||||
} else
|
{
|
||||||
{
|
colAlgo = m_dispatcher->findAlgorithm(&compoundWrap0,&compoundWrap1,m_sharedManifold);
|
||||||
colAlgo = m_dispatcher->findAlgorithm(&compoundWrap0,&compoundWrap1,m_sharedManifold);
|
pair = m_childCollisionAlgorithmCache->addOverlappingPair(childIndex0,childIndex1);
|
||||||
pair = m_childCollisionAlgorithmCache->addOverlappingPair(childIndex0,childIndex1);
|
btAssert(pair);
|
||||||
btAssert(pair);
|
pair->m_userPointer = colAlgo;
|
||||||
pair->m_userPointer = colAlgo;
|
}
|
||||||
}
|
|
||||||
|
btAssert(colAlgo);
|
||||||
btAssert(colAlgo);
|
|
||||||
|
const btCollisionObjectWrapper* tmpWrap0 = 0;
|
||||||
const btCollisionObjectWrapper* tmpWrap0 = 0;
|
const btCollisionObjectWrapper* tmpWrap1 = 0;
|
||||||
const btCollisionObjectWrapper* tmpWrap1 = 0;
|
|
||||||
|
tmpWrap0 = m_resultOut->getBody0Wrap();
|
||||||
tmpWrap0 = m_resultOut->getBody0Wrap();
|
tmpWrap1 = m_resultOut->getBody1Wrap();
|
||||||
tmpWrap1 = m_resultOut->getBody1Wrap();
|
|
||||||
|
m_resultOut->setBody0Wrap(&compoundWrap0);
|
||||||
m_resultOut->setBody0Wrap(&compoundWrap0);
|
m_resultOut->setBody1Wrap(&compoundWrap1);
|
||||||
m_resultOut->setBody1Wrap(&compoundWrap1);
|
|
||||||
|
m_resultOut->setShapeIdentifiersA(-1,childIndex0);
|
||||||
m_resultOut->setShapeIdentifiersA(-1,childIndex0);
|
m_resultOut->setShapeIdentifiersB(-1,childIndex1);
|
||||||
m_resultOut->setShapeIdentifiersB(-1,childIndex1);
|
|
||||||
|
|
||||||
|
colAlgo->processCollision(&compoundWrap0,&compoundWrap1,m_dispatchInfo,m_resultOut);
|
||||||
colAlgo->processCollision(&compoundWrap0,&compoundWrap1,m_dispatchInfo,m_resultOut);
|
|
||||||
|
m_resultOut->setBody0Wrap(tmpWrap0);
|
||||||
m_resultOut->setBody0Wrap(tmpWrap0);
|
m_resultOut->setBody1Wrap(tmpWrap1);
|
||||||
m_resultOut->setBody1Wrap(tmpWrap1);
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
static DBVT_INLINE bool MyIntersect( const btDbvtAabbMm& a,
|
||||||
static DBVT_INLINE bool MyIntersect( const btDbvtAabbMm& a,
|
const btDbvtAabbMm& b, const btTransform& xform)
|
||||||
const btDbvtAabbMm& b, const btTransform& xform)
|
{
|
||||||
{
|
btVector3 newmin,newmax;
|
||||||
btVector3 newmin,newmax;
|
btTransformAabb(b.Mins(),b.Maxs(),0.f,xform,newmin,newmax);
|
||||||
btTransformAabb(b.Mins(),b.Maxs(),0.f,xform,newmin,newmax);
|
btDbvtAabbMm newb = btDbvtAabbMm::FromMM(newmin,newmax);
|
||||||
btDbvtAabbMm newb = btDbvtAabbMm::FromMM(newmin,newmax);
|
return Intersect(a,newb);
|
||||||
return Intersect(a,newb);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
static inline void MycollideTT( const btDbvtNode* root0,
|
||||||
static inline void MycollideTT( const btDbvtNode* root0,
|
const btDbvtNode* root1,
|
||||||
const btDbvtNode* root1,
|
const btTransform& xform,
|
||||||
const btTransform& xform,
|
btCompoundCompoundLeafCallback* callback)
|
||||||
btCompoundCompoundLeafCallback* callback)
|
{
|
||||||
{
|
|
||||||
|
if(root0&&root1)
|
||||||
if(root0&&root1)
|
{
|
||||||
{
|
int depth=1;
|
||||||
int depth=1;
|
int treshold=btDbvt::DOUBLE_STACKSIZE-4;
|
||||||
int treshold=btDbvt::DOUBLE_STACKSIZE-4;
|
btAlignedObjectArray<btDbvt::sStkNN> stkStack;
|
||||||
btAlignedObjectArray<btDbvt::sStkNN> stkStack;
|
stkStack.resize(btDbvt::DOUBLE_STACKSIZE);
|
||||||
stkStack.resize(btDbvt::DOUBLE_STACKSIZE);
|
stkStack[0]=btDbvt::sStkNN(root0,root1);
|
||||||
stkStack[0]=btDbvt::sStkNN(root0,root1);
|
do {
|
||||||
do {
|
btDbvt::sStkNN p=stkStack[--depth];
|
||||||
btDbvt::sStkNN p=stkStack[--depth];
|
if(MyIntersect(p.a->volume,p.b->volume,xform))
|
||||||
if(MyIntersect(p.a->volume,p.b->volume,xform))
|
{
|
||||||
{
|
if(depth>treshold)
|
||||||
if(depth>treshold)
|
{
|
||||||
{
|
stkStack.resize(stkStack.size()*2);
|
||||||
stkStack.resize(stkStack.size()*2);
|
treshold=stkStack.size()-4;
|
||||||
treshold=stkStack.size()-4;
|
}
|
||||||
}
|
if(p.a->isinternal())
|
||||||
if(p.a->isinternal())
|
{
|
||||||
{
|
if(p.b->isinternal())
|
||||||
if(p.b->isinternal())
|
{
|
||||||
{
|
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b->childs[0]);
|
||||||
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b->childs[0]);
|
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b->childs[0]);
|
||||||
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b->childs[0]);
|
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b->childs[1]);
|
||||||
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b->childs[1]);
|
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b->childs[1]);
|
||||||
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b->childs[1]);
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b);
|
||||||
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b);
|
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b);
|
||||||
stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b);
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
if(p.b->isinternal())
|
||||||
if(p.b->isinternal())
|
{
|
||||||
{
|
stkStack[depth++]=btDbvt::sStkNN(p.a,p.b->childs[0]);
|
||||||
stkStack[depth++]=btDbvt::sStkNN(p.a,p.b->childs[0]);
|
stkStack[depth++]=btDbvt::sStkNN(p.a,p.b->childs[1]);
|
||||||
stkStack[depth++]=btDbvt::sStkNN(p.a,p.b->childs[1]);
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
callback->Process(p.a,p.b);
|
||||||
callback->Process(p.a,p.b);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while(depth);
|
||||||
} while(depth);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||||
void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
{
|
||||||
{
|
|
||||||
|
const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
|
||||||
const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
|
const btCollisionObjectWrapper* col1ObjWrap= body1Wrap;
|
||||||
const btCollisionObjectWrapper* col1ObjWrap= body1Wrap;
|
|
||||||
|
btAssert (col0ObjWrap->getCollisionShape()->isCompound());
|
||||||
btAssert (col0ObjWrap->getCollisionShape()->isCompound());
|
btAssert (col1ObjWrap->getCollisionShape()->isCompound());
|
||||||
btAssert (col1ObjWrap->getCollisionShape()->isCompound());
|
const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
|
||||||
const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
|
const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
|
||||||
const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
|
|
||||||
|
const btDbvt* tree0 = compoundShape0->getDynamicAabbTree();
|
||||||
const btDbvt* tree0 = compoundShape0->getDynamicAabbTree();
|
const btDbvt* tree1 = compoundShape1->getDynamicAabbTree();
|
||||||
const btDbvt* tree1 = compoundShape1->getDynamicAabbTree();
|
if (!tree0 || !tree1)
|
||||||
if (!tree0 || !tree1)
|
{
|
||||||
{
|
return btCompoundCollisionAlgorithm::processCollision(body0Wrap,body1Wrap,dispatchInfo,resultOut);
|
||||||
return btCompoundCollisionAlgorithm::processCollision(body0Wrap,body1Wrap,dispatchInfo,resultOut);
|
}
|
||||||
}
|
///btCompoundShape might have changed:
|
||||||
///btCompoundShape might have changed:
|
////make sure the internal child collision algorithm caches are still valid
|
||||||
////make sure the internal child collision algorithm caches are still valid
|
if ((compoundShape0->getUpdateRevision() != m_compoundShapeRevision0) || (compoundShape1->getUpdateRevision() != m_compoundShapeRevision1))
|
||||||
if ((compoundShape0->getUpdateRevision() != m_compoundShapeRevision0) || (compoundShape1->getUpdateRevision() != m_compoundShapeRevision1))
|
{
|
||||||
{
|
///clear all
|
||||||
///clear all
|
removeChildAlgorithms();
|
||||||
removeChildAlgorithms();
|
m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
|
||||||
m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
|
m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
|
||||||
m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
///we need to refresh all contact manifolds
|
||||||
///we need to refresh all contact manifolds
|
///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
|
||||||
///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
|
///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
|
||||||
///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
|
{
|
||||||
{
|
int i;
|
||||||
int i;
|
btManifoldArray manifoldArray;
|
||||||
btManifoldArray manifoldArray;
|
btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
|
||||||
btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
|
for (i=0;i<pairs.size();i++)
|
||||||
for (i=0;i<pairs.size();i++)
|
{
|
||||||
{
|
if (pairs[i].m_userPointer)
|
||||||
if (pairs[i].m_userPointer)
|
{
|
||||||
{
|
btCollisionAlgorithm* algo = (btCollisionAlgorithm*) pairs[i].m_userPointer;
|
||||||
btCollisionAlgorithm* algo = (btCollisionAlgorithm*) pairs[i].m_userPointer;
|
algo->getAllContactManifolds(manifoldArray);
|
||||||
algo->getAllContactManifolds(manifoldArray);
|
for (int m=0;m<manifoldArray.size();m++)
|
||||||
for (int m=0;m<manifoldArray.size();m++)
|
{
|
||||||
{
|
if (manifoldArray[m]->getNumContacts())
|
||||||
if (manifoldArray[m]->getNumContacts())
|
{
|
||||||
{
|
resultOut->setPersistentManifold(manifoldArray[m]);
|
||||||
resultOut->setPersistentManifold(manifoldArray[m]);
|
resultOut->refreshContactPoints();
|
||||||
resultOut->refreshContactPoints();
|
resultOut->setPersistentManifold(0);
|
||||||
resultOut->setPersistentManifold(0);
|
}
|
||||||
}
|
}
|
||||||
}
|
manifoldArray.resize(0);
|
||||||
manifoldArray.resize(0);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
btCompoundCompoundLeafCallback callback(col0ObjWrap,col1ObjWrap,this->m_dispatcher,dispatchInfo,resultOut,this->m_childCollisionAlgorithmCache,m_sharedManifold);
|
||||||
btCompoundCompoundLeafCallback callback(col0ObjWrap,col1ObjWrap,this->m_dispatcher,dispatchInfo,resultOut,this->m_childCollisionAlgorithmCache,m_sharedManifold);
|
|
||||||
|
|
||||||
|
const btTransform xform=col0ObjWrap->getWorldTransform().inverse()*col1ObjWrap->getWorldTransform();
|
||||||
const btTransform xform=col0ObjWrap->getWorldTransform().inverse()*col1ObjWrap->getWorldTransform();
|
MycollideTT(tree0->m_root,tree1->m_root,xform,&callback);
|
||||||
MycollideTT(tree0->m_root,tree1->m_root,xform,&callback);
|
|
||||||
|
//printf("#compound-compound child/leaf overlap =%d \r",callback.m_numOverlapPairs);
|
||||||
//printf("#compound-compound child/leaf overlap =%d \r",callback.m_numOverlapPairs);
|
|
||||||
|
//remove non-overlapping child pairs
|
||||||
//remove non-overlapping child pairs
|
|
||||||
|
{
|
||||||
{
|
btAssert(m_removePairs.size()==0);
|
||||||
btAssert(m_removePairs.size()==0);
|
|
||||||
|
//iterate over all children, perform an AABB check inside ProcessChildShape
|
||||||
//iterate over all children, perform an AABB check inside ProcessChildShape
|
btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
|
||||||
btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
|
|
||||||
|
int i;
|
||||||
int i;
|
btManifoldArray manifoldArray;
|
||||||
btManifoldArray manifoldArray;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
|
||||||
btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
|
|
||||||
|
for (i=0;i<pairs.size();i++)
|
||||||
for (i=0;i<pairs.size();i++)
|
{
|
||||||
{
|
if (pairs[i].m_userPointer)
|
||||||
if (pairs[i].m_userPointer)
|
{
|
||||||
{
|
btCollisionAlgorithm* algo = (btCollisionAlgorithm*)pairs[i].m_userPointer;
|
||||||
btCollisionAlgorithm* algo = (btCollisionAlgorithm*)pairs[i].m_userPointer;
|
|
||||||
|
{
|
||||||
{
|
btTransform orgTrans0;
|
||||||
btTransform orgTrans0;
|
const btCollisionShape* childShape0 = 0;
|
||||||
const btCollisionShape* childShape0 = 0;
|
|
||||||
|
btTransform newChildWorldTrans0;
|
||||||
btTransform newChildWorldTrans0;
|
btTransform orgInterpolationTrans0;
|
||||||
btTransform orgInterpolationTrans0;
|
childShape0 = compoundShape0->getChildShape(pairs[i].m_indexA);
|
||||||
childShape0 = compoundShape0->getChildShape(pairs[i].m_indexA);
|
orgTrans0 = col0ObjWrap->getWorldTransform();
|
||||||
orgTrans0 = col0ObjWrap->getWorldTransform();
|
orgInterpolationTrans0 = col0ObjWrap->getWorldTransform();
|
||||||
orgInterpolationTrans0 = col0ObjWrap->getWorldTransform();
|
const btTransform& childTrans0 = compoundShape0->getChildTransform(pairs[i].m_indexA);
|
||||||
const btTransform& childTrans0 = compoundShape0->getChildTransform(pairs[i].m_indexA);
|
newChildWorldTrans0 = orgTrans0*childTrans0 ;
|
||||||
newChildWorldTrans0 = orgTrans0*childTrans0 ;
|
childShape0->getAabb(newChildWorldTrans0,aabbMin0,aabbMax0);
|
||||||
childShape0->getAabb(newChildWorldTrans0,aabbMin0,aabbMax0);
|
}
|
||||||
}
|
|
||||||
|
{
|
||||||
{
|
btTransform orgInterpolationTrans1;
|
||||||
btTransform orgInterpolationTrans1;
|
const btCollisionShape* childShape1 = 0;
|
||||||
const btCollisionShape* childShape1 = 0;
|
btTransform orgTrans1;
|
||||||
btTransform orgTrans1;
|
btTransform newChildWorldTrans1;
|
||||||
btTransform newChildWorldTrans1;
|
|
||||||
|
childShape1 = compoundShape1->getChildShape(pairs[i].m_indexB);
|
||||||
childShape1 = compoundShape1->getChildShape(pairs[i].m_indexB);
|
orgTrans1 = col1ObjWrap->getWorldTransform();
|
||||||
orgTrans1 = col1ObjWrap->getWorldTransform();
|
orgInterpolationTrans1 = col1ObjWrap->getWorldTransform();
|
||||||
orgInterpolationTrans1 = col1ObjWrap->getWorldTransform();
|
const btTransform& childTrans1 = compoundShape1->getChildTransform(pairs[i].m_indexB);
|
||||||
const btTransform& childTrans1 = compoundShape1->getChildTransform(pairs[i].m_indexB);
|
newChildWorldTrans1 = orgTrans1*childTrans1 ;
|
||||||
newChildWorldTrans1 = orgTrans1*childTrans1 ;
|
childShape1->getAabb(newChildWorldTrans1,aabbMin1,aabbMax1);
|
||||||
childShape1->getAabb(newChildWorldTrans1,aabbMin1,aabbMax1);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
|
||||||
if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
|
{
|
||||||
{
|
algo->~btCollisionAlgorithm();
|
||||||
algo->~btCollisionAlgorithm();
|
m_dispatcher->freeCollisionAlgorithm(algo);
|
||||||
m_dispatcher->freeCollisionAlgorithm(algo);
|
m_removePairs.push_back(btSimplePair(pairs[i].m_indexA,pairs[i].m_indexB));
|
||||||
m_removePairs.push_back(btSimplePair(pairs[i].m_indexA,pairs[i].m_indexB));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for (int i=0;i<m_removePairs.size();i++)
|
||||||
for (int i=0;i<m_removePairs.size();i++)
|
{
|
||||||
{
|
m_childCollisionAlgorithmCache->removeOverlappingPair(m_removePairs[i].m_indexA,m_removePairs[i].m_indexB);
|
||||||
m_childCollisionAlgorithmCache->removeOverlappingPair(m_removePairs[i].m_indexA,m_removePairs[i].m_indexB);
|
}
|
||||||
}
|
m_removePairs.clear();
|
||||||
m_removePairs.clear();
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
btScalar btCompoundCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||||
btScalar btCompoundCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
{
|
||||||
{
|
btAssert(0);
|
||||||
btAssert(0);
|
return 0.f;
|
||||||
return 0.f;
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,89 +1,89 @@
|
|||||||
/*
|
/*
|
||||||
Bullet Continuous Collision Detection and Physics Library
|
Bullet Continuous Collision Detection and Physics Library
|
||||||
Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
|
Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty.
|
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.
|
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,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it freely,
|
including commercial applications, and to alter it and redistribute it freely,
|
||||||
subject to the following restrictions:
|
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.
|
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.
|
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.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
|
#ifndef BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
|
||||||
#define BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
|
#define BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
|
||||||
|
|
||||||
#include "btCompoundCollisionAlgorithm.h"
|
#include "btCompoundCollisionAlgorithm.h"
|
||||||
|
|
||||||
#include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
|
#include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
|
||||||
#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
|
#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
|
||||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
|
#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
|
||||||
|
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
||||||
class btDispatcher;
|
class btDispatcher;
|
||||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
|
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
|
||||||
#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
|
#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
|
||||||
#include "LinearMath/btAlignedObjectArray.h"
|
#include "LinearMath/btAlignedObjectArray.h"
|
||||||
#include "BulletCollision/CollisionDispatch/btHashedSimplePairCache.h"
|
#include "BulletCollision/CollisionDispatch/btHashedSimplePairCache.h"
|
||||||
class btDispatcher;
|
class btDispatcher;
|
||||||
class btCollisionObject;
|
class btCollisionObject;
|
||||||
|
|
||||||
class btCollisionShape;
|
class btCollisionShape;
|
||||||
typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCollisionShape* pShape1);
|
typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCollisionShape* pShape1);
|
||||||
extern btShapePairCallback gCompoundCompoundChildShapePairCallback;
|
extern btShapePairCallback gCompoundCompoundChildShapePairCallback;
|
||||||
|
|
||||||
/// btCompoundCompoundCollisionAlgorithm supports collision between two btCompoundCollisionShape shapes
|
/// btCompoundCompoundCollisionAlgorithm supports collision between two btCompoundCollisionShape shapes
|
||||||
class btCompoundCompoundCollisionAlgorithm : public btCompoundCollisionAlgorithm
|
class btCompoundCompoundCollisionAlgorithm : public btCompoundCollisionAlgorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
class btHashedSimplePairCache* m_childCollisionAlgorithmCache;
|
class btHashedSimplePairCache* m_childCollisionAlgorithmCache;
|
||||||
btSimplePairArray m_removePairs;
|
btSimplePairArray m_removePairs;
|
||||||
|
|
||||||
|
|
||||||
int m_compoundShapeRevision0;//to keep track of changes, so that childAlgorithm array can be updated
|
int m_compoundShapeRevision0;//to keep track of changes, so that childAlgorithm array can be updated
|
||||||
int m_compoundShapeRevision1;
|
int m_compoundShapeRevision1;
|
||||||
|
|
||||||
void removeChildAlgorithms();
|
void removeChildAlgorithms();
|
||||||
|
|
||||||
// void preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
|
// void preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
btCompoundCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
|
btCompoundCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
|
||||||
|
|
||||||
virtual ~btCompoundCompoundCollisionAlgorithm();
|
virtual ~btCompoundCompoundCollisionAlgorithm();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||||
|
|
||||||
btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||||
|
|
||||||
virtual void getAllContactManifolds(btManifoldArray& manifoldArray);
|
virtual void getAllContactManifolds(btManifoldArray& manifoldArray);
|
||||||
|
|
||||||
|
|
||||||
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
||||||
{
|
{
|
||||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
||||||
{
|
{
|
||||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
|
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
|
||||||
return new(mem) btCompoundCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
|
return new(mem) btCompoundCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SwappedCreateFunc :public btCollisionAlgorithmCreateFunc
|
struct SwappedCreateFunc :public btCollisionAlgorithmCreateFunc
|
||||||
{
|
{
|
||||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
||||||
{
|
{
|
||||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
|
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
|
||||||
return new(mem) btCompoundCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
|
return new(mem) btCompoundCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
|
#endif //BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
|
||||||
|
|||||||
@@ -88,20 +88,19 @@ partId, int triangleIndex)
|
|||||||
//just for debugging purposes
|
//just for debugging purposes
|
||||||
//printf("triangle %d",m_triangleCount++);
|
//printf("triangle %d",m_triangleCount++);
|
||||||
|
|
||||||
const btCollisionObject* ob = const_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
|
|
||||||
|
|
||||||
btCollisionAlgorithmConstructionInfo ci;
|
btCollisionAlgorithmConstructionInfo ci;
|
||||||
ci.m_dispatcher1 = m_dispatcher;
|
ci.m_dispatcher1 = m_dispatcher;
|
||||||
|
|
||||||
//const btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
///debug drawing of the overlapping triangles
|
///debug drawing of the overlapping triangles
|
||||||
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
|
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
|
||||||
{
|
{
|
||||||
|
const btCollisionObject* ob = const_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
|
||||||
btVector3 color(1,1,0);
|
btVector3 color(1,1,0);
|
||||||
btTransform& tr = ob->getWorldTransform();
|
btTransform& tr = ob->getWorldTransform();
|
||||||
m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color);
|
m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color);
|
||||||
|
|||||||
@@ -105,8 +105,7 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
|
|||||||
int maxSize = sizeof(btConvexConvexAlgorithm);
|
int maxSize = sizeof(btConvexConvexAlgorithm);
|
||||||
int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
|
int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
|
||||||
int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
|
int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
|
||||||
int sl = sizeof(btConvexSeparatingDistanceUtil);
|
|
||||||
sl = sizeof(btGjkPairDetector);
|
|
||||||
int collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize);
|
int collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize);
|
||||||
collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
|
collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
|
||||||
collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
|
collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
|
||||||
|
|||||||
@@ -1,278 +1,278 @@
|
|||||||
/*
|
/*
|
||||||
Bullet Continuous Collision Detection and Physics Library
|
Bullet Continuous Collision Detection and Physics Library
|
||||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty.
|
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.
|
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,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it freely,
|
including commercial applications, and to alter it and redistribute it freely,
|
||||||
subject to the following restrictions:
|
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.
|
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.
|
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.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "btHashedSimplePairCache.h"
|
#include "btHashedSimplePairCache.h"
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int gOverlappingSimplePairs = 0;
|
int gOverlappingSimplePairs = 0;
|
||||||
int gRemoveSimplePairs =0;
|
int gRemoveSimplePairs =0;
|
||||||
int gAddedSimplePairs =0;
|
int gAddedSimplePairs =0;
|
||||||
int gFindSimplePairs =0;
|
int gFindSimplePairs =0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
btHashedSimplePairCache::btHashedSimplePairCache():
|
btHashedSimplePairCache::btHashedSimplePairCache():
|
||||||
m_blockedForChanges(false)
|
m_blockedForChanges(false)
|
||||||
{
|
{
|
||||||
int initialAllocatedSize= 2;
|
int initialAllocatedSize= 2;
|
||||||
m_overlappingPairArray.reserve(initialAllocatedSize);
|
m_overlappingPairArray.reserve(initialAllocatedSize);
|
||||||
growTables();
|
growTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
btHashedSimplePairCache::~btHashedSimplePairCache()
|
btHashedSimplePairCache::~btHashedSimplePairCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void btHashedSimplePairCache::removeAllPairs()
|
void btHashedSimplePairCache::removeAllPairs()
|
||||||
{
|
{
|
||||||
m_overlappingPairArray.clear();
|
m_overlappingPairArray.clear();
|
||||||
m_hashTable.clear();
|
m_hashTable.clear();
|
||||||
m_next.clear();
|
m_next.clear();
|
||||||
|
|
||||||
int initialAllocatedSize= 2;
|
int initialAllocatedSize= 2;
|
||||||
m_overlappingPairArray.reserve(initialAllocatedSize);
|
m_overlappingPairArray.reserve(initialAllocatedSize);
|
||||||
growTables();
|
growTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
btSimplePair* btHashedSimplePairCache::findPair(int indexA, int indexB)
|
btSimplePair* btHashedSimplePairCache::findPair(int indexA, int indexB)
|
||||||
{
|
{
|
||||||
gFindSimplePairs++;
|
gFindSimplePairs++;
|
||||||
|
|
||||||
|
|
||||||
/*if (indexA > indexB)
|
/*if (indexA > indexB)
|
||||||
btSwap(indexA, indexB);*/
|
btSwap(indexA, indexB);*/
|
||||||
|
|
||||||
int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA), static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
|
int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA), static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
|
||||||
|
|
||||||
if (hash >= m_hashTable.size())
|
if (hash >= m_hashTable.size())
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = m_hashTable[hash];
|
int index = m_hashTable[hash];
|
||||||
while (index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], indexA, indexB) == false)
|
while (index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], indexA, indexB) == false)
|
||||||
{
|
{
|
||||||
index = m_next[index];
|
index = m_next[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == BT_SIMPLE_NULL_PAIR)
|
if (index == BT_SIMPLE_NULL_PAIR)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
btAssert(index < m_overlappingPairArray.size());
|
btAssert(index < m_overlappingPairArray.size());
|
||||||
|
|
||||||
return &m_overlappingPairArray[index];
|
return &m_overlappingPairArray[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
//#include <stdio.h>
|
//#include <stdio.h>
|
||||||
|
|
||||||
void btHashedSimplePairCache::growTables()
|
void btHashedSimplePairCache::growTables()
|
||||||
{
|
{
|
||||||
|
|
||||||
int newCapacity = m_overlappingPairArray.capacity();
|
int newCapacity = m_overlappingPairArray.capacity();
|
||||||
|
|
||||||
if (m_hashTable.size() < newCapacity)
|
if (m_hashTable.size() < newCapacity)
|
||||||
{
|
{
|
||||||
//grow hashtable and next table
|
//grow hashtable and next table
|
||||||
int curHashtableSize = m_hashTable.size();
|
int curHashtableSize = m_hashTable.size();
|
||||||
|
|
||||||
m_hashTable.resize(newCapacity);
|
m_hashTable.resize(newCapacity);
|
||||||
m_next.resize(newCapacity);
|
m_next.resize(newCapacity);
|
||||||
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i= 0; i < newCapacity; ++i)
|
for (i= 0; i < newCapacity; ++i)
|
||||||
{
|
{
|
||||||
m_hashTable[i] = BT_SIMPLE_NULL_PAIR;
|
m_hashTable[i] = BT_SIMPLE_NULL_PAIR;
|
||||||
}
|
}
|
||||||
for (i = 0; i < newCapacity; ++i)
|
for (i = 0; i < newCapacity; ++i)
|
||||||
{
|
{
|
||||||
m_next[i] = BT_SIMPLE_NULL_PAIR;
|
m_next[i] = BT_SIMPLE_NULL_PAIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i<curHashtableSize;i++)
|
for(i=0;i<curHashtableSize;i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
const btSimplePair& pair = m_overlappingPairArray[i];
|
const btSimplePair& pair = m_overlappingPairArray[i];
|
||||||
int indexA = pair.m_indexA;
|
int indexA = pair.m_indexA;
|
||||||
int indexB = pair.m_indexB;
|
int indexB = pair.m_indexB;
|
||||||
|
|
||||||
int hashValue = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1)); // New hash value with new mask
|
int hashValue = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1)); // New hash value with new mask
|
||||||
m_next[i] = m_hashTable[hashValue];
|
m_next[i] = m_hashTable[hashValue];
|
||||||
m_hashTable[hashValue] = i;
|
m_hashTable[hashValue] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
btSimplePair* btHashedSimplePairCache::internalAddPair(int indexA, int indexB)
|
btSimplePair* btHashedSimplePairCache::internalAddPair(int indexA, int indexB)
|
||||||
{
|
{
|
||||||
|
|
||||||
int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1)); // New hash value with new mask
|
int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1)); // New hash value with new mask
|
||||||
|
|
||||||
|
|
||||||
btSimplePair* pair = internalFindPair(indexA, indexB, hash);
|
btSimplePair* pair = internalFindPair(indexA, indexB, hash);
|
||||||
if (pair != NULL)
|
if (pair != NULL)
|
||||||
{
|
{
|
||||||
return pair;
|
return pair;
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = m_overlappingPairArray.size();
|
int count = m_overlappingPairArray.size();
|
||||||
int oldCapacity = m_overlappingPairArray.capacity();
|
int oldCapacity = m_overlappingPairArray.capacity();
|
||||||
void* mem = &m_overlappingPairArray.expandNonInitializing();
|
void* mem = &m_overlappingPairArray.expandNonInitializing();
|
||||||
|
|
||||||
int newCapacity = m_overlappingPairArray.capacity();
|
int newCapacity = m_overlappingPairArray.capacity();
|
||||||
|
|
||||||
if (oldCapacity < newCapacity)
|
if (oldCapacity < newCapacity)
|
||||||
{
|
{
|
||||||
growTables();
|
growTables();
|
||||||
//hash with new capacity
|
//hash with new capacity
|
||||||
hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
|
hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
pair = new (mem) btSimplePair(indexA,indexB);
|
pair = new (mem) btSimplePair(indexA,indexB);
|
||||||
|
|
||||||
pair->m_userPointer = 0;
|
pair->m_userPointer = 0;
|
||||||
|
|
||||||
m_next[count] = m_hashTable[hash];
|
m_next[count] = m_hashTable[hash];
|
||||||
m_hashTable[hash] = count;
|
m_hashTable[hash] = count;
|
||||||
|
|
||||||
return pair;
|
return pair;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* btHashedSimplePairCache::removeOverlappingPair(int indexA, int indexB)
|
void* btHashedSimplePairCache::removeOverlappingPair(int indexA, int indexB)
|
||||||
{
|
{
|
||||||
gRemoveSimplePairs++;
|
gRemoveSimplePairs++;
|
||||||
|
|
||||||
|
|
||||||
/*if (indexA > indexB)
|
/*if (indexA > indexB)
|
||||||
btSwap(indexA, indexB);*/
|
btSwap(indexA, indexB);*/
|
||||||
|
|
||||||
int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
|
int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
|
||||||
|
|
||||||
btSimplePair* pair = internalFindPair(indexA, indexB, hash);
|
btSimplePair* pair = internalFindPair(indexA, indexB, hash);
|
||||||
if (pair == NULL)
|
if (pair == NULL)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void* userData = pair->m_userPointer;
|
void* userData = pair->m_userPointer;
|
||||||
|
|
||||||
|
|
||||||
int pairIndex = int(pair - &m_overlappingPairArray[0]);
|
int pairIndex = int(pair - &m_overlappingPairArray[0]);
|
||||||
btAssert(pairIndex < m_overlappingPairArray.size());
|
btAssert(pairIndex < m_overlappingPairArray.size());
|
||||||
|
|
||||||
// Remove the pair from the hash table.
|
// Remove the pair from the hash table.
|
||||||
int index = m_hashTable[hash];
|
int index = m_hashTable[hash];
|
||||||
btAssert(index != BT_SIMPLE_NULL_PAIR);
|
btAssert(index != BT_SIMPLE_NULL_PAIR);
|
||||||
|
|
||||||
int previous = BT_SIMPLE_NULL_PAIR;
|
int previous = BT_SIMPLE_NULL_PAIR;
|
||||||
while (index != pairIndex)
|
while (index != pairIndex)
|
||||||
{
|
{
|
||||||
previous = index;
|
previous = index;
|
||||||
index = m_next[index];
|
index = m_next[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previous != BT_SIMPLE_NULL_PAIR)
|
if (previous != BT_SIMPLE_NULL_PAIR)
|
||||||
{
|
{
|
||||||
btAssert(m_next[previous] == pairIndex);
|
btAssert(m_next[previous] == pairIndex);
|
||||||
m_next[previous] = m_next[pairIndex];
|
m_next[previous] = m_next[pairIndex];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_hashTable[hash] = m_next[pairIndex];
|
m_hashTable[hash] = m_next[pairIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
// We now move the last pair into spot of the
|
// We now move the last pair into spot of the
|
||||||
// pair being removed. We need to fix the hash
|
// pair being removed. We need to fix the hash
|
||||||
// table indices to support the move.
|
// table indices to support the move.
|
||||||
|
|
||||||
int lastPairIndex = m_overlappingPairArray.size() - 1;
|
int lastPairIndex = m_overlappingPairArray.size() - 1;
|
||||||
|
|
||||||
// If the removed pair is the last pair, we are done.
|
// If the removed pair is the last pair, we are done.
|
||||||
if (lastPairIndex == pairIndex)
|
if (lastPairIndex == pairIndex)
|
||||||
{
|
{
|
||||||
m_overlappingPairArray.pop_back();
|
m_overlappingPairArray.pop_back();
|
||||||
return userData;
|
return userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the last pair from the hash table.
|
// Remove the last pair from the hash table.
|
||||||
const btSimplePair* last = &m_overlappingPairArray[lastPairIndex];
|
const btSimplePair* last = &m_overlappingPairArray[lastPairIndex];
|
||||||
/* missing swap here too, Nat. */
|
/* missing swap here too, Nat. */
|
||||||
int lastHash = static_cast<int>(getHash(static_cast<unsigned int>(last->m_indexA), static_cast<unsigned int>(last->m_indexB)) & (m_overlappingPairArray.capacity()-1));
|
int lastHash = static_cast<int>(getHash(static_cast<unsigned int>(last->m_indexA), static_cast<unsigned int>(last->m_indexB)) & (m_overlappingPairArray.capacity()-1));
|
||||||
|
|
||||||
index = m_hashTable[lastHash];
|
index = m_hashTable[lastHash];
|
||||||
btAssert(index != BT_SIMPLE_NULL_PAIR);
|
btAssert(index != BT_SIMPLE_NULL_PAIR);
|
||||||
|
|
||||||
previous = BT_SIMPLE_NULL_PAIR;
|
previous = BT_SIMPLE_NULL_PAIR;
|
||||||
while (index != lastPairIndex)
|
while (index != lastPairIndex)
|
||||||
{
|
{
|
||||||
previous = index;
|
previous = index;
|
||||||
index = m_next[index];
|
index = m_next[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previous != BT_SIMPLE_NULL_PAIR)
|
if (previous != BT_SIMPLE_NULL_PAIR)
|
||||||
{
|
{
|
||||||
btAssert(m_next[previous] == lastPairIndex);
|
btAssert(m_next[previous] == lastPairIndex);
|
||||||
m_next[previous] = m_next[lastPairIndex];
|
m_next[previous] = m_next[lastPairIndex];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_hashTable[lastHash] = m_next[lastPairIndex];
|
m_hashTable[lastHash] = m_next[lastPairIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the last pair into the remove pair's spot.
|
// Copy the last pair into the remove pair's spot.
|
||||||
m_overlappingPairArray[pairIndex] = m_overlappingPairArray[lastPairIndex];
|
m_overlappingPairArray[pairIndex] = m_overlappingPairArray[lastPairIndex];
|
||||||
|
|
||||||
// Insert the last pair into the hash table
|
// Insert the last pair into the hash table
|
||||||
m_next[pairIndex] = m_hashTable[lastHash];
|
m_next[pairIndex] = m_hashTable[lastHash];
|
||||||
m_hashTable[lastHash] = pairIndex;
|
m_hashTable[lastHash] = pairIndex;
|
||||||
|
|
||||||
m_overlappingPairArray.pop_back();
|
m_overlappingPairArray.pop_back();
|
||||||
|
|
||||||
return userData;
|
return userData;
|
||||||
}
|
}
|
||||||
//#include <stdio.h>
|
//#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,174 +1,174 @@
|
|||||||
/*
|
/*
|
||||||
Bullet Continuous Collision Detection and Physics Library
|
Bullet Continuous Collision Detection and Physics Library
|
||||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty.
|
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.
|
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,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it freely,
|
including commercial applications, and to alter it and redistribute it freely,
|
||||||
subject to the following restrictions:
|
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.
|
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.
|
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.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef BT_HASHED_SIMPLE_PAIR_CACHE_H
|
#ifndef BT_HASHED_SIMPLE_PAIR_CACHE_H
|
||||||
#define BT_HASHED_SIMPLE_PAIR_CACHE_H
|
#define BT_HASHED_SIMPLE_PAIR_CACHE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "LinearMath/btAlignedObjectArray.h"
|
#include "LinearMath/btAlignedObjectArray.h"
|
||||||
|
|
||||||
const int BT_SIMPLE_NULL_PAIR=0xffffffff;
|
const int BT_SIMPLE_NULL_PAIR=0xffffffff;
|
||||||
|
|
||||||
struct btSimplePair
|
struct btSimplePair
|
||||||
{
|
{
|
||||||
btSimplePair(int indexA,int indexB)
|
btSimplePair(int indexA,int indexB)
|
||||||
:m_indexA(indexA),
|
:m_indexA(indexA),
|
||||||
m_indexB(indexB),
|
m_indexB(indexB),
|
||||||
m_userPointer(0)
|
m_userPointer(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_indexA;
|
int m_indexA;
|
||||||
int m_indexB;
|
int m_indexB;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
void* m_userPointer;
|
void* m_userPointer;
|
||||||
int m_userValue;
|
int m_userValue;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef btAlignedObjectArray<btSimplePair> btSimplePairArray;
|
typedef btAlignedObjectArray<btSimplePair> btSimplePairArray;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern int gOverlappingSimplePairs;
|
extern int gOverlappingSimplePairs;
|
||||||
extern int gRemoveSimplePairs;
|
extern int gRemoveSimplePairs;
|
||||||
extern int gAddedSimplePairs;
|
extern int gAddedSimplePairs;
|
||||||
extern int gFindSimplePairs;
|
extern int gFindSimplePairs;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class btHashedSimplePairCache
|
class btHashedSimplePairCache
|
||||||
{
|
{
|
||||||
btSimplePairArray m_overlappingPairArray;
|
btSimplePairArray m_overlappingPairArray;
|
||||||
|
|
||||||
bool m_blockedForChanges;
|
bool m_blockedForChanges;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
btAlignedObjectArray<int> m_hashTable;
|
btAlignedObjectArray<int> m_hashTable;
|
||||||
btAlignedObjectArray<int> m_next;
|
btAlignedObjectArray<int> m_next;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
btHashedSimplePairCache();
|
btHashedSimplePairCache();
|
||||||
virtual ~btHashedSimplePairCache();
|
virtual ~btHashedSimplePairCache();
|
||||||
|
|
||||||
void removeAllPairs();
|
void removeAllPairs();
|
||||||
|
|
||||||
virtual void* removeOverlappingPair(int indexA,int indexB);
|
virtual void* removeOverlappingPair(int indexA,int indexB);
|
||||||
|
|
||||||
// Add a pair and return the new pair. If the pair already exists,
|
// Add a pair and return the new pair. If the pair already exists,
|
||||||
// no new pair is created and the old one is returned.
|
// no new pair is created and the old one is returned.
|
||||||
virtual btSimplePair* addOverlappingPair(int indexA,int indexB)
|
virtual btSimplePair* addOverlappingPair(int indexA,int indexB)
|
||||||
{
|
{
|
||||||
gAddedSimplePairs++;
|
gAddedSimplePairs++;
|
||||||
|
|
||||||
return internalAddPair(indexA,indexB);
|
return internalAddPair(indexA,indexB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual btSimplePair* getOverlappingPairArrayPtr()
|
virtual btSimplePair* getOverlappingPairArrayPtr()
|
||||||
{
|
{
|
||||||
return &m_overlappingPairArray[0];
|
return &m_overlappingPairArray[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const btSimplePair* getOverlappingPairArrayPtr() const
|
const btSimplePair* getOverlappingPairArrayPtr() const
|
||||||
{
|
{
|
||||||
return &m_overlappingPairArray[0];
|
return &m_overlappingPairArray[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
btSimplePairArray& getOverlappingPairArray()
|
btSimplePairArray& getOverlappingPairArray()
|
||||||
{
|
{
|
||||||
return m_overlappingPairArray;
|
return m_overlappingPairArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
const btSimplePairArray& getOverlappingPairArray() const
|
const btSimplePairArray& getOverlappingPairArray() const
|
||||||
{
|
{
|
||||||
return m_overlappingPairArray;
|
return m_overlappingPairArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
btSimplePair* findPair(int indexA,int indexB);
|
btSimplePair* findPair(int indexA,int indexB);
|
||||||
|
|
||||||
int GetCount() const { return m_overlappingPairArray.size(); }
|
int GetCount() const { return m_overlappingPairArray.size(); }
|
||||||
|
|
||||||
int getNumOverlappingPairs() const
|
int getNumOverlappingPairs() const
|
||||||
{
|
{
|
||||||
return m_overlappingPairArray.size();
|
return m_overlappingPairArray.size();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|
||||||
btSimplePair* internalAddPair(int indexA, int indexB);
|
btSimplePair* internalAddPair(int indexA, int indexB);
|
||||||
|
|
||||||
void growTables();
|
void growTables();
|
||||||
|
|
||||||
SIMD_FORCE_INLINE bool equalsPair(const btSimplePair& pair, int indexA, int indexB)
|
SIMD_FORCE_INLINE bool equalsPair(const btSimplePair& pair, int indexA, int indexB)
|
||||||
{
|
{
|
||||||
return pair.m_indexA == indexA && pair.m_indexB == indexB;
|
return pair.m_indexA == indexA && pair.m_indexB == indexB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SIMD_FORCE_INLINE unsigned int getHash(unsigned int indexA, unsigned int indexB)
|
SIMD_FORCE_INLINE unsigned int getHash(unsigned int indexA, unsigned int indexB)
|
||||||
{
|
{
|
||||||
int key = static_cast<int>(((unsigned int)indexA) | (((unsigned int)indexB) <<16));
|
int key = static_cast<int>(((unsigned int)indexA) | (((unsigned int)indexB) <<16));
|
||||||
// Thomas Wang's hash
|
// Thomas Wang's hash
|
||||||
|
|
||||||
key += ~(key << 15);
|
key += ~(key << 15);
|
||||||
key ^= (key >> 10);
|
key ^= (key >> 10);
|
||||||
key += (key << 3);
|
key += (key << 3);
|
||||||
key ^= (key >> 6);
|
key ^= (key >> 6);
|
||||||
key += ~(key << 11);
|
key += ~(key << 11);
|
||||||
key ^= (key >> 16);
|
key ^= (key >> 16);
|
||||||
return static_cast<unsigned int>(key);
|
return static_cast<unsigned int>(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SIMD_FORCE_INLINE btSimplePair* internalFindPair(int proxyIdA , int proxyIdB, int hash)
|
SIMD_FORCE_INLINE btSimplePair* internalFindPair(int proxyIdA , int proxyIdB, int hash)
|
||||||
{
|
{
|
||||||
|
|
||||||
int index = m_hashTable[hash];
|
int index = m_hashTable[hash];
|
||||||
|
|
||||||
while( index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyIdA, proxyIdB) == false)
|
while( index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyIdA, proxyIdB) == false)
|
||||||
{
|
{
|
||||||
index = m_next[index];
|
index = m_next[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( index == BT_SIMPLE_NULL_PAIR )
|
if ( index == BT_SIMPLE_NULL_PAIR )
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
btAssert(index < m_overlappingPairArray.size());
|
btAssert(index < m_overlappingPairArray.size());
|
||||||
|
|
||||||
return &m_overlappingPairArray[index];
|
return &m_overlappingPairArray[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //BT_HASHED_SIMPLE_PAIR_CACHE_H
|
#endif //BT_HASHED_SIMPLE_PAIR_CACHE_H
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ struct btConnectivityProcessor : public btTriangleCallback
|
|||||||
if(numshared >= 3)
|
if(numshared >= 3)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (numshared)
|
switch (numshared)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -203,6 +202,7 @@ struct btConnectivityProcessor : public btTriangleCallback
|
|||||||
ang4 = 0.f;
|
ang4 = 0.f;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
|
||||||
calculatedEdge.normalize();
|
calculatedEdge.normalize();
|
||||||
btVector3 calculatedNormalA = calculatedEdge.cross(edgeCrossA);
|
btVector3 calculatedNormalA = calculatedEdge.cross(edgeCrossA);
|
||||||
calculatedNormalA.normalize();
|
calculatedNormalA.normalize();
|
||||||
@@ -213,7 +213,7 @@ struct btConnectivityProcessor : public btTriangleCallback
|
|||||||
isConvex = (dotA<0.);
|
isConvex = (dotA<0.);
|
||||||
|
|
||||||
correctedAngle = isConvex ? ang4 : -ang4;
|
correctedAngle = isConvex ? ang4 : -ang4;
|
||||||
btQuaternion orn2 = btQuaternion(btVector3(calculatedEdge.x(), calculatedEdge.y(), calculatedEdge.z()),-correctedAngle);
|
btQuaternion orn2(calculatedEdge,-correctedAngle);
|
||||||
calculatedNormalB = btMatrix3x3(orn2)*normalA;
|
calculatedNormalB = btMatrix3x3(orn2)*normalA;
|
||||||
|
|
||||||
|
|
||||||
@@ -301,6 +301,11 @@ struct btConnectivityProcessor : public btTriangleCallback
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// printf("warning: duplicate triangle\n");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,18 +28,14 @@ ATTRIBUTE_ALIGNED16(class) btCollisionShape
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
int m_shapeType;
|
int m_shapeType;
|
||||||
|
void* m_userPointer;
|
||||||
|
int m_userIndex;
|
||||||
|
|
||||||
union
|
|
||||||
{
|
|
||||||
void* m_userPointer;
|
|
||||||
int m_userIndex;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0)
|
btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0), m_userIndex(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,17 +131,17 @@ public:
|
|||||||
{
|
{
|
||||||
return m_userPointer;
|
return m_userPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUserIndex(int index)
|
void setUserIndex(int index)
|
||||||
{
|
{
|
||||||
m_userIndex = index;
|
m_userIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getUserIndex() const
|
int getUserIndex() const
|
||||||
{
|
{
|
||||||
return m_userIndex;
|
return m_userIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual int calculateSerializeBufferSize() const;
|
virtual int calculateSerializeBufferSize() const;
|
||||||
|
|
||||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ void btCompoundShape::createAabbTreeFromChildren()
|
|||||||
m_dynamicAabbTree = new(mem) btDbvt();
|
m_dynamicAabbTree = new(mem) btDbvt();
|
||||||
btAssert(mem==m_dynamicAabbTree);
|
btAssert(mem==m_dynamicAabbTree);
|
||||||
|
|
||||||
for ( size_t index = 0; index < m_children.size(); index++ )
|
for ( int index = 0; index < m_children.size(); index++ )
|
||||||
{
|
{
|
||||||
btCompoundShapeChild &child = m_children[index];
|
btCompoundShapeChild &child = m_children[index];
|
||||||
|
|
||||||
@@ -312,7 +312,8 @@ void btCompoundShape::createAabbTreeFromChildren()
|
|||||||
child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax);
|
child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax);
|
||||||
|
|
||||||
const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
|
const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
|
||||||
child.m_node = m_dynamicAabbTree->insert(bounds, reinterpret_cast<void*>(index) );
|
size_t index2 = index;
|
||||||
|
child.m_node = m_dynamicAabbTree->insert(bounds, reinterpret_cast<void*>(index2) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ void btConvexPolyhedron::initialize()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void btConvexPolyhedron::project(const btTransform& trans, const btVector3& dir, btScalar& minProj, btScalar& maxProj, btVector3& witnesPtMin,btVector3& witnesPtMax) const
|
void btConvexPolyhedron::project(const btTransform& trans, const btVector3& dir, btScalar& minProj, btScalar& maxProj, btVector3& witnesPtMin,btVector3& witnesPtMax) const
|
||||||
{
|
{
|
||||||
minProj = FLT_MAX;
|
minProj = FLT_MAX;
|
||||||
maxProj = -FLT_MAX;
|
maxProj = -FLT_MAX;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ ATTRIBUTE_ALIGNED16(class) btConvexPolyhedron
|
|||||||
void initialize();
|
void initialize();
|
||||||
bool testContainment() const;
|
bool testContainment() const;
|
||||||
|
|
||||||
void project(const btTransform& trans, const btVector3& dir, btScalar& minProj, btScalar& maxProj, btVector3& witnesPtMin,btVector3& witnesPtMax) const;
|
void project(const btTransform& trans, const btVector3& dir, btScalar& minProj, btScalar& maxProj, btVector3& witnesPtMin,btVector3& witnesPtMax) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -365,13 +365,13 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
|
|||||||
{
|
{
|
||||||
//first triangle
|
//first triangle
|
||||||
getVertex(x,j,vertices[0]);
|
getVertex(x,j,vertices[0]);
|
||||||
getVertex(x, j + 1, vertices[1]);
|
getVertex(x, j + 1, vertices[1]);
|
||||||
getVertex(x + 1, j + 1, vertices[2]);
|
getVertex(x + 1, j + 1, vertices[2]);
|
||||||
callback->processTriangle(vertices,x,j);
|
callback->processTriangle(vertices,x,j);
|
||||||
//second triangle
|
//second triangle
|
||||||
// getVertex(x,j,vertices[0]);//already got this vertex before, thanks to Danny Chapman
|
// getVertex(x,j,vertices[0]);//already got this vertex before, thanks to Danny Chapman
|
||||||
getVertex(x+1,j+1,vertices[1]);
|
getVertex(x+1,j+1,vertices[1]);
|
||||||
getVertex(x + 1, j, vertices[2]);
|
getVertex(x + 1, j, vertices[2]);
|
||||||
callback->processTriangle(vertices, x, j);
|
callback->processTriangle(vertices, x, j);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
|||||||
@@ -1,93 +1,93 @@
|
|||||||
#ifndef BT_COMPOUND_FROM_GIMPACT
|
#ifndef BT_COMPOUND_FROM_GIMPACT
|
||||||
#define BT_COMPOUND_FROM_GIMPACT
|
#define BT_COMPOUND_FROM_GIMPACT
|
||||||
|
|
||||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||||
#include "btGImpactShape.h"
|
#include "btGImpactShape.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
|
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
|
||||||
|
|
||||||
struct MyCallback : public btTriangleRaycastCallback
|
struct MyCallback : public btTriangleRaycastCallback
|
||||||
{
|
{
|
||||||
int m_ignorePart;
|
int m_ignorePart;
|
||||||
int m_ignoreTriangleIndex;
|
int m_ignoreTriangleIndex;
|
||||||
|
|
||||||
|
|
||||||
MyCallback(const btVector3& from, const btVector3& to, int ignorePart, int ignoreTriangleIndex)
|
MyCallback(const btVector3& from, const btVector3& to, int ignorePart, int ignoreTriangleIndex)
|
||||||
:btTriangleRaycastCallback(from,to),
|
:btTriangleRaycastCallback(from,to),
|
||||||
m_ignorePart(ignorePart),
|
m_ignorePart(ignorePart),
|
||||||
m_ignoreTriangleIndex(ignoreTriangleIndex)
|
m_ignoreTriangleIndex(ignoreTriangleIndex)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex)
|
virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex)
|
||||||
{
|
{
|
||||||
if (partId!=m_ignorePart || triangleIndex!=m_ignoreTriangleIndex)
|
if (partId!=m_ignorePart || triangleIndex!=m_ignoreTriangleIndex)
|
||||||
{
|
{
|
||||||
if (hitFraction < m_hitFraction)
|
if (hitFraction < m_hitFraction)
|
||||||
return hitFraction;
|
return hitFraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_hitFraction;
|
return m_hitFraction;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct MyInternalTriangleIndexCallback :public btInternalTriangleIndexCallback
|
struct MyInternalTriangleIndexCallback :public btInternalTriangleIndexCallback
|
||||||
{
|
{
|
||||||
const btGImpactMeshShape* m_gimpactShape;
|
const btGImpactMeshShape* m_gimpactShape;
|
||||||
btCompoundShape* m_colShape;
|
btCompoundShape* m_colShape;
|
||||||
btScalar m_depth;
|
btScalar m_depth;
|
||||||
|
|
||||||
MyInternalTriangleIndexCallback (btCompoundShape* colShape, const btGImpactMeshShape* meshShape, btScalar depth)
|
MyInternalTriangleIndexCallback (btCompoundShape* colShape, const btGImpactMeshShape* meshShape, btScalar depth)
|
||||||
:m_colShape(colShape),
|
:m_colShape(colShape),
|
||||||
m_gimpactShape(meshShape),
|
m_gimpactShape(meshShape),
|
||||||
m_depth(depth)
|
m_depth(depth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
|
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
|
||||||
{
|
{
|
||||||
btVector3 scale = m_gimpactShape->getLocalScaling();
|
btVector3 scale = m_gimpactShape->getLocalScaling();
|
||||||
btVector3 v0=triangle[0]*scale;
|
btVector3 v0=triangle[0]*scale;
|
||||||
btVector3 v1=triangle[1]*scale;
|
btVector3 v1=triangle[1]*scale;
|
||||||
btVector3 v2=triangle[2]*scale;
|
btVector3 v2=triangle[2]*scale;
|
||||||
|
|
||||||
btVector3 centroid = (v0+v1+v2)/3;
|
btVector3 centroid = (v0+v1+v2)/3;
|
||||||
btVector3 normal = (v1-v0).cross(v2-v0);
|
btVector3 normal = (v1-v0).cross(v2-v0);
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
btVector3 rayFrom = centroid;
|
btVector3 rayFrom = centroid;
|
||||||
btVector3 rayTo = centroid-normal*m_depth;
|
btVector3 rayTo = centroid-normal*m_depth;
|
||||||
|
|
||||||
MyCallback cb(rayFrom,rayTo,partId,triangleIndex);
|
MyCallback cb(rayFrom,rayTo,partId,triangleIndex);
|
||||||
|
|
||||||
m_gimpactShape->processAllTrianglesRay(&cb,rayFrom, rayTo);
|
m_gimpactShape->processAllTrianglesRay(&cb,rayFrom, rayTo);
|
||||||
if (cb.m_hitFraction<1)
|
if (cb.m_hitFraction<1)
|
||||||
{
|
{
|
||||||
rayTo.setInterpolate3(cb.m_from,cb.m_to,cb.m_hitFraction);
|
rayTo.setInterpolate3(cb.m_from,cb.m_to,cb.m_hitFraction);
|
||||||
//rayTo = cb.m_from;
|
//rayTo = cb.m_from;
|
||||||
//rayTo = rayTo.lerp(cb.m_to,cb.m_hitFraction);
|
//rayTo = rayTo.lerp(cb.m_to,cb.m_hitFraction);
|
||||||
//gDebugDraw.drawLine(tr(centroid),tr(centroid+normal),btVector3(1,0,0));
|
//gDebugDraw.drawLine(tr(centroid),tr(centroid+normal),btVector3(1,0,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
btBU_Simplex1to4* tet = new btBU_Simplex1to4(v0,v1,v2,rayTo);
|
btBU_Simplex1to4* tet = new btBU_Simplex1to4(v0,v1,v2,rayTo);
|
||||||
btTransform ident;
|
btTransform ident;
|
||||||
ident.setIdentity();
|
ident.setIdentity();
|
||||||
m_colShape->addChildShape(ident,tet);
|
m_colShape->addChildShape(ident,tet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
btCompoundShape* btCreateCompoundFromGimpactShape(const btGImpactMeshShape* gimpactMesh, btScalar depth)
|
btCompoundShape* btCreateCompoundFromGimpactShape(const btGImpactMeshShape* gimpactMesh, btScalar depth)
|
||||||
{
|
{
|
||||||
btCompoundShape* colShape = new btCompoundShape();
|
btCompoundShape* colShape = new btCompoundShape();
|
||||||
|
|
||||||
btTransform tr;
|
btTransform tr;
|
||||||
tr.setIdentity();
|
tr.setIdentity();
|
||||||
|
|
||||||
MyInternalTriangleIndexCallback cb(colShape,gimpactMesh, depth);
|
MyInternalTriangleIndexCallback cb(colShape,gimpactMesh, depth);
|
||||||
btVector3 aabbMin,aabbMax;
|
btVector3 aabbMin,aabbMax;
|
||||||
gimpactMesh->getAabb(tr,aabbMin,aabbMax);
|
gimpactMesh->getAabb(tr,aabbMin,aabbMax);
|
||||||
gimpactMesh->getMeshInterface()->InternalProcessAllTriangles(&cb,aabbMin,aabbMax);
|
gimpactMesh->getMeshInterface()->InternalProcessAllTriangles(&cb,aabbMin,aabbMax);
|
||||||
|
|
||||||
return colShape;
|
return colShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //BT_COMPOUND_FROM_GIMPACT
|
#endif //BT_COMPOUND_FROM_GIMPACT
|
||||||
@@ -178,62 +178,62 @@ void InverseTransformPoint3x3(btVector3& out, const btVector3& in, const btTrans
|
|||||||
}
|
}
|
||||||
#endif //TEST_INTERNAL_OBJECTS
|
#endif //TEST_INTERNAL_OBJECTS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SIMD_FORCE_INLINE void btSegmentsClosestPoints(
|
SIMD_FORCE_INLINE void btSegmentsClosestPoints(
|
||||||
btVector3& ptsVector,
|
btVector3& ptsVector,
|
||||||
btVector3& offsetA,
|
btVector3& offsetA,
|
||||||
btVector3& offsetB,
|
btVector3& offsetB,
|
||||||
btScalar& tA, btScalar& tB,
|
btScalar& tA, btScalar& tB,
|
||||||
const btVector3& translation,
|
const btVector3& translation,
|
||||||
const btVector3& dirA, btScalar hlenA,
|
const btVector3& dirA, btScalar hlenA,
|
||||||
const btVector3& dirB, btScalar hlenB )
|
const btVector3& dirB, btScalar hlenB )
|
||||||
{
|
{
|
||||||
// compute the parameters of the closest points on each line segment
|
// compute the parameters of the closest points on each line segment
|
||||||
|
|
||||||
btScalar dirA_dot_dirB = btDot(dirA,dirB);
|
btScalar dirA_dot_dirB = btDot(dirA,dirB);
|
||||||
btScalar dirA_dot_trans = btDot(dirA,translation);
|
btScalar dirA_dot_trans = btDot(dirA,translation);
|
||||||
btScalar dirB_dot_trans = btDot(dirB,translation);
|
btScalar dirB_dot_trans = btDot(dirB,translation);
|
||||||
|
|
||||||
btScalar denom = 1.0f - dirA_dot_dirB * dirA_dot_dirB;
|
btScalar denom = 1.0f - dirA_dot_dirB * dirA_dot_dirB;
|
||||||
|
|
||||||
if ( denom == 0.0f ) {
|
if ( denom == 0.0f ) {
|
||||||
tA = 0.0f;
|
tA = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
tA = ( dirA_dot_trans - dirB_dot_trans * dirA_dot_dirB ) / denom;
|
tA = ( dirA_dot_trans - dirB_dot_trans * dirA_dot_dirB ) / denom;
|
||||||
if ( tA < -hlenA )
|
if ( tA < -hlenA )
|
||||||
tA = -hlenA;
|
tA = -hlenA;
|
||||||
else if ( tA > hlenA )
|
else if ( tA > hlenA )
|
||||||
tA = hlenA;
|
tA = hlenA;
|
||||||
}
|
}
|
||||||
|
|
||||||
tB = tA * dirA_dot_dirB - dirB_dot_trans;
|
tB = tA * dirA_dot_dirB - dirB_dot_trans;
|
||||||
|
|
||||||
if ( tB < -hlenB ) {
|
if ( tB < -hlenB ) {
|
||||||
tB = -hlenB;
|
tB = -hlenB;
|
||||||
tA = tB * dirA_dot_dirB + dirA_dot_trans;
|
tA = tB * dirA_dot_dirB + dirA_dot_trans;
|
||||||
|
|
||||||
if ( tA < -hlenA )
|
if ( tA < -hlenA )
|
||||||
tA = -hlenA;
|
tA = -hlenA;
|
||||||
else if ( tA > hlenA )
|
else if ( tA > hlenA )
|
||||||
tA = hlenA;
|
tA = hlenA;
|
||||||
} else if ( tB > hlenB ) {
|
} else if ( tB > hlenB ) {
|
||||||
tB = hlenB;
|
tB = hlenB;
|
||||||
tA = tB * dirA_dot_dirB + dirA_dot_trans;
|
tA = tB * dirA_dot_dirB + dirA_dot_trans;
|
||||||
|
|
||||||
if ( tA < -hlenA )
|
if ( tA < -hlenA )
|
||||||
tA = -hlenA;
|
tA = -hlenA;
|
||||||
else if ( tA > hlenA )
|
else if ( tA > hlenA )
|
||||||
tA = hlenA;
|
tA = hlenA;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute the closest points relative to segment centers.
|
// compute the closest points relative to segment centers.
|
||||||
|
|
||||||
offsetA = dirA * tA;
|
offsetA = dirA * tA;
|
||||||
offsetB = dirB * tB;
|
offsetB = dirB * tB;
|
||||||
|
|
||||||
ptsVector = translation - offsetA + offsetB;
|
ptsVector = translation - offsetA + offsetB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ bool btPolyhedralContactClipping::findSeparatingAxis( const btConvexPolyhedron&
|
|||||||
int edgeB=-1;
|
int edgeB=-1;
|
||||||
btVector3 worldEdgeA;
|
btVector3 worldEdgeA;
|
||||||
btVector3 worldEdgeB;
|
btVector3 worldEdgeB;
|
||||||
btVector3 witnessPointA,witnessPointB;
|
btVector3 witnessPointA(0,0,0),witnessPointB(0,0,0);
|
||||||
|
|
||||||
|
|
||||||
int curEdgeEdge = 0;
|
int curEdgeEdge = 0;
|
||||||
@@ -369,23 +369,23 @@ bool btPolyhedralContactClipping::findSeparatingAxis( const btConvexPolyhedron&
|
|||||||
// printf("edge-edge\n");
|
// printf("edge-edge\n");
|
||||||
//add an edge-edge contact
|
//add an edge-edge contact
|
||||||
|
|
||||||
btVector3 ptsVector;
|
btVector3 ptsVector;
|
||||||
btVector3 offsetA;
|
btVector3 offsetA;
|
||||||
btVector3 offsetB;
|
btVector3 offsetB;
|
||||||
btScalar tA;
|
btScalar tA;
|
||||||
btScalar tB;
|
btScalar tB;
|
||||||
|
|
||||||
btVector3 translation = witnessPointB-witnessPointA;
|
btVector3 translation = witnessPointB-witnessPointA;
|
||||||
|
|
||||||
btVector3 dirA = worldEdgeA;
|
btVector3 dirA = worldEdgeA;
|
||||||
btVector3 dirB = worldEdgeB;
|
btVector3 dirB = worldEdgeB;
|
||||||
|
|
||||||
btScalar hlenB = 1e30f;
|
btScalar hlenB = 1e30f;
|
||||||
btScalar hlenA = 1e30f;
|
btScalar hlenA = 1e30f;
|
||||||
|
|
||||||
btSegmentsClosestPoints(ptsVector,offsetA,offsetB,tA,tB,
|
btSegmentsClosestPoints(ptsVector,offsetA,offsetB,tA,tB,
|
||||||
translation,
|
translation,
|
||||||
dirA, hlenA,
|
dirA, hlenA,
|
||||||
dirB,hlenB);
|
dirB,hlenB);
|
||||||
|
|
||||||
btScalar nlSqrt = ptsVector.length2();
|
btScalar nlSqrt = ptsVector.length2();
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ subject to the following restrictions:
|
|||||||
struct btBroadphaseProxy;
|
struct btBroadphaseProxy;
|
||||||
class btConvexShape;
|
class btConvexShape;
|
||||||
|
|
||||||
|
|
||||||
class btTriangleRaycastCallback: public btTriangleCallback
|
class btTriangleRaycastCallback: public btTriangleCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -33,7 +32,7 @@ public:
|
|||||||
//@BP Mod - allow backface filtering and unflipped normals
|
//@BP Mod - allow backface filtering and unflipped normals
|
||||||
enum EFlags
|
enum EFlags
|
||||||
{
|
{
|
||||||
kF_None = 0,
|
kF_None = 0,
|
||||||
kF_FilterBackfaces = 1 << 0,
|
kF_FilterBackfaces = 1 << 0,
|
||||||
kF_KeepUnflippedNormal = 1 << 1, // Prevents returned face normal getting flipped when a ray hits a back-facing triangle
|
kF_KeepUnflippedNormal = 1 << 1, // Prevents returned face normal getting flipped when a ray hits a back-facing triangle
|
||||||
///SubSimplexConvexCastRaytest is the default, even if kF_None is set.
|
///SubSimplexConvexCastRaytest is the default, even if kF_None is set.
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ bool btSubsimplexConvexCast::calcTimeOfImpact(
|
|||||||
|
|
||||||
btVector3 n;
|
btVector3 n;
|
||||||
n.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
|
n.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||||
bool hasResult = false;
|
|
||||||
btVector3 c;
|
btVector3 c;
|
||||||
|
|
||||||
btScalar lastLambda = lambda;
|
|
||||||
|
|
||||||
|
|
||||||
btScalar dist2 = v.length2();
|
btScalar dist2 = v.length2();
|
||||||
@@ -109,9 +109,9 @@ bool btSubsimplexConvexCast::calcTimeOfImpact(
|
|||||||
//m_simplexSolver->reset();
|
//m_simplexSolver->reset();
|
||||||
//check next line
|
//check next line
|
||||||
w = supVertexA-supVertexB;
|
w = supVertexA-supVertexB;
|
||||||
lastLambda = lambda;
|
|
||||||
n = v;
|
n = v;
|
||||||
hasResult = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
///Just like regular GJK only add the vertex if it isn't already (close) to current vertex, it would lead to divisions by zero and NaN etc.
|
///Just like regular GJK only add the vertex if it isn't already (close) to current vertex, it would lead to divisions by zero and NaN etc.
|
||||||
@@ -121,7 +121,7 @@ bool btSubsimplexConvexCast::calcTimeOfImpact(
|
|||||||
if (m_simplexSolver->closest(v))
|
if (m_simplexSolver->closest(v))
|
||||||
{
|
{
|
||||||
dist2 = v.length2();
|
dist2 = v.length2();
|
||||||
hasResult = true;
|
|
||||||
//todo: check this normal for validity
|
//todo: check this normal for validity
|
||||||
//n=v;
|
//n=v;
|
||||||
//printf("V=%f , %f, %f\n",v[0],v[1],v[2]);
|
//printf("V=%f , %f, %f\n",v[0],v[1],v[2]);
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
project "BulletCollision"
|
project "BulletCollision"
|
||||||
|
|
||||||
kind "StaticLib"
|
kind "StaticLib"
|
||||||
targetdir "../../lib"
|
targetdir "../../lib"
|
||||||
includedirs {
|
includedirs {
|
||||||
"..",
|
"..",
|
||||||
}
|
}
|
||||||
files {
|
files {
|
||||||
"*.cpp",
|
"*.cpp",
|
||||||
"*.h",
|
"*.h",
|
||||||
"BroadphaseCollision/*.cpp",
|
"BroadphaseCollision/*.cpp",
|
||||||
"BroadphaseCollision/*.h",
|
"BroadphaseCollision/*.h",
|
||||||
"CollisionDispatch/*.cpp",
|
"CollisionDispatch/*.cpp",
|
||||||
"CollisionDispatch/*.h",
|
"CollisionDispatch/*.h",
|
||||||
"CollisionShapes/*.cpp",
|
"CollisionShapes/*.cpp",
|
||||||
"CollisionShapes/*.h",
|
"CollisionShapes/*.h",
|
||||||
"Gimpact/*.cpp",
|
"Gimpact/*.cpp",
|
||||||
"Gimpact/*.h",
|
"Gimpact/*.h",
|
||||||
"NarrowPhaseCollision/*.cpp",
|
"NarrowPhaseCollision/*.cpp",
|
||||||
"NarrowPhaseCollision/*.h",
|
"NarrowPhaseCollision/*.h",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user