Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Coumans <blender@erwincoumans.com>2007-07-06 07:12:31 +0400
committerErwin Coumans <blender@erwincoumans.com>2007-07-06 07:12:31 +0400
commit376be529bb932f867b01466592c33899ee5ec2c8 (patch)
treee89c72da658f04ed4aa816ada6adabfb5d938b74 /extern/bullet2/src/BulletCollision
parentcff039bc58fe2ed54d4dad0828f5dede0b26a206 (diff)
synchronized to latest version of Bullet. added btConeTwistConstraint (useful for ragdolls etc)
Diffstat (limited to 'extern/bullet2/src/BulletCollision')
-rw-r--r--extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp3
-rw-r--r--extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h28
-rw-r--r--extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h2
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp2
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp6
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h28
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp62
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h16
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp12
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h4
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp298
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h34
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp2
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h6
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h14
-rw-r--r--extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp2
-rw-r--r--extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h6
17 files changed, 444 insertions, 81 deletions
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
index 4187a8f2970..60f0a41a9d7 100644
--- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
+++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
@@ -24,7 +24,8 @@ subject to the following restrictions:
int gOverlappingPairs = 0;
btOverlappingPairCache::btOverlappingPairCache():
-m_blockedForChanges(false)
+m_blockedForChanges(false),
+m_overlapFilterCallback(0)
//m_NumOverlapBroadphasePair(0)
{
}
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
index e3442212171..a81fe3264df 100644
--- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
+++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
@@ -26,13 +26,20 @@ subject to the following restrictions:
struct btOverlapCallback
{
-virtual ~btOverlapCallback()
-{
-}
+ virtual ~btOverlapCallback()
+ {}
//return true for deletion of the pair
virtual bool processOverlap(btBroadphasePair& pair) = 0;
};
+struct btOverlapFilterCallback
+{
+ virtual ~btOverlapFilterCallback()
+ {}
+ // return true when pairs need collision
+ virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const = 0;
+};
+
///btOverlappingPairCache maintains the objects with overlapping AABB
///Typically managed by the Broadphase, Axis3Sweep or btSimpleBroadphase
class btOverlappingPairCache : public btBroadphaseInterface
@@ -44,6 +51,8 @@ class btOverlappingPairCache : public btBroadphaseInterface
//during the dispatch, check that user doesn't destroy/create proxy
bool m_blockedForChanges;
+ //if set, use the callback instead of the built in filter in needBroadphaseCollision
+ btOverlapFilterCallback* m_overlapFilterCallback;
public:
btOverlappingPairCache();
@@ -67,6 +76,9 @@ class btOverlappingPairCache : public btBroadphaseInterface
inline bool needsBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const
{
+ if (m_overlapFilterCallback)
+ return m_overlapFilterCallback->needBroadphaseCollision(proxy0,proxy1);
+
bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
@@ -92,7 +104,17 @@ class btOverlappingPairCache : public btBroadphaseInterface
return m_overlappingPairArray.size();
}
+ btOverlapFilterCallback* getOverlapFilterCallback()
+ {
+ return m_overlapFilterCallback;
+ }
+
+ void setOverlapFilterCallback(btOverlapFilterCallback* callback)
+ {
+ m_overlapFilterCallback = callback;
+ }
};
#endif //OVERLAPPING_PAIR_CACHE_H
+
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
index 1f265f3dd6b..fb155e7047c 100644
--- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
+++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
@@ -41,6 +41,8 @@ struct btSimpleBroadphaseProxy : public btBroadphaseProxy
class btSimpleBroadphase : public btOverlappingPairCache
{
+protected:
+
btSimpleBroadphaseProxy* m_proxies;
int* m_freeProxies;
int m_firstFreeProxy;
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
index 198276d76df..b535fac6563 100644
--- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
@@ -273,6 +273,8 @@ bool btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionO
if ((!body0->isActive()) && (!body1->isActive()))
needsCollision = false;
+ else if (!body0->checkCollideWith(body1))
+ needsCollision = false;
return needsCollision ;
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp
index 7b6f066275d..d4c0a4e8cb3 100644
--- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp
@@ -24,11 +24,15 @@ btCollisionObject::btCollisionObject()
m_userObjectPointer(0),
m_hitFraction(btScalar(1.)),
m_ccdSweptSphereRadius(btScalar(0.)),
- m_ccdSquareMotionThreshold(btScalar(0.))
+ m_ccdSquareMotionThreshold(btScalar(0.)),
+ m_checkCollideWith(false)
{
}
+btCollisionObject::~btCollisionObject()
+{
+}
void btCollisionObject::setActivationState(int newState)
{
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h
index 93990235afe..9fb6a67c4a3 100644
--- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h
+++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h
@@ -69,15 +69,23 @@ protected:
void* m_internalOwner;
///time of impact calculation
- btScalar m_hitFraction;
+ btScalar m_hitFraction;
///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
- btScalar m_ccdSweptSphereRadius;
+ btScalar m_ccdSweptSphereRadius;
/// Don't do continuous collision detection if square motion (in one step) is less then m_ccdSquareMotionThreshold
- btScalar m_ccdSquareMotionThreshold;
+ btScalar m_ccdSquareMotionThreshold;
- char m_pad[8];
+ /// If some object should have elaborate collision filtering by sub-classes
+ bool m_checkCollideWith;
+
+ char m_pad[7];
+
+ virtual bool checkCollideWithOverride(btCollisionObject* co)
+ {
+ return true;
+ }
public:
@@ -118,6 +126,7 @@ public:
btCollisionObject();
+ virtual ~btCollisionObject();
void setCollisionShape(btCollisionShape* collisionShape)
{
@@ -159,7 +168,7 @@ public:
return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
}
- void setRestitution(btScalar rest)
+ void setRestitution(btScalar rest)
{
m_restitution = rest;
}
@@ -322,6 +331,15 @@ public:
m_userObjectPointer = userPointer;
}
+ inline bool checkCollideWith(btCollisionObject* co)
+ {
+ if (m_checkCollideWith)
+ return checkCollideWithOverride(co);
+
+ return true;
+ }
+
+
}
;
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
index 49f35c2cc90..b49036a5b50 100644
--- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
@@ -17,6 +17,8 @@ subject to the following restrictions:
#include "btCollisionDispatcher.h"
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
+#include "BulletCollision/CollisionShapes/btConvexShape.h"
+
#include "BulletCollision/CollisionShapes/btSphereShape.h" //for raycasting
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h" //for raycasting
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
@@ -179,12 +181,27 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
btCollisionObject* collisionObject,
const btCollisionShape* collisionShape,
const btTransform& colObjWorldTransform,
- RayResultCallback& resultCallback)
+ RayResultCallback& resultCallback,short int collisionFilterMask)
{
btSphereShape pointShape(btScalar(0.0));
pointShape.setMargin(0.f);
+ objectQuerySingle(&pointShape,rayFromTrans,rayToTrans,
+ collisionObject,
+ collisionShape,
+ colObjWorldTransform,
+ resultCallback,collisionFilterMask);
+}
+
+void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const btTransform& rayFromTrans,const btTransform& rayToTrans,
+ btCollisionObject* collisionObject,
+ const btCollisionShape* collisionShape,
+ const btTransform& colObjWorldTransform,
+ RayResultCallback& resultCallback,short int collisionFilterMask)
+{
+
+
if (collisionShape->isConvex())
{
btConvexCast::CastResult castResult;
@@ -192,9 +209,9 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
btConvexShape* convexShape = (btConvexShape*) collisionShape;
btVoronoiSimplexSolver simplexSolver;
- btSubsimplexConvexCast convexCaster(&pointShape,convexShape,&simplexSolver);
- //GjkConvexCast convexCaster(&pointShape,convexShape,&simplexSolver);
- //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
+ btSubsimplexConvexCast convexCaster(castShape,convexShape,&simplexSolver);
+ //GjkConvexCast convexCaster(castShape,convexShape,&simplexSolver);
+ //ContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
{
@@ -292,11 +309,11 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
btTransform childTrans = compoundShape->getChildTransform(i);
const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
btTransform childWorldTrans = colObjWorldTransform * childTrans;
- rayTestSingle(rayFromTrans,rayToTrans,
+ objectQuerySingle(castShape, rayFromTrans,rayToTrans,
collisionObject,
childCollisionShape,
childWorldTrans,
- resultCallback);
+ resultCallback, collisionFilterMask);
}
@@ -306,7 +323,7 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
}
}
-void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback)
+void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback,short int collisionFilterMask)
{
@@ -323,21 +340,22 @@ void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& r
for (i=0;i<m_collisionObjects.size();i++)
{
btCollisionObject* collisionObject= m_collisionObjects[i];
-
- //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
- btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
- collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax);
-
- btScalar hitLambda = btScalar(1.); //could use resultCallback.m_closestHitFraction, but needs testing
- btVector3 hitNormal;
- if (btRayAabb(rayFromWorld,rayToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
- {
- rayTestSingle(rayFromTrans,rayToTrans,
- collisionObject,
- collisionObject->getCollisionShape(),
- collisionObject->getWorldTransform(),
- resultCallback);
-
+ //only perform raycast if filterMask matches
+ if(collisionObject->getBroadphaseHandle()->m_collisionFilterGroup & collisionFilterMask) {
+ //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
+ btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
+ collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax);
+
+ btScalar hitLambda = btScalar(1.); //could use resultCallback.m_closestHitFraction, but needs testing
+ btVector3 hitNormal;
+ if (btRayAabb(rayFromWorld,rayToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
+ {
+ rayTestSingle(rayFromTrans,rayToTrans,
+ collisionObject,
+ collisionObject->getCollisionShape(),
+ collisionObject->getWorldTransform(),
+ resultCallback);
+ }
}
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
index 0b0286c50f4..b6d80233ab7 100644
--- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
+++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
@@ -53,9 +53,9 @@ subject to the following restrictions:
* Bullet has been designed in a modular way keeping dependencies to a minimum. The ConvexHullDistance demo demonstrates direct use of btGjkPairDetector.
*
* @section copyright Copyright
- * Copyright (C) 2005-2006 Erwin Coumans, some contributions Copyright Gino van den Bergen, Christer Ericson, Simon Hobbs, Ricardo Padrela, F Richter(res), Stephane Redon
+ * Copyright (C) 2005-2007 Erwin Coumans, some contributions Copyright Gino van den Bergen, Christer Ericson, Simon Hobbs, Ricardo Padrela, F Richter(res), Stephane Redon
* Special thanks to all visitors of the Bullet Physics forum, and in particular above contributors, Dave Eberle, Dirk Gregorius, Erin Catto, Dave Eberle, Adam Moravanszky,
- * Pierre Terdiman, Kenny Erleben, Russell Smith, Oliver Strunk, Jan Paul van Waveren.
+ * Pierre Terdiman, Kenny Erleben, Russell Smith, Oliver Strunk, Jan Paul van Waveren, Marten Svanfeldt.
*
*/
@@ -66,6 +66,7 @@ subject to the following restrictions:
class btStackAlloc;
class btCollisionShape;
+class btConvexShape;
class btBroadphaseInterface;
#include "../../LinearMath/btVector3.h"
#include "../../LinearMath/btTransform.h"
@@ -208,7 +209,7 @@ public:
/// rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback
/// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.
- void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback);
+ void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback, short int collisionFilterMask=-1);
/// rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest.
/// In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape.
@@ -217,7 +218,14 @@ public:
btCollisionObject* collisionObject,
const btCollisionShape* collisionShape,
const btTransform& colObjWorldTransform,
- RayResultCallback& resultCallback);
+ RayResultCallback& resultCallback, short int collisionFilterMask=-1);
+
+ /// objectQuerySingle performs a collision detection query and calls the resultCallback. It is used internally by rayTest.
+ static void objectQuerySingle(const btConvexShape* castShape, const btTransform& rayFromTrans,const btTransform& rayToTrans,
+ btCollisionObject* collisionObject,
+ const btCollisionShape* collisionShape,
+ const btTransform& colObjWorldTransform,
+ RayResultCallback& resultCallback, short int collisionFilterMask=-1);
void addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=1,short int collisionFilterMask=1);
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
index 2f96c2e13c5..92f4c8b28a6 100644
--- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
@@ -77,9 +77,9 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
btTransform orgTrans = colObj->getWorldTransform();
btCollisionShape* orgShape = colObj->getCollisionShape();
- btTransform childTrans = compoundShape->getChildTransform(i);
- btTransform newChildWorldTrans = orgTrans*childTrans ;
- colObj->setWorldTransform( newChildWorldTrans );
+ const btTransform& childTrans = compoundShape->getChildTransform(i);
+ //btTransform newChildWorldTrans = orgTrans*childTrans ;
+ colObj->setWorldTransform( orgTrans*childTrans );
//the contactpoint is still projected back using the original inverted worldtrans
colObj->setCollisionShape( childShape );
m_childCollisionAlgorithms[i]->processCollision(colObj,otherObj,dispatchInfo,resultOut);
@@ -119,9 +119,9 @@ btScalar btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject*
btTransform orgTrans = colObj->getWorldTransform();
btCollisionShape* orgShape = colObj->getCollisionShape();
- btTransform childTrans = compoundShape->getChildTransform(i);
- btTransform newChildWorldTrans = orgTrans*childTrans ;
- colObj->setWorldTransform( newChildWorldTrans );
+ const btTransform& childTrans = compoundShape->getChildTransform(i);
+ //btTransform newChildWorldTrans = orgTrans*childTrans ;
+ colObj->setWorldTransform( orgTrans*childTrans );
colObj->setCollisionShape( childShape );
btScalar frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h
index 2d384bd2180..86dc1f80947 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h
@@ -58,11 +58,11 @@ public:
return m_childShapes[index];
}
- btTransform getChildTransform(int index)
+ btTransform& getChildTransform(int index)
{
return m_childTransforms[index];
}
- const btTransform getChildTransform(int index) const
+ const btTransform& getChildTransform(int index) const
{
return m_childTransforms[index];
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
index 5a359c0cff1..94be43c88e2 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
@@ -18,9 +18,66 @@ subject to the following restrictions:
#include "LinearMath/btTransformUtil.h"
-btHeightfieldTerrainShape::btHeightfieldTerrainShape()
-:m_localScaling(btScalar(0.),btScalar(0.),btScalar(0.))
+btHeightfieldTerrainShape::btHeightfieldTerrainShape(int width,int length,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges)
+:m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
+m_width(width),
+m_length(length),
+m_heightfieldDataUnknown(heightfieldData),
+m_maxHeight(maxHeight),
+m_upAxis(upAxis),
+m_useFloatData(useFloatData),
+m_flipQuadEdges(flipQuadEdges),
+m_useDiamondSubdivision(false)
{
+
+
+ btScalar quantizationMargin = 1.f;
+
+ //enlarge the AABB to avoid division by zero when initializing the quantization values
+ btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
+
+ btVector3 halfExtents(0,0,0);
+
+ switch (m_upAxis)
+ {
+ case 0:
+ {
+ halfExtents.setValue(
+ m_maxHeight,
+ m_width,
+ m_length);
+ break;
+ }
+ case 1:
+ {
+ halfExtents.setValue(
+ m_width,
+ m_maxHeight,
+ m_length);
+ break;
+ };
+ case 2:
+ {
+ halfExtents.setValue(
+ m_width,
+ m_length,
+ m_maxHeight
+ );
+ break;
+ }
+ default:
+ {
+ //need to get valid m_upAxis
+ btAssert(0);
+ }
+ }
+
+ halfExtents*= btScalar(0.5);
+
+ m_localAabbMin = -halfExtents - clampValue;
+ m_localAabbMax = halfExtents + clampValue;
+ btVector3 aabbSize = m_localAabbMax - m_localAabbMin;
+
}
@@ -30,51 +87,238 @@ btHeightfieldTerrainShape::~btHeightfieldTerrainShape()
-void btHeightfieldTerrainShape::getAabb(const btTransform& ,btVector3& aabbMin,btVector3& aabbMax) const
+void btHeightfieldTerrainShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
+{
+/*
+ aabbMin.setValue(-1e30f,-1e30f,-1e30f);
+ aabbMax.setValue(1e30f,1e30f,1e30f);
+*/
+
+ btVector3 halfExtents = (m_localAabbMax-m_localAabbMin)* m_localScaling * btScalar(0.5);
+
+ btMatrix3x3 abs_b = t.getBasis().absolute();
+ btPoint3 center = t.getOrigin();
+ btVector3 extent = btVector3(abs_b[0].dot(halfExtents),
+ abs_b[1].dot(halfExtents),
+ abs_b[2].dot(halfExtents));
+ extent += btVector3(getMargin(),getMargin(),getMargin());
+
+ aabbMin = center - extent;
+ aabbMax = center + extent;
+
+
+}
+
+btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const
{
- aabbMin.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
- aabbMax.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
+ btScalar val = 0.f;
+ if (m_useFloatData)
+ {
+ val = m_heightfieldDataFloat[(y*m_width)+x];
+ } else
+ {
+ //assume unsigned short int
+ unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_width)+x];
+ val = heightFieldValue* (m_maxHeight/btScalar(65535));
+ }
+ return val;
}
+
+void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
+{
+
+ btAssert(x>=0);
+ btAssert(y>=0);
+ btAssert(x<m_width);
+ btAssert(y<m_length);
+
+
+ btScalar height = getHeightFieldValue(x,y);
+
+ switch (m_upAxis)
+ {
+ case 0:
+ {
+ vertex.setValue(
+ height,
+ (-m_width/2 ) + x,
+ (-m_length/2 ) + y
+ );
+ break;
+ }
+ case 1:
+ {
+ vertex.setValue(
+ (-m_width/2 ) + x,
+ height,
+ (-m_length/2 ) + y
+ );
+ break;
+ };
+ case 2:
+ {
+ vertex.setValue(
+ (-m_width/2 ) + x,
+ (-m_length/2 ) + y,
+ height
+ );
+ break;
+ }
+ default:
+ {
+ //need to get valid m_upAxis
+ btAssert(0);
+ }
+ }
+
+ vertex*=m_localScaling;
+
+}
+
+
+void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point) const
+{
+
+
+ btVector3 clampedPoint(point);
+ clampedPoint.setMax(m_localAabbMin);
+ clampedPoint.setMin(m_localAabbMax);
+
+ btVector3 v = (clampedPoint );// * m_quantization;
+
+ out[0] = (int)(v.getX());
+ out[1] = (int)(v.getY());
+ out[2] = (int)(v.getZ());
+ //correct for
+
+}
+
+
void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
{
(void)callback;
(void)aabbMax;
(void)aabbMin;
- /*
- btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
- btVector3 center = (aabbMax + aabbMin) * btScalar(0.5);
+ //quantize the aabbMin and aabbMax, and adjust the start/end ranges
+
+ int quantizedAabbMin[3];
+ int quantizedAabbMax[3];
+
+ btVector3 localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
+ btVector3 localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
+
+ quantizeWithClamp(quantizedAabbMin, localAabbMin);
+ quantizeWithClamp(quantizedAabbMax, localAabbMax);
+
- //TODO
- //this is where the triangles are generated, given AABB and plane equation (normal/constant)
- btVector3 tangentDir0,tangentDir1;
+ int startX=0;
+ int endX=m_width-1;
+ int startJ=0;
+ int endJ=m_length-1;
- //tangentDir0/tangentDir1 can be precalculated
- btPlaneSpace1(m_planeNormal,tangentDir0,tangentDir1);
+ switch (m_upAxis)
+ {
+ case 0:
+ {
+ quantizedAabbMin[1]+=m_width/2-1;
+ quantizedAabbMax[1]+=m_width/2+1;
+ quantizedAabbMin[2]+=m_length/2-1;
+ quantizedAabbMax[2]+=m_length/2+1;
- btVector3 supVertex0,supVertex1;
+ if (quantizedAabbMin[1]>startX)
+ startX = quantizedAabbMin[1];
+ if (quantizedAabbMax[1]<endX)
+ endX = quantizedAabbMax[1];
+ if (quantizedAabbMin[2]>startJ)
+ startJ = quantizedAabbMin[2];
+ if (quantizedAabbMax[2]<endJ)
+ endJ = quantizedAabbMax[2];
+ break;
+ }
+ case 1:
+ {
+ quantizedAabbMin[0]+=m_width/2-1;
+ quantizedAabbMax[0]+=m_width/2+1;
+ quantizedAabbMin[2]+=m_length/2-1;
+ quantizedAabbMax[2]+=m_length/2+1;
- btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal;
-
- btVector3 triangle[3];
- btScalar radius = halfExtents.length();
- triangle[0] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
- triangle[1] = projectedCenter + tangentDir0*radius - tangentDir1*radius;
- triangle[2] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
+ if (quantizedAabbMin[0]>startX)
+ startX = quantizedAabbMin[0];
+ if (quantizedAabbMax[0]<endX)
+ endX = quantizedAabbMax[0];
+ if (quantizedAabbMin[2]>startJ)
+ startJ = quantizedAabbMin[2];
+ if (quantizedAabbMax[2]<endJ)
+ endJ = quantizedAabbMax[2];
+ break;
+ };
+ case 2:
+ {
+ quantizedAabbMin[0]+=m_width/2-1;
+ quantizedAabbMax[0]+=m_width/2+1;
+ quantizedAabbMin[1]+=m_length/2-1;
+ quantizedAabbMax[1]+=m_length/2+1;
- callback->processTriangle(triangle,0,0);
+ if (quantizedAabbMin[0]>startX)
+ startX = quantizedAabbMin[0];
+ if (quantizedAabbMax[0]<endX)
+ endX = quantizedAabbMax[0];
+ if (quantizedAabbMin[1]>startJ)
+ startJ = quantizedAabbMin[1];
+ if (quantizedAabbMax[1]<endJ)
+ endJ = quantizedAabbMax[1];
+ break;
+ }
+ default:
+ {
+ //need to get valid m_upAxis
+ btAssert(0);
+ }
+ }
- triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
- triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
- triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
+
+
- callback->processTriangle(triangle,0,1);
-*/
+ for(int j=startJ; j<endJ; j++)
+ {
+ for(int x=startX; x<endX; x++)
+ {
+ btVector3 vertices[3];
+ if (m_flipQuadEdges || (m_useDiamondSubdivision && ((j+x) & 1)))
+ {
+ //first triangle
+ getVertex(x,j,vertices[0]);
+ getVertex(x+1,j,vertices[1]);
+ getVertex(x+1,j+1,vertices[2]);
+ callback->processTriangle(vertices,x,j);
+ //second triangle
+ getVertex(x,j,vertices[0]);
+ getVertex(x+1,j+1,vertices[1]);
+ getVertex(x,j+1,vertices[2]);
+ callback->processTriangle(vertices,x,j);
+ } else
+ {
+ //first triangle
+ getVertex(x,j,vertices[0]);
+ getVertex(x,j+1,vertices[1]);
+ getVertex(x+1,j,vertices[2]);
+ callback->processTriangle(vertices,x,j);
+ //second triangle
+ getVertex(x+1,j,vertices[0]);
+ getVertex(x,j+1,vertices[1]);
+ getVertex(x+1,j+1,vertices[2]);
+ callback->processTriangle(vertices,x,j);
+ }
+ }
+ }
+
+
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
index 85fd49638ce..49f3e106733 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
@@ -25,16 +25,46 @@ protected:
btVector3 m_localAabbMin;
btVector3 m_localAabbMax;
- //todo: terrain data
+ ///terrain data
+ int m_width;
+ int m_length;
+ btScalar m_maxHeight;
+ union
+ {
+ unsigned char* m_heightfieldDataUnsignedChar;
+ btScalar* m_heightfieldDataFloat;
+ void* m_heightfieldDataUnknown;
+ };
+
+ bool m_useFloatData;
+ bool m_flipQuadEdges;
+ bool m_useDiamondSubdivision;
+ int m_upAxis;
+
btVector3 m_localScaling;
+ virtual btScalar getHeightFieldValue(int x,int y) const;
+ void quantizeWithClamp(int* out, const btVector3& point) const;
+ void getVertex(int x,int y,btVector3& vertex) const;
+
+ inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const int* aabbMin2,const int* aabbMax2) const
+ {
+ bool overlap = true;
+ overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
+ overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
+ overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
+ return overlap;
+ }
+
public:
- btHeightfieldTerrainShape();
+ btHeightfieldTerrainShape(int width,int height,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
virtual ~btHeightfieldTerrainShape();
+ void setUseDiamondSubdivision(bool useDiamondSubdivision=true) { m_useDiamondSubdivision = useDiamondSubdivision;}
+
virtual int getShapeType() const
{
return TERRAIN_SHAPE_PROXYTYPE;
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
index b213f3819a4..015314bc09f 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
@@ -16,7 +16,7 @@ subject to the following restrictions:
#include "btMinkowskiSumShape.h"
-btMinkowskiSumShape::btMinkowskiSumShape(btConvexShape* shapeA,btConvexShape* shapeB)
+btMinkowskiSumShape::btMinkowskiSumShape(const btConvexShape* shapeA,const btConvexShape* shapeB)
:m_shapeA(shapeA),
m_shapeB(shapeB)
{
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
index 489b7ddde1e..198faaff9f9 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
@@ -25,12 +25,12 @@ class btMinkowskiSumShape : public btConvexShape
btTransform m_transA;
btTransform m_transB;
- btConvexShape* m_shapeA;
- btConvexShape* m_shapeB;
+ const btConvexShape* m_shapeA;
+ const btConvexShape* m_shapeB;
public:
- btMinkowskiSumShape(btConvexShape* shapeA,btConvexShape* shapeB);
+ btMinkowskiSumShape(const btConvexShape* shapeA,const btConvexShape* shapeB);
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h
index be044dbc16a..1897b474057 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h
@@ -46,6 +46,20 @@ public:
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
+ int getSphereCount() const
+ {
+ return m_numSpheres;
+ }
+
+ const btVector3& getSpherePosition(int index) const
+ {
+ return m_localPositions[index];
+ }
+
+ btScalar getSphereRadius(int index) const
+ {
+ return m_radi[index];
+ }
virtual int getShapeType() const { return MULTI_SPHERE_SHAPE_PROXYTYPE; }
diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp
index 1ab336b4d54..687738b7fa9 100644
--- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp
+++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp
@@ -20,7 +20,7 @@ subject to the following restrictions:
#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
-btSubsimplexConvexCast::btSubsimplexConvexCast (btConvexShape* convexA,btConvexShape* convexB,btSimplexSolverInterface* simplexSolver)
+btSubsimplexConvexCast::btSubsimplexConvexCast (const btConvexShape* convexA,const btConvexShape* convexB,btSimplexSolverInterface* simplexSolver)
:m_simplexSolver(simplexSolver),
m_convexA(convexA),m_convexB(convexB)
{
diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h
index a2a3193b090..05662db5d23 100644
--- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h
+++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h
@@ -28,12 +28,12 @@ class btConvexShape;
class btSubsimplexConvexCast : public btConvexCast
{
btSimplexSolverInterface* m_simplexSolver;
- btConvexShape* m_convexA;
- btConvexShape* m_convexB;
+ const btConvexShape* m_convexA;
+ const btConvexShape* m_convexB;
public:
- btSubsimplexConvexCast (btConvexShape* shapeA,btConvexShape* shapeB,btSimplexSolverInterface* simplexSolver);
+ btSubsimplexConvexCast (const btConvexShape* shapeA,const btConvexShape* shapeB,btSimplexSolverInterface* simplexSolver);
//virtual ~btSubsimplexConvexCast();
///SimsimplexConvexCast calculateTimeOfImpact calculates the time of impact+normal for the linear cast (sweep) between two moving objects.