more Bullet physics improvements, mainly stability and performance related.

AddObjectActuator has new python method to immediately create objects (this allows to create multiple objects in 1 frame in different positions)
This commit is contained in:
Erwin Coumans 2006-04-01 03:30:15 +00:00
parent 63bc0b3847
commit 36fd42ac85
27 changed files with 231 additions and 150 deletions

@ -18,7 +18,7 @@ subject to the following restrictions:
struct DispatcherInfo;
struct DispatcherInfo;
class Dispatcher;
struct BroadphaseProxy;
#include "SimdVector3.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;
};

@ -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;
};

@ -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;
}

@ -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

@ -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();

@ -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();

@ -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);

@ -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;
}

@ -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);

@ -74,7 +74,7 @@ void ConvexTriangleCallback::ProcessTriangle(SimdVector3* triangle)
input.m_maximumDistanceSquared = 1e30f;//?
gjkDetector.GetClosestPoints(input,output);
gjkDetector.GetClosestPoints(input,output,0);
}

@ -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)

@ -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;
};

@ -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;}
};

@ -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)

@ -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);
}

@ -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)
{

@ -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);
}
#endif //DEBUG_DRAW
GjkPairDetector gjkdet(convexA,convexB,&simplexSolver,0);
v = minNorm * minProj;
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;
}

@ -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
);
};

@ -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;

@ -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,

@ -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)

@ -315,7 +315,8 @@ m_solverType(-1)
//broadphase = new SimpleBroadphase();
}
setSolverType(0);
setSolverType(1);
m_collisionWorld = new CollisionWorld(dispatcher,broadphase);

@ -1091,6 +1091,7 @@ PyObject* KX_GameObject::PySetPosition(PyObject* self,
if (PyVecArgTo(args, pos))
{
NodeSetLocalPosition(pos);
NodeUpdateGS(0.f,true);
Py_Return;
}

@ -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 */

@ -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 */

@ -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;
}