diff options
27 files changed, 231 insertions, 150 deletions
diff --git a/extern/bullet/Bullet/BroadphaseCollision/BroadphaseInterface.h b/extern/bullet/Bullet/BroadphaseCollision/BroadphaseInterface.h index d4ac5d0b624..b81815b9764 100644 --- a/extern/bullet/Bullet/BroadphaseCollision/BroadphaseInterface.h +++ b/extern/bullet/Bullet/BroadphaseCollision/BroadphaseInterface.h @@ -18,7 +18,7 @@ subject to the following restrictions: -struct DispatcherInfo; +struct DispatcherInfo; class Dispatcher; struct BroadphaseProxy; #include "SimdVector3.h" diff --git a/extern/bullet/Bullet/BroadphaseCollision/CollisionAlgorithm.h b/extern/bullet/Bullet/BroadphaseCollision/CollisionAlgorithm.h index f4ef0717b4a..9368a16f227 100644 --- a/extern/bullet/Bullet/BroadphaseCollision/CollisionAlgorithm.h +++ b/extern/bullet/Bullet/BroadphaseCollision/CollisionAlgorithm.h @@ -57,9 +57,9 @@ public: virtual ~CollisionAlgorithm() {}; - virtual void ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount, bool useContinuous) = 0; + virtual void ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const struct DispatcherInfo& dispatchInfo) = 0; - virtual float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount) = 0; + virtual float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const struct DispatcherInfo& dispatchInfo) = 0; }; diff --git a/extern/bullet/Bullet/BroadphaseCollision/Dispatcher.h b/extern/bullet/Bullet/BroadphaseCollision/Dispatcher.h index 6e02556d562..ed556c2e60a 100644 --- a/extern/bullet/Bullet/BroadphaseCollision/Dispatcher.h +++ b/extern/bullet/Bullet/BroadphaseCollision/Dispatcher.h @@ -40,7 +40,8 @@ struct DispatcherInfo DispatcherInfo() :m_dispatchFunc(DISPATCH_DISCRETE), m_timeOfImpact(1.f), - m_useContinuous(false) + m_useContinuous(false), + m_debugDraw(0) { } @@ -49,6 +50,7 @@ struct DispatcherInfo int m_dispatchFunc; float m_timeOfImpact; bool m_useContinuous; + class IDebugDraw* m_debugDraw; }; diff --git a/extern/bullet/Bullet/BroadphaseCollision/SimpleBroadphase.cpp b/extern/bullet/Bullet/BroadphaseCollision/SimpleBroadphase.cpp index 4b3d0c0745a..c415b7b997d 100644 --- a/extern/bullet/Bullet/BroadphaseCollision/SimpleBroadphase.cpp +++ b/extern/bullet/Bullet/BroadphaseCollision/SimpleBroadphase.cpp @@ -292,10 +292,10 @@ void SimpleBroadphase::DispatchAllCollisionPairs(Dispatcher& dispatcher,Dispatch { if (dispatchInfo.m_dispatchFunc == DispatcherInfo::DISPATCH_DISCRETE) { - pair.m_algorithms[dispatcherId]->ProcessCollision(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo.m_timeStep,dispatchInfo.m_stepCount,dispatchInfo.m_useContinuous); + pair.m_algorithms[dispatcherId]->ProcessCollision(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo); } else { - float toi = pair.m_algorithms[dispatcherId]->CalculateTimeOfImpact(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo.m_timeStep,dispatchInfo.m_stepCount); + float toi = pair.m_algorithms[dispatcherId]->CalculateTimeOfImpact(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo); if (dispatchInfo.m_timeOfImpact > toi) dispatchInfo.m_timeOfImpact = toi; @@ -312,10 +312,10 @@ void SimpleBroadphase::DispatchAllCollisionPairs(Dispatcher& dispatcher,Dispatch { if (dispatchInfo.m_dispatchFunc == DispatcherInfo::DISPATCH_DISCRETE) { - algo->ProcessCollision(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo.m_timeStep,dispatchInfo.m_stepCount,dispatchInfo.m_useContinuous); + algo->ProcessCollision(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo); } else { - float toi = algo->CalculateTimeOfImpact(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo.m_timeStep,dispatchInfo.m_stepCount); + float toi = algo->CalculateTimeOfImpact(pair.m_pProxy0,pair.m_pProxy1,dispatchInfo); if (dispatchInfo.m_timeOfImpact > toi) dispatchInfo.m_timeOfImpact = toi; } diff --git a/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cpp b/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cpp index bb0bf7abbbd..d600c061638 100644 --- a/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cpp +++ b/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cpp @@ -29,6 +29,7 @@ subject to the following restrictions: ConvexConcaveCollisionAlgorithm::ConvexConcaveCollisionAlgorithm( const CollisionAlgorithmConstructionInfo& ci,BroadphaseProxy* proxy0,BroadphaseProxy* proxy1) : CollisionAlgorithm(ci),m_convex(*proxy0),m_concave(*proxy1), m_boxTriangleCallback(ci.m_dispatcher,proxy0,proxy1) + { } @@ -40,9 +41,7 @@ ConvexConcaveCollisionAlgorithm::~ConvexConcaveCollisionAlgorithm() BoxTriangleCallback::BoxTriangleCallback(Dispatcher* dispatcher,BroadphaseProxy* proxy0,BroadphaseProxy* proxy1): m_boxProxy(proxy0),m_triangleProxy(*proxy1),m_dispatcher(dispatcher), - m_timeStep(0.f), - m_stepCount(-1), - m_triangleCount(0) + m_dispatchInfoPtr(0) { // @@ -96,7 +95,7 @@ void BoxTriangleCallback::ProcessTriangle(SimdVector3* triangle) ob->m_collisionShape = &tm; ConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_boxProxy,&m_triangleProxy); - cvxcvxalgo.ProcessCollision(m_boxProxy,&m_triangleProxy,m_timeStep,m_stepCount,m_useContinuous); + cvxcvxalgo.ProcessCollision(m_boxProxy,&m_triangleProxy,*m_dispatchInfoPtr); ob->m_collisionShape = tmpShape; } @@ -107,12 +106,9 @@ void BoxTriangleCallback::ProcessTriangle(SimdVector3* triangle) -void BoxTriangleCallback::SetTimeStepAndCounters(float timeStep,int stepCount,float collisionMarginTriangle,bool useContinuous) +void BoxTriangleCallback::SetTimeStepAndCounters(float collisionMarginTriangle,const DispatcherInfo& dispatchInfo) { - m_triangleCount = 0; - m_timeStep = timeStep; - m_stepCount = stepCount; - m_useContinuous = useContinuous; + m_dispatchInfoPtr = &dispatchInfo; m_collisionMarginTriangle = collisionMarginTriangle; //recalc aabbs @@ -142,7 +138,7 @@ void ConvexConcaveCollisionAlgorithm::ClearCache() } -void ConvexConcaveCollisionAlgorithm::ProcessCollision (BroadphaseProxy* ,BroadphaseProxy* ,float timeStep,int stepCount,bool useContinuous) +void ConvexConcaveCollisionAlgorithm::ProcessCollision (BroadphaseProxy* ,BroadphaseProxy* ,const DispatcherInfo& dispatchInfo) { CollisionObject* boxBody = static_cast<CollisionObject* >(m_convex.m_clientObject); @@ -163,7 +159,7 @@ void ConvexConcaveCollisionAlgorithm::ProcessCollision (BroadphaseProxy* ,Broadp { float collisionMarginTriangle = triangleMesh->GetMargin(); - m_boxTriangleCallback.SetTimeStepAndCounters(timeStep,stepCount, collisionMarginTriangle,useContinuous); + m_boxTriangleCallback.SetTimeStepAndCounters(collisionMarginTriangle,dispatchInfo); #ifdef USE_BOX_TRIANGLE m_boxTriangleCallback.m_manifoldPtr->ClearManifold(); #endif @@ -179,7 +175,7 @@ void ConvexConcaveCollisionAlgorithm::ProcessCollision (BroadphaseProxy* ,Broadp } -float ConvexConcaveCollisionAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* ,BroadphaseProxy* ,float timeStep,int stepCount) +float ConvexConcaveCollisionAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* ,BroadphaseProxy* ,const DispatcherInfo& dispatchInfo) { //quick approximation using raycast, todo: use proper continuou collision detection diff --git a/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.h b/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.h index 00a03f64f8d..7569f4ed32e 100644 --- a/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.h +++ b/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.h @@ -35,9 +35,7 @@ class BoxTriangleCallback : public TriangleCallback SimdVector3 m_aabbMax ; Dispatcher* m_dispatcher; - float m_timeStep; - int m_stepCount; - bool m_useContinuous; + const DispatcherInfo* m_dispatchInfoPtr; float m_collisionMarginTriangle; public: @@ -47,7 +45,7 @@ int m_triangleCount; BoxTriangleCallback(Dispatcher* dispatcher,BroadphaseProxy* proxy0,BroadphaseProxy* proxy1); - void SetTimeStepAndCounters(float timeStep,int stepCount, float collisionMarginTriangle,bool useContinuous); + void SetTimeStepAndCounters(float collisionMarginTriangle,const DispatcherInfo& dispatchInfo); virtual ~BoxTriangleCallback(); @@ -86,9 +84,9 @@ public: virtual ~ConvexConcaveCollisionAlgorithm(); - virtual void ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount, bool useContinuous); + virtual void ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo); - float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount); + float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo); void ClearCache(); diff --git a/extern/bullet/Bullet/CollisionDispatch/ConvexConvexAlgorithm.cpp b/extern/bullet/Bullet/CollisionDispatch/ConvexConvexAlgorithm.cpp index e9c56189bfc..8ec124e3dc6 100644 --- a/extern/bullet/Bullet/CollisionDispatch/ConvexConvexAlgorithm.cpp +++ b/extern/bullet/Bullet/CollisionDispatch/ConvexConvexAlgorithm.cpp @@ -167,8 +167,9 @@ void ConvexConvexAlgorithm::CheckPenetrationDepthSolver() // // box-box collision algorithm, for simplicity also applies resolution-impulse // -void ConvexConvexAlgorithm ::ProcessCollision (BroadphaseProxy* ,BroadphaseProxy* ,float timeStep,int stepCount, bool useContinuous) +void ConvexConvexAlgorithm ::ProcessCollision (BroadphaseProxy* ,BroadphaseProxy* ,const DispatcherInfo& dispatchInfo) { + if (!m_manifoldPtr) return; @@ -194,7 +195,7 @@ void ConvexConvexAlgorithm ::ProcessCollision (BroadphaseProxy* ,BroadphaseProxy MinkowskiSumShape expanded0(min0,&sphere); MinkowskiSumShape expanded1(min1,&sphere); - if (useContinuous) + if (dispatchInfo.m_useContinuous) { m_gjkPairDetector.SetMinkowskiA(&expanded0); m_gjkPairDetector.SetMinkowskiB(&expanded1); @@ -214,12 +215,12 @@ void ConvexConvexAlgorithm ::ProcessCollision (BroadphaseProxy* ,BroadphaseProxy input.m_transformA = col0->m_worldTransform; input.m_transformB = col1->m_worldTransform; - m_gjkPairDetector.GetClosestPoints(input,*resultOut); + m_gjkPairDetector.GetClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); m_dispatcher->ReleaseManifoldResult(resultOut); } bool disableCcd = false; -float ConvexConvexAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount) +float ConvexConvexAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo) { CheckPenetrationDepthSolver(); diff --git a/extern/bullet/Bullet/CollisionDispatch/ConvexConvexAlgorithm.h b/extern/bullet/Bullet/CollisionDispatch/ConvexConvexAlgorithm.h index 15e0f3a2141..6d8143df552 100644 --- a/extern/bullet/Bullet/CollisionDispatch/ConvexConvexAlgorithm.h +++ b/extern/bullet/Bullet/CollisionDispatch/ConvexConvexAlgorithm.h @@ -49,9 +49,9 @@ public: virtual ~ConvexConvexAlgorithm(); - virtual void ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount, bool useContinuous); + virtual void ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo); - virtual float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount); + virtual float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo); void SetLowLevelOfDetail(bool useLowLevel); diff --git a/extern/bullet/Bullet/CollisionDispatch/EmptyCollisionAlgorithm.cpp b/extern/bullet/Bullet/CollisionDispatch/EmptyCollisionAlgorithm.cpp index ff4824dadca..6ef31ad6fb4 100644 --- a/extern/bullet/Bullet/CollisionDispatch/EmptyCollisionAlgorithm.cpp +++ b/extern/bullet/Bullet/CollisionDispatch/EmptyCollisionAlgorithm.cpp @@ -22,12 +22,12 @@ EmptyAlgorithm::EmptyAlgorithm(const CollisionAlgorithmConstructionInfo& ci) { } -void EmptyAlgorithm::ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep, int stepCount,bool useContinuous) +void EmptyAlgorithm::ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo) { } -float EmptyAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount) +float EmptyAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo) { return 1.f; } diff --git a/extern/bullet/Bullet/CollisionDispatch/EmptyCollisionAlgorithm.h b/extern/bullet/Bullet/CollisionDispatch/EmptyCollisionAlgorithm.h index 598fb27b883..c85efac9959 100644 --- a/extern/bullet/Bullet/CollisionDispatch/EmptyCollisionAlgorithm.h +++ b/extern/bullet/Bullet/CollisionDispatch/EmptyCollisionAlgorithm.h @@ -28,9 +28,9 @@ public: EmptyAlgorithm(const CollisionAlgorithmConstructionInfo& ci); - virtual void ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep, int stepCount, bool useContinuous); + virtual void ProcessCollision (BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo); - virtual float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,float timeStep,int stepCount); + virtual float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo); diff --git a/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.cpp b/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.cpp index 35cad78fbb9..71a74f65bc2 100644 --- a/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.cpp +++ b/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.cpp @@ -74,7 +74,7 @@ void ConvexTriangleCallback::ProcessTriangle(SimdVector3* triangle) input.m_maximumDistanceSquared = 1e30f;//? - gjkDetector.GetClosestPoints(input,output); + gjkDetector.GetClosestPoints(input,output,0); } diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/ContinuousConvexCollision.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/ContinuousConvexCollision.cpp index d760b368fe3..f5762ee248c 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/ContinuousConvexCollision.cpp +++ b/extern/bullet/Bullet/NarrowPhaseCollision/ContinuousConvexCollision.cpp @@ -93,7 +93,7 @@ bool ContinuousConvexCollision::calcTimeOfImpact( GjkPairDetector::ClosestPointInput input; input.m_transformA = fromA; input.m_transformB = fromB; - gjk.GetClosestPoints(input,pointCollector1); + gjk.GetClosestPoints(input,pointCollector1,0); hasResult = pointCollector1.m_hasResult; c = pointCollector1.m_pointInWorld; @@ -152,7 +152,7 @@ bool ContinuousConvexCollision::calcTimeOfImpact( GjkPairDetector::ClosestPointInput input; input.m_transformA = interpolatedTransA; input.m_transformB = interpolatedTransB; - gjk.GetClosestPoints(input,pointCollector); + gjk.GetClosestPoints(input,pointCollector,0); if (pointCollector.m_hasResult) { if (pointCollector.m_distance < 0.f) diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/ConvexPenetrationDepthSolver.h b/extern/bullet/Bullet/NarrowPhaseCollision/ConvexPenetrationDepthSolver.h index 8001c7883b6..7b1d8426bc0 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/ConvexPenetrationDepthSolver.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/ConvexPenetrationDepthSolver.h @@ -31,7 +31,9 @@ public: virtual bool CalcPenDepth( SimplexSolverInterface& simplexSolver, ConvexShape* convexA,ConvexShape* convexB, const SimdTransform& transA,const SimdTransform& transB, - SimdVector3& v, SimdPoint3& pa, SimdPoint3& pb) = 0; + SimdVector3& v, SimdPoint3& pa, SimdPoint3& pb, + class IDebugDraw* debugDraw + ) = 0; }; diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/DiscreteCollisionDetectorInterface.h b/extern/bullet/Bullet/NarrowPhaseCollision/DiscreteCollisionDetectorInterface.h index 08007d75496..400ac805bc3 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/DiscreteCollisionDetectorInterface.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/DiscreteCollisionDetectorInterface.h @@ -54,7 +54,7 @@ struct DiscreteCollisionDetectorInterface // give either closest points (distance > 0) or penetration (distance) // the normal always points from B towards A // - virtual void GetClosestPoints(const ClosestPointInput& input,Result& output) = 0; + virtual void GetClosestPoints(const ClosestPointInput& input,Result& output,class IDebugDraw* debugDraw) = 0; SimdScalar getCollisionMargin() { return 0.2f;} }; diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.cpp index 0f20061c6e6..344a4555bcf 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.cpp +++ b/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.cpp @@ -96,7 +96,7 @@ bool GjkConvexCast::calcTimeOfImpact( GjkPairDetector::ClosestPointInput input; input.m_transformA = sphereTr; input.m_transformB = identityTrans; - gjk.GetClosestPoints(input,pointCollector1); + gjk.GetClosestPoints(input,pointCollector1,0); hasResult = pointCollector1.m_hasResult; c = pointCollector1.m_pointInWorld; @@ -133,7 +133,7 @@ bool GjkConvexCast::calcTimeOfImpact( GjkPairDetector::ClosestPointInput input; input.m_transformA = sphereTr; input.m_transformB = identityTrans; - gjk.GetClosestPoints(input,pointCollector); + gjk.GetClosestPoints(input,pointCollector,0); if (pointCollector.m_hasResult) { if (pointCollector.m_distance < 0.f) diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.cpp index c453264662f..8ccffc0d86d 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.cpp +++ b/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.cpp @@ -33,7 +33,7 @@ m_minkowskiB(objectB) { } -void GjkPairDetector::GetClosestPoints(const ClosestPointInput& input,Result& output) +void GjkPairDetector::GetClosestPoints(const ClosestPointInput& input,Result& output,class IDebugDraw* debugDraw) { SimdScalar distance; SimdVector3 normalInB(0.f,0.f,0.f); @@ -155,7 +155,9 @@ void GjkPairDetector::GetClosestPoints(const ClosestPointInput& input,Result& ou *m_simplexSolver, m_minkowskiA,m_minkowskiB, input.m_transformA,input.m_transformB, - m_cachedSeparatingAxis, pointOnA, pointOnB); + m_cachedSeparatingAxis, pointOnA, pointOnB, + debugDraw + ); if (isValid) { @@ -180,6 +182,7 @@ void GjkPairDetector::GetClosestPoints(const ClosestPointInput& input,Result& ou normalInB, pointOnB, distance); + //printf("gjk add:%f",distance); } diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.h b/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.h index 337f8128071..e18fd20697c 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.h @@ -44,7 +44,7 @@ public: GjkPairDetector(ConvexShape* objectA,ConvexShape* objectB,SimplexSolverInterface* simplexSolver,ConvexPenetrationDepthSolver* penetrationDepthSolver); virtual ~GjkPairDetector() {}; - virtual void GetClosestPoints(const ClosestPointInput& input,Result& output); + virtual void GetClosestPoints(const ClosestPointInput& input,Result& output,class IDebugDraw* debugDraw); void SetMinkowskiA(ConvexShape* minkA) { diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cpp index d4fbf022d6c..d482be27659 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cpp +++ b/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cpp @@ -41,113 +41,147 @@ struct MyResult : public DiscreteCollisionDetectorInterface::Result } }; +#define NUM_UNITSPHERE_POINTS 42 +static SimdVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS] = +{ +SimdVector3(0.000000f , -0.000000f,-1.000000f), +SimdVector3(0.723608f , -0.525725f,-0.447219f), +SimdVector3(-0.276388f , -0.850649f,-0.447219f), +SimdVector3(-0.894426f , -0.000000f,-0.447216f), +SimdVector3(-0.276388f , 0.850649f,-0.447220f), +SimdVector3(0.723608f , 0.525725f,-0.447219f), +SimdVector3(0.276388f , -0.850649f,0.447220f), +SimdVector3(-0.723608f , -0.525725f,0.447219f), +SimdVector3(-0.723608f , 0.525725f,0.447219f), +SimdVector3(0.276388f , 0.850649f,0.447219f), +SimdVector3(0.894426f , 0.000000f,0.447216f), +SimdVector3(-0.000000f , 0.000000f,1.000000f), +SimdVector3(0.425323f , -0.309011f,-0.850654f), +SimdVector3(-0.162456f , -0.499995f,-0.850654f), +SimdVector3(0.262869f , -0.809012f,-0.525738f), +SimdVector3(0.425323f , 0.309011f,-0.850654f), +SimdVector3(0.850648f , -0.000000f,-0.525736f), +SimdVector3(-0.525730f , -0.000000f,-0.850652f), +SimdVector3(-0.688190f , -0.499997f,-0.525736f), +SimdVector3(-0.162456f , 0.499995f,-0.850654f), +SimdVector3(-0.688190f , 0.499997f,-0.525736f), +SimdVector3(0.262869f , 0.809012f,-0.525738f), +SimdVector3(0.951058f , 0.309013f,0.000000f), +SimdVector3(0.951058f , -0.309013f,0.000000f), +SimdVector3(0.587786f , -0.809017f,0.000000f), +SimdVector3(0.000000f , -1.000000f,0.000000f), +SimdVector3(-0.587786f , -0.809017f,0.000000f), +SimdVector3(-0.951058f , -0.309013f,-0.000000f), +SimdVector3(-0.951058f , 0.309013f,-0.000000f), +SimdVector3(-0.587786f , 0.809017f,-0.000000f), +SimdVector3(-0.000000f , 1.000000f,-0.000000f), +SimdVector3(0.587786f , 0.809017f,-0.000000f), +SimdVector3(0.688190f , -0.499997f,0.525736f), +SimdVector3(-0.262869f , -0.809012f,0.525738f), +SimdVector3(-0.850648f , 0.000000f,0.525736f), +SimdVector3(-0.262869f , 0.809012f,0.525738f), +SimdVector3(0.688190f , 0.499997f,0.525736f), +SimdVector3(0.525730f , 0.000000f,0.850652f), +SimdVector3(0.162456f , -0.499995f,0.850654f), +SimdVector3(-0.425323f , -0.309011f,0.850654f), +SimdVector3(-0.425323f , 0.309011f,0.850654f), +SimdVector3(0.162456f , 0.499995f,0.850654f) +}; bool MinkowskiPenetrationDepthSolver::CalcPenDepth(SimplexSolverInterface& simplexSolver, ConvexShape* convexA,ConvexShape* convexB, const SimdTransform& transA,const SimdTransform& transB, - SimdVector3& v, SimdPoint3& pa, SimdPoint3& pb) + SimdVector3& v, SimdPoint3& pa, SimdPoint3& pb, + class IDebugDraw* debugDraw + ) { //just take fixed number of orientation, and sample the penetration depth in that direction - - int N = 3; float minProj = 1e30f; SimdVector3 minNorm; SimdVector3 minVertex; SimdVector3 minA,minB; - - //not so good, lots of directions overlap, better to use gauss map - for (int i=-N;i<N;i++) + for (int i=0;i<NUM_UNITSPHERE_POINTS;i++) { - for (int j = -N;j<N;j++) + const SimdVector3& norm = sPenetrationDirections[i]; + + SimdVector3 seperatingAxisInA = (-norm)* transA.getBasis(); + SimdVector3 seperatingAxisInB = norm* transB.getBasis(); + + SimdVector3 pInA = convexA->LocalGetSupportingVertex(seperatingAxisInA); + SimdVector3 qInB = convexB->LocalGetSupportingVertex(seperatingAxisInB); + SimdPoint3 pWorld = transA(pInA); + SimdPoint3 qWorld = transB(qInB); + + SimdVector3 w = qWorld - pWorld; + float delta = norm.dot(w); + //find smallest delta + + if (delta < minProj) { - for (int k=-N;k<N;k++) - { - if (i | j | k) - { - SimdVector3 norm(i,j,k); - norm.normalize(); - - { - SimdVector3 seperatingAxisInA = (-norm)* transA.getBasis(); - SimdVector3 seperatingAxisInB = norm* transB.getBasis(); - - SimdVector3 pInA = convexA->LocalGetSupportingVertex(seperatingAxisInA); - SimdVector3 qInB = convexB->LocalGetSupportingVertex(seperatingAxisInB); - SimdPoint3 pWorld = transA(pInA); - SimdPoint3 qWorld = transB(qInB); - - SimdVector3 w = qWorld - pWorld; - float delta = norm.dot(w); - //find smallest delta - - if (delta < minProj) - { - minProj = delta; - minNorm = norm; - minA = pWorld; - minB = qWorld; - } - } - - { - SimdVector3 seperatingAxisInA = (norm)* transA.getBasis(); - SimdVector3 seperatingAxisInB = -norm* transB.getBasis(); - - SimdVector3 pInA = convexA->LocalGetSupportingVertex(seperatingAxisInA); - SimdVector3 qInB = convexB->LocalGetSupportingVertex(seperatingAxisInB); - SimdPoint3 pWorld = transA(pInA); - SimdPoint3 qWorld = transB(qInB); - - SimdVector3 w = qWorld - pWorld; - float delta = (-norm).dot(w); - //find smallest delta - - if (delta < minProj) - { - minProj = delta ; - minNorm = -norm; - minA = pWorld; - minB = qWorld; - } - } - - - - } - } + minProj = delta; + minNorm = norm; + minA = pWorld; + minB = qWorld; + } } - SimdTransform ident; - ident.setIdentity(); +#ifdef DEBUG_DRAW + if (debugDraw) + { + SimdVector3 color(0,1,0); + debugDraw->DrawLine(minA,minB,color); + color = SimdVector3 (1,1,1); + SimdVector3 vec = minB-minA; + float prj2 = minNorm.dot(vec); + debugDraw->DrawLine(minA,minA+(minNorm*minProj),color); - GjkPairDetector gjkdet(convexA,convexB,&simplexSolver,0); + } +#endif //DEBUG_DRAW + - v = minNorm * minProj; + GjkPairDetector gjkdet(convexA,convexB,&simplexSolver,0); + + SimdScalar offsetDist = (minProj+0.1f); + SimdVector3 offset = minNorm * offsetDist; + GjkPairDetector::ClosestPointInput input; - SimdVector3 newOrg = transA.getOrigin() + v + v; + SimdVector3 newOrg = transA.getOrigin() + offset; SimdTransform displacedTrans = transA; displacedTrans.setOrigin(newOrg); input.m_transformA = displacedTrans; input.m_transformB = transB; - input.m_maximumDistanceSquared = 1e30f; + input.m_maximumDistanceSquared = 1e30f;//minProj; MyResult res; - gjkdet.GetClosestPoints(input,res); + gjkdet.GetClosestPoints(input,res,debugDraw); + + if (res.m_hasResult) { - pa = res.m_pointInWorld - res.m_normalOnBInWorld*0.1f*res.m_depth; + + pa = res.m_pointInWorld - minNorm * minProj; pb = res.m_pointInWorld; + +#ifdef DEBUG_DRAW + if (debugDraw) + { + SimdVector3 color(1,0,0); + debugDraw->DrawLine(pa,pb,color); + } +#endif//DEBUG_DRAW + + } return res.m_hasResult; } diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.h b/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.h index 65154c59b4e..b7a0da3a024 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.h @@ -27,7 +27,9 @@ public: virtual bool CalcPenDepth( SimplexSolverInterface& simplexSolver, ConvexShape* convexA,ConvexShape* convexB, const SimdTransform& transA,const SimdTransform& transB, - SimdVector3& v, SimdPoint3& pa, SimdPoint3& pb); + SimdVector3& v, SimdPoint3& pa, SimdPoint3& pb, + class IDebugDraw* debugDraw + ); }; diff --git a/extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp b/extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp index d78a812edf2..38c82fdb07d 100644 --- a/extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp +++ b/extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp @@ -102,7 +102,7 @@ void resolveSingleBilateral(RigidBody& body1, const SimdVector3& pos1, #endif } - +float allowedPenetration = 0.0f; //velocity + friction @@ -115,9 +115,26 @@ float resolveSingleCollision( ) { + const SimdVector3& pos1 = contactPoint.GetPositionWorldOnA(); const SimdVector3& pos2 = contactPoint.GetPositionWorldOnB(); SimdScalar distance = contactPoint.GetDistance(); + + +// printf("distance=%f\n",distance); + + if (distance>0.f) + { + contactPoint.m_appliedImpulse = 0.f; + contactPoint.m_accumulatedTangentImpulse0 = 0.f; + contactPoint.m_accumulatedTangentImpulse1 = 0.f; + + return 0.f; + } + +#define MAXPENETRATIONPERFRAME -0.05 + distance = distance < MAXPENETRATIONPERFRAME? MAXPENETRATIONPERFRAME:distance; + const SimdVector3& normal = contactPoint.m_normalWorldOnB; SimdVector3 rel_pos1 = pos1 - body1.getCenterOfMassPosition(); @@ -146,14 +163,14 @@ float resolveSingleCollision( float Kcor = Kerp *Kfps; - float allowedPenetration = 0.001f; + //printf("dist=%f\n",distance); float clipDist = distance + allowedPenetration; float dist = (clipDist > 0.f) ? 0.f : clipDist; - - SimdScalar positionalError = Kcor *-dist*damping; + //distance = 0.f; + SimdScalar positionalError = Kcor *-clipDist; //jacDiagABInv; - SimdScalar velocityError = -(1.0f + restitution) * rel_vel; + SimdScalar velocityError = -(1.0f + restitution) * rel_vel;// * damping; SimdScalar penetrationImpulse = positionalError * contactPoint.m_jacDiagABInv; diff --git a/extern/bullet/BulletDynamics/ConstraintSolver/SimpleConstraintSolver.cpp b/extern/bullet/BulletDynamics/ConstraintSolver/SimpleConstraintSolver.cpp index 658554a5d94..7fd42d04775 100644 --- a/extern/bullet/BulletDynamics/ConstraintSolver/SimpleConstraintSolver.cpp +++ b/extern/bullet/BulletDynamics/ConstraintSolver/SimpleConstraintSolver.cpp @@ -122,9 +122,10 @@ float SimpleConstraintSolver::Solve(PersistentManifold* manifoldPtr, const Conta //re-calculate friction direction every frame, todo: check if this is really needed SimdPlaneSpace1(cp.m_normalWorldOnB,cp.m_frictionWorldTangential0,cp.m_frictionWorldTangential1); +#ifdef NO_FRICTION_WARMSTART cp.m_accumulatedTangentImpulse0 = 0.f; cp.m_accumulatedTangentImpulse1 = 0.f; - +#endif //NO_FRICTION_WARMSTART float denom0 = body0->ComputeImpulseDenominator(pos1,cp.m_frictionWorldTangential0); float denom1 = body1->ComputeImpulseDenominator(pos2,cp.m_frictionWorldTangential0); float denom = relaxation/(denom0+denom1); @@ -137,8 +138,10 @@ float SimpleConstraintSolver::Solve(PersistentManifold* manifoldPtr, const Conta cp.m_jacDiagABInvTangent1 = denom; SimdVector3 totalImpulse = - // cp.m_frictionWorldTangential0*cp.m_accumulatedTangentImpulse0+ - // cp.m_frictionWorldTangential1*cp.m_accumulatedTangentImpulse1+ +#ifndef NO_FRICTION_WARMSTART + cp.m_frictionWorldTangential0*cp.m_accumulatedTangentImpulse0+ + cp.m_frictionWorldTangential1*cp.m_accumulatedTangentImpulse1+ +#endif //NO_FRICTION_WARMSTART cp.m_normalWorldOnB*cp.m_appliedImpulse; //apply previous frames impulse on both bodies @@ -173,12 +176,8 @@ float SimpleConstraintSolver::Solve(PersistentManifold* manifoldPtr, const Conta { - //float actualDist = cp.GetDistance(); - //#define MAXPENETRATIONPERFRAME -0.2f - //float dist = actualDist< MAXPENETRATIONPERFRAME? MAXPENETRATIONPERFRAME:actualDist; - - float dist = cp.GetDistance(); - + //float dist = cp.GetDistance(); + //printf("dist(%i)=%f\n",j,dist); float impulse = resolveSingleCollision( *body0,*body1, cp, diff --git a/extern/bullet/BulletDynamics/Dynamics/RigidBody.cpp b/extern/bullet/BulletDynamics/Dynamics/RigidBody.cpp index db90a833633..315a9d66c38 100644 --- a/extern/bullet/BulletDynamics/Dynamics/RigidBody.cpp +++ b/extern/bullet/BulletDynamics/Dynamics/RigidBody.cpp @@ -97,7 +97,7 @@ void RigidBody::applyForces(SimdScalar step) m_linearVelocity *= GEN_clamped((1.f - step * gLinearAirDamping * m_linearDamping), 0.0f, 1.0f); m_angularVelocity *= GEN_clamped((1.f - step * m_angularDamping), 0.0f, 1.0f); -//#define FORCE_VELOCITY_DAMPING 1 +#define FORCE_VELOCITY_DAMPING 1 #ifdef FORCE_VELOCITY_DAMPING float speed = m_linearVelocity.length(); if (speed < m_linearDamping) diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp index 98387076892..3039bba8565 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp @@ -315,7 +315,8 @@ m_solverType(-1) //broadphase = new SimpleBroadphase(); } - setSolverType(0); + + setSolverType(1); m_collisionWorld = new CollisionWorld(dispatcher,broadphase); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 85fdc51826a..3b1e4f7ce59 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1091,6 +1091,7 @@ PyObject* KX_GameObject::PySetPosition(PyObject* self, if (PyVecArgTo(args, pos)) { NodeSetLocalPosition(pos); + NodeUpdateGS(0.f,true); Py_Return; } diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index d9517a3a65b..322f41e11a3 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -85,28 +85,16 @@ bool KX_SCA_AddObjectActuator::Update() RemoveAllEvents(); if (bNegativeEvent) return false; // do nothing on negative events - if (m_OriginalObject) - { - // Add an identical object, with properties inherited from the original object - // Now it needs to be added to the current scene. - SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp ); - KX_GameObject * game_obj = static_cast<KX_GameObject *>(replica); - game_obj->setLinearVelocity(m_linear_velocity,m_localFlag); - game_obj->ResolveCombinedVelocities(m_linear_velocity, MT_Vector3(0., 0., 0.), m_localFlag, false); - // keep a copy of the last object, to allow python scripters to change it - if (m_lastCreatedObject) - m_lastCreatedObject->Release(); - - m_lastCreatedObject = replica; - m_lastCreatedObject->AddRef(); - } + InstantAddObject(); + return false; } + SCA_IObject* KX_SCA_AddObjectActuator::GetLastCreatedObject() const { return m_lastCreatedObject; @@ -169,6 +157,8 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { {"getLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLinearVelocity, METH_VARARGS, GetLinearVelocity_doc}, {"setLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetLinearVelocity, METH_VARARGS, SetLinearVelocity_doc}, {"getLastCreatedObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLastCreatedObject, METH_VARARGS,"getLastCreatedObject() : get the object handle to the last created object\n"}, + {"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_VARARGS,"instantAddObject() : immediately add object without delay\n"}, + {NULL,NULL} //Sentinel }; @@ -315,6 +305,35 @@ PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self, Py_Return; } +void KX_SCA_AddObjectActuator::InstantAddObject() +{ + if (m_OriginalObject) + { + // Add an identical object, with properties inherited from the original object + // Now it needs to be added to the current scene. + SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp ); + KX_GameObject * game_obj = static_cast<KX_GameObject *>(replica); + game_obj->setLinearVelocity(m_linear_velocity,m_localFlag); + game_obj->ResolveCombinedVelocities(m_linear_velocity, MT_Vector3(0., 0., 0.), m_localFlag, false); + + // keep a copy of the last object, to allow python scripters to change it + if (m_lastCreatedObject) + m_lastCreatedObject->Release(); + + m_lastCreatedObject = replica; + m_lastCreatedObject->AddRef(); + } +} + +PyObject* KX_SCA_AddObjectActuator::PyInstantAddObject(PyObject* self, + PyObject* args, + PyObject* kwds) +{ + InstantAddObject(); + + Py_Return; +} + /* 7. GetLastCreatedObject */ diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h index 2a7c27669fa..60adcb27b12 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h @@ -104,6 +104,8 @@ public: GetLastCreatedObject( ) const ; + void InstantAddObject(); + /* 1. setObject */ KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,SetObject); /* 2. setTime */ @@ -118,6 +120,8 @@ public: KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,SetLinearVelocity); /* 7. getLastCreatedObject */ KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,GetLastCreatedObject); + /* 8. instantAddObject*/ + KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,InstantAddObject); }; /* end of class KX_SCA_AddObjectActuator : public KX_EditObjectActuator */ diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 98387076892..2c4f98c5624 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -315,7 +315,7 @@ m_solverType(-1) //broadphase = new SimpleBroadphase(); } - setSolverType(0); + setSolverType(1); m_collisionWorld = new CollisionWorld(dispatcher,broadphase); @@ -524,6 +524,7 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep) DispatcherInfo dispatchInfo; dispatchInfo.m_timeStep = timeStep; dispatchInfo.m_stepCount = 0; + dispatchInfo.m_debugDraw = m_debugDrawer; scene->DispatchAllCollisionPairs(*GetDispatcher(),dispatchInfo);///numsubstep,g); @@ -882,7 +883,7 @@ void CcdPhysicsEnvironment::setSolverType(int solverType) { m_solver = new SimpleConstraintSolver(); - + //printf("Iterative Impulse ConstraintSolver\n"); break; } } @@ -892,6 +893,7 @@ void CcdPhysicsEnvironment::setSolverType(int solverType) if (m_solverType != solverType) { m_solver = new OdeConstraintSolver(); + //printf("Quickstep ConstraintSolver\n"); break; } |