diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-01-11 09:24:18 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-01-11 09:24:18 +0300 |
commit | 1332091dc27f02e89b7e0c87c1fabe01148b7322 (patch) | |
tree | 61bc8562c533fd95cff75b7132a77bb22119d789 /extern | |
parent | 638b625d140376bfb48412c1aac5cf8e5587bb76 (diff) |
bullet in the orange branch seems to be merged incorrectly. updated to the latest version
Diffstat (limited to 'extern')
58 files changed, 421 insertions, 211 deletions
diff --git a/extern/bullet/Bullet/BroadphaseCollision/BroadphaseProxy.h b/extern/bullet/Bullet/BroadphaseCollision/BroadphaseProxy.h index 2f4ed2c1653..235e2f1e465 100644 --- a/extern/bullet/Bullet/BroadphaseCollision/BroadphaseProxy.h +++ b/extern/bullet/Bullet/BroadphaseCollision/BroadphaseProxy.h @@ -36,6 +36,7 @@ IMPLICIT_CONVEX_SHAPES_START_HERE, CONCAVE_SHAPES_START_HERE, //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy! TRIANGLE_MESH_SHAPE_PROXYTYPE, + EMPTY_SHAPE_PROXYTYPE, MAX_BROADPHASE_COLLISION_TYPES }; diff --git a/extern/bullet/Bullet/BroadphaseCollision/SimpleBroadphase.cpp b/extern/bullet/Bullet/BroadphaseCollision/SimpleBroadphase.cpp index 663cae2949a..823bfdc9edd 100644 --- a/extern/bullet/Bullet/BroadphaseCollision/SimpleBroadphase.cpp +++ b/extern/bullet/Bullet/BroadphaseCollision/SimpleBroadphase.cpp @@ -16,7 +16,7 @@ #include "SimdTransform.h" #include "SimdMatrix3x3.h" #include <vector> -#include "NarrowPhaseCollision/CollisionMargin.h" +#include "CollisionShapes/CollisionMargin.h" SimpleBroadphase::SimpleBroadphase() : m_firstFreeProxy(0), @@ -63,12 +63,34 @@ BroadphaseProxy* SimpleBroadphase::CreateProxy( void *object, int type, const Si } void SimpleBroadphase::DestroyProxy(BroadphaseProxy* proxy) { - m_numProxies--; + + int i; + BroadphaseProxy* proxy1 = &m_proxies[0]; int index = proxy - proxy1; m_freeProxies[--m_firstFreeProxy] = index; + for ( i=m_NumOverlapBroadphasePair-1;i>=0;i--) + { + BroadphasePair& pair = m_OverlappingPairs[i]; + if (pair.m_pProxy0 == proxy || + pair.m_pProxy1 == proxy) + { + RemoveOverlappingPair(pair); + } + } + + for (i=0;i<m_numProxies;i++) + { + if (m_pProxies[i] == proxy) + { + m_proxies[i] = m_proxies[m_numProxies-1]; + break; + } + } + m_numProxies--; + } SimpleBroadphaseProxy* SimpleBroadphase::GetSimpleProxyFromProxy(BroadphaseProxy* proxy) @@ -76,7 +98,7 @@ SimpleBroadphaseProxy* SimpleBroadphase::GetSimpleProxyFromProxy(BroadphaseProxy SimpleBroadphaseProxy* proxy0 = static_cast<SimpleBroadphaseProxy*>(proxy); int index = proxy0 - &m_proxies[0]; - assert(index < m_numProxies); + //assert(index < m_numProxies); SimpleBroadphaseProxy* sbp = &m_proxies[index]; return sbp; @@ -118,6 +140,8 @@ void SimpleBroadphase::CleanProxyFromPairs(BroadphaseProxy* proxy) void SimpleBroadphase::AddOverlappingPair(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1) { + + BroadphasePair pair(*proxy0,*proxy1); m_OverlappingPairs[m_NumOverlapBroadphasePair] = pair; diff --git a/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp b/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp index b3274435263..f7492328c02 100644 --- a/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp @@ -50,4 +50,5 @@ void BoxShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia) inertia[2] = mass/(12.0f) * (lx*lx + ly*ly); -}
\ No newline at end of file +} + diff --git a/extern/bullet/Bullet/CollisionShapes/BoxShape.h b/extern/bullet/Bullet/CollisionShapes/BoxShape.h index 1cb0d822b76..bbc07f90f5b 100644 --- a/extern/bullet/Bullet/CollisionShapes/BoxShape.h +++ b/extern/bullet/Bullet/CollisionShapes/BoxShape.h @@ -13,7 +13,7 @@ #define OBB_BOX_MINKOWSKI_H #include "PolyhedralConvexShape.h" -#include "NarrowPhaseCollision/CollisionMargin.h" +#include "CollisionShapes/CollisionMargin.h" #include "BroadphaseCollision/BroadphaseProxy.h" #include "SimdPoint3.h" #include "SimdMinMax.h" diff --git a/extern/bullet/Bullet/CollisionShapes/ConeShape.h b/extern/bullet/Bullet/CollisionShapes/ConeShape.h index 5a6b27c904d..55a6d02c334 100644 --- a/extern/bullet/Bullet/CollisionShapes/ConeShape.h +++ b/extern/bullet/Bullet/CollisionShapes/ConeShape.h @@ -70,4 +70,5 @@ public: }; -#endif //CONE_MINKOWSKI_H
\ No newline at end of file +#endif //CONE_MINKOWSKI_H + diff --git a/extern/bullet/Bullet/CollisionShapes/ConvexHullShape.cpp b/extern/bullet/Bullet/CollisionShapes/ConvexHullShape.cpp index 1cea1d02f08..fdb7a4d801a 100644 --- a/extern/bullet/Bullet/CollisionShapes/ConvexHullShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/ConvexHullShape.cpp @@ -10,7 +10,7 @@ */ #include "ConvexHullShape.h" -#include "NarrowPhaseCollision/CollisionMargin.h" +#include "CollisionShapes/CollisionMargin.h" #include "SimdQuaternion.h" @@ -75,29 +75,7 @@ SimdVector3 ConvexHullShape::LocalGetSupportingVertex(const SimdVector3& vec)con -void ConvexHullShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia) -{ - //not yet, return box inertia - - float margin = GetMargin(); - - SimdTransform ident; - ident.setIdentity(); - SimdVector3 aabbMin,aabbMax; - GetAabb(ident,aabbMin,aabbMax); - SimdVector3 halfExtents = (aabbMax-aabbMin)*0.5f; - SimdScalar lx=2.f*(halfExtents.x()+margin); - SimdScalar ly=2.f*(halfExtents.y()+margin); - SimdScalar lz=2.f*(halfExtents.z()+margin); - const SimdScalar x2 = lx*lx; - const SimdScalar y2 = ly*ly; - const SimdScalar z2 = lz*lz; - const SimdScalar scaledmass = mass * 0.08333333f; - - inertia = scaledmass * (SimdVector3(y2+z2,x2+z2,x2+y2)); - -} diff --git a/extern/bullet/Bullet/CollisionShapes/ConvexHullShape.h b/extern/bullet/Bullet/CollisionShapes/ConvexHullShape.h index a06bcb1e9dc..5906b9354c4 100644 --- a/extern/bullet/Bullet/CollisionShapes/ConvexHullShape.h +++ b/extern/bullet/Bullet/CollisionShapes/ConvexHullShape.h @@ -35,7 +35,6 @@ public: virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec)const; virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const; - virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia); virtual int GetShapeType()const { return CONVEX_HULL_SHAPE_PROXYTYPE; } @@ -56,4 +55,5 @@ public: }; -#endif //CONVEX_HULL_SHAPE_H
\ No newline at end of file +#endif //CONVEX_HULL_SHAPE_H + diff --git a/extern/bullet/Bullet/CollisionShapes/ConvexShape.h b/extern/bullet/Bullet/CollisionShapes/ConvexShape.h index b1e6f9e9924..82986200497 100644 --- a/extern/bullet/Bullet/CollisionShapes/ConvexShape.h +++ b/extern/bullet/Bullet/CollisionShapes/ConvexShape.h @@ -18,7 +18,7 @@ #include "SimdTransform.h" #include "SimdMatrix3x3.h" #include <vector> -#include "NarrowPhaseCollision/CollisionMargin.h" +#include "CollisionShapes/CollisionMargin.h" //todo: get rid of this ConvexCastResult thing! struct ConvexCastResult; diff --git a/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.h b/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.h index 8e0e446a549..c9f1a4acffd 100644 --- a/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.h +++ b/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.h @@ -46,4 +46,5 @@ int m_triangleCount; }; -#endif //CONVEX_TRIANGLE_CALLBACK_H
\ No newline at end of file +#endif //CONVEX_TRIANGLE_CALLBACK_H + diff --git a/extern/bullet/Bullet/CollisionShapes/CylinderShape.h b/extern/bullet/Bullet/CollisionShapes/CylinderShape.h index 8b1cb66685a..e35464ef1d3 100644 --- a/extern/bullet/Bullet/CollisionShapes/CylinderShape.h +++ b/extern/bullet/Bullet/CollisionShapes/CylinderShape.h @@ -82,4 +82,5 @@ public: }; -#endif //CYLINDER_MINKOWSKI_H
\ No newline at end of file +#endif //CYLINDER_MINKOWSKI_H + diff --git a/extern/bullet/Bullet/CollisionShapes/MultiSphereShape.cpp b/extern/bullet/Bullet/CollisionShapes/MultiSphereShape.cpp index 93787081a34..d1d5aa92897 100644 --- a/extern/bullet/Bullet/CollisionShapes/MultiSphereShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/MultiSphereShape.cpp @@ -9,7 +9,7 @@ * It is provided "as is" without express or implied warranty. */ #include "MultiSphereShape.h" -#include "NarrowPhaseCollision/CollisionMargin.h" +#include "CollisionShapes/CollisionMargin.h" #include "SimdQuaternion.h" MultiSphereShape::MultiSphereShape (const SimdVector3& inertiaHalfExtents,const SimdVector3* positions,const SimdScalar* radi,int numSpheres) diff --git a/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h b/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h index 911bb9af432..ca71ded41c9 100644 --- a/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h +++ b/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h @@ -89,4 +89,5 @@ public: }; -#endif //OPTIMIZED_BVH_H
\ No newline at end of file +#endif //OPTIMIZED_BVH_H + diff --git a/extern/bullet/Bullet/CollisionShapes/PolyhedralConvexShape.cpp b/extern/bullet/Bullet/CollisionShapes/PolyhedralConvexShape.cpp index 55f29bab960..e480b8911c7 100644 --- a/extern/bullet/Bullet/CollisionShapes/PolyhedralConvexShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/PolyhedralConvexShape.cpp @@ -50,3 +50,28 @@ SimdVector3 PolyhedralConvexShape::LocalGetSupportingVertexWithoutMargin(const S return supVec; } + +void PolyhedralConvexShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia) +{ + //not yet, return box inertia + + float margin = GetMargin(); + + SimdTransform ident; + ident.setIdentity(); + SimdVector3 aabbMin,aabbMax; + GetAabb(ident,aabbMin,aabbMax); + SimdVector3 halfExtents = (aabbMax-aabbMin)*0.5f; + + SimdScalar lx=2.f*(halfExtents.x()+margin); + SimdScalar ly=2.f*(halfExtents.y()+margin); + SimdScalar lz=2.f*(halfExtents.z()+margin); + const SimdScalar x2 = lx*lx; + const SimdScalar y2 = ly*ly; + const SimdScalar z2 = lz*lz; + const SimdScalar scaledmass = mass * 0.08333333f; + + inertia = scaledmass * (SimdVector3(y2+z2,x2+z2,x2+y2)); + +} + diff --git a/extern/bullet/Bullet/CollisionShapes/PolyhedralConvexShape.h b/extern/bullet/Bullet/CollisionShapes/PolyhedralConvexShape.h index 9c3764ae014..f1462e21f97 100644 --- a/extern/bullet/Bullet/CollisionShapes/PolyhedralConvexShape.h +++ b/extern/bullet/Bullet/CollisionShapes/PolyhedralConvexShape.h @@ -27,6 +27,9 @@ public: //brute force implementations virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const; + virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia); + + virtual int GetNumVertices() const = 0 ; virtual int GetNumEdges() const = 0; diff --git a/extern/bullet/Bullet/CollisionShapes/Simplex1to4Shape.h b/extern/bullet/Bullet/CollisionShapes/Simplex1to4Shape.h index a7533efa5cf..7c61cb661d7 100644 --- a/extern/bullet/Bullet/CollisionShapes/Simplex1to4Shape.h +++ b/extern/bullet/Bullet/CollisionShapes/Simplex1to4Shape.h @@ -38,10 +38,6 @@ public: m_numVertices = 0; } - virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia) - { - inertia = SimdVector3(1.f,1.f,1.f); - } virtual int GetShapeType() const{ return TETRAHEDRAL_SHAPE_PROXYTYPE; } diff --git a/extern/bullet/Bullet/CollisionShapes/SphereShape.cpp b/extern/bullet/Bullet/CollisionShapes/SphereShape.cpp index 8c28cca172e..bbffb8137de 100644 --- a/extern/bullet/Bullet/CollisionShapes/SphereShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/SphereShape.cpp @@ -10,7 +10,7 @@ */ #include "SphereShape.h" -#include "NarrowPhaseCollision/CollisionMargin.h" +#include "CollisionShapes/CollisionMargin.h" #include "SimdQuaternion.h" diff --git a/extern/bullet/Bullet/CollisionShapes/StridingMeshInterface.cpp b/extern/bullet/Bullet/CollisionShapes/StridingMeshInterface.cpp index 8fd761f06cb..9763a3c02a2 100644 --- a/extern/bullet/Bullet/CollisionShapes/StridingMeshInterface.cpp +++ b/extern/bullet/Bullet/CollisionShapes/StridingMeshInterface.cpp @@ -14,3 +14,67 @@ StridingMeshInterface::~StridingMeshInterface() { } + + +void StridingMeshInterface::InternalProcessAllTriangles(InternalTriangleIndexCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const +{ + + SimdVector3 meshScaling = getScaling(); + + int numtotalphysicsverts = 0; + int part,graphicssubparts = getNumSubParts(); + for (part=0;part<graphicssubparts ;part++) + { + const unsigned char * vertexbase; + const unsigned char * indexbase; + int indexstride; + PHY_ScalarType type; + PHY_ScalarType gfxindextype; + int stride,numverts,numtriangles; + getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part); + + numtotalphysicsverts+=numtriangles*3; //upper bound + + + int gfxindex; + SimdVector3 triangle[3]; + + for (gfxindex=0;gfxindex<numtriangles;gfxindex++) + { + + int graphicsindex=0; + +#ifdef DEBUG_TRIANGLE_MESH + printf("triangle indices:\n"); +#endif //DEBUG_TRIANGLE_MESH + ASSERT(gfxindextype == PHY_INTEGER); + int* gfxbase = (int*)(indexbase+gfxindex*indexstride); + + for (int j=2;j>=0;j--) + { + + graphicsindex = gfxbase[j]; +#ifdef DEBUG_TRIANGLE_MESH + printf("%d ,",graphicsindex); +#endif //DEBUG_TRIANGLE_MESH + float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); + + triangle[j] = SimdVector3( + graphicsbase[0]*meshScaling.getX(), + graphicsbase[1]*meshScaling.getY(), + graphicsbase[2]*meshScaling.getZ()); +#ifdef DEBUG_TRIANGLE_MESH + printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z()); +#endif //DEBUG_TRIANGLE_MESH + } + + + //check aabb in triangle-space, before doing this + callback->InternalProcessTriangleIndex(triangle,part,gfxindex); + + } + + unLockReadOnlyVertexBase(part); + } +} + diff --git a/extern/bullet/Bullet/CollisionShapes/StridingMeshInterface.h b/extern/bullet/Bullet/CollisionShapes/StridingMeshInterface.h index ba8a925c8dd..82f89b4dbe0 100644 --- a/extern/bullet/Bullet/CollisionShapes/StridingMeshInterface.h +++ b/extern/bullet/Bullet/CollisionShapes/StridingMeshInterface.h @@ -12,6 +12,7 @@ #define STRIDING_MESHINTERFACE_H #include "SimdVector3.h" +#include "TriangleCallback.h" /// PHY_ScalarType enumerates possible scalar types. /// See the StridingMeshInterface for its use @@ -38,26 +39,36 @@ class StridingMeshInterface } virtual ~StridingMeshInterface(); + + + + void InternalProcessAllTriangles(InternalTriangleIndexCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const; + + /// get read and write access to a subpart of a triangle mesh /// this subpart has a continuous array of vertices and indices /// in this way the mesh can be handled as chunks of memory with striding /// very similar to OpenGL vertexarray support /// make a call to unLockVertexBase when the read and write access is finished - virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0)=0; + virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0)=0; - + virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const=0; + /// unLockVertexBase finishes the access to a subpart of the triangle mesh /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished virtual void unLockVertexBase(int subpart)=0; + virtual void unLockReadOnlyVertexBase(int subpart) const=0; + + /// getNumSubParts returns the number of seperate subparts /// each subpart has a continuous array of vertices and indices - virtual int getNumSubParts()=0; + virtual int getNumSubParts() const=0; virtual void preallocateVertices(int numverts)=0; virtual void preallocateIndices(int numindices)=0; - const SimdVector3& getScaling() { + const SimdVector3& getScaling() const { return m_scaling; } void setScaling(const SimdVector3& scaling) diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleCallback.cpp b/extern/bullet/Bullet/CollisionShapes/TriangleCallback.cpp index 6fc69355c2d..64704dc41fd 100644 --- a/extern/bullet/Bullet/CollisionShapes/TriangleCallback.cpp +++ b/extern/bullet/Bullet/CollisionShapes/TriangleCallback.cpp @@ -20,4 +20,5 @@ TriangleCallback::~TriangleCallback() InternalTriangleIndexCallback::~InternalTriangleIndexCallback() { -}
\ No newline at end of file +} + diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleCallback.h b/extern/bullet/Bullet/CollisionShapes/TriangleCallback.h index 0e464d09e8b..cbffeeb9839 100644 --- a/extern/bullet/Bullet/CollisionShapes/TriangleCallback.h +++ b/extern/bullet/Bullet/CollisionShapes/TriangleCallback.h @@ -22,4 +22,14 @@ public: virtual void ProcessTriangle(SimdVector3* triangle) = 0; }; +class InternalTriangleIndexCallback +{ +public: + + virtual ~InternalTriangleIndexCallback(); + virtual void InternalProcessTriangleIndex(SimdVector3* triangle,int partId,int triangleIndex) = 0; +}; + + + #endif //TRIANGLE_CALLBACK_H diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.h b/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.h index 4784dc3938f..1e82950a344 100644 --- a/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.h +++ b/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.h @@ -43,4 +43,5 @@ public: virtual void preallocateVertices(int numverts){} virtual void preallocateIndices(int numindices){} -};
\ No newline at end of file +}; + diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleMesh.cpp b/extern/bullet/Bullet/CollisionShapes/TriangleMesh.cpp index d02b9600985..38cccec3e15 100644 --- a/extern/bullet/Bullet/CollisionShapes/TriangleMesh.cpp +++ b/extern/bullet/Bullet/CollisionShapes/TriangleMesh.cpp @@ -33,7 +33,24 @@ void TriangleMesh::getLockedVertexIndexBase(unsigned char **vertexbase, int& num } -int TriangleMesh::getNumSubParts() +void TriangleMesh::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const +{ + numverts = 3; + *vertexbase = (unsigned char*)&m_triangles[subpart]; + type = PHY_FLOAT; + stride = sizeof(SimdVector3); + + + numfaces = 1; + *indexbase = (unsigned char*) &myindices[0]; + indicestype = PHY_INTEGER; + indexstride = sizeof(int); + +} + + + +int TriangleMesh::getNumSubParts() const { return m_triangles.size(); } diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleMesh.h b/extern/bullet/Bullet/CollisionShapes/TriangleMesh.h index 0b0b937bf12..891ef6ea91a 100644 --- a/extern/bullet/Bullet/CollisionShapes/TriangleMesh.h +++ b/extern/bullet/Bullet/CollisionShapes/TriangleMesh.h @@ -46,13 +46,17 @@ class TriangleMesh : public StridingMeshInterface virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0); + virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const; + /// unLockVertexBase finishes the access to a subpart of the triangle mesh /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished virtual void unLockVertexBase(int subpart) {} + virtual void unLockReadOnlyVertexBase(int subpart) const {} + /// getNumSubParts returns the number of seperate subparts /// each subpart has a continuous array of vertices and indices - virtual int getNumSubParts(); + virtual int getNumSubParts() const; virtual void preallocateVertices(int numverts){} virtual void preallocateIndices(int numindices){} diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleMeshShape.cpp b/extern/bullet/Bullet/CollisionShapes/TriangleMeshShape.cpp index 0c20f78c1df..743e413307e 100644 --- a/extern/bullet/Bullet/CollisionShapes/TriangleMeshShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/TriangleMeshShape.cpp @@ -13,7 +13,7 @@ #include "SimdQuaternion.h" #include "StridingMeshInterface.h" #include "AabbUtil2.h" -#include "NarrowPhaseCollision/CollisionMargin.h" +#include "CollisionShapes/CollisionMargin.h" #include "stdio.h" @@ -21,8 +21,10 @@ TriangleMeshShape::TriangleMeshShape(StridingMeshInterface* meshInterface) : m_meshInterface(meshInterface), m_collisionMargin(CONVEX_DISTANCE_MARGIN) { + RecalcLocalAabb(); } + TriangleMeshShape::~TriangleMeshShape() { @@ -34,23 +36,39 @@ TriangleMeshShape::~TriangleMeshShape() void TriangleMeshShape::GetAabb(const SimdTransform& trans,SimdVector3& aabbMin,SimdVector3& aabbMax) const { + SimdVector3 localHalfExtents = 0.5f*(m_localAabbMax-m_localAabbMin); + SimdVector3 localCenter = 0.5f*(m_localAabbMax+m_localAabbMin); + + SimdMatrix3x3 abs_b = trans.getBasis().absolute(); + + SimdPoint3 center = trans(localCenter); + + SimdVector3 extent = SimdVector3(abs_b[0].dot(localHalfExtents), + abs_b[1].dot(localHalfExtents), + abs_b[2].dot(localHalfExtents)); + extent += SimdVector3(GetMargin(),GetMargin(),GetMargin()); + + aabbMin = center - extent; + aabbMax = center + extent; + + +} + +void TriangleMeshShape::RecalcLocalAabb() +{ for (int i=0;i<3;i++) { SimdVector3 vec(0.f,0.f,0.f); vec[i] = 1.f; - SimdVector3 tmp = trans(LocalGetSupportingVertex(vec*trans.getBasis())); - aabbMax[i] = tmp[i]+m_collisionMargin; + SimdVector3 tmp = LocalGetSupportingVertex(vec); + m_localAabbMax[i] = tmp[i]+m_collisionMargin; vec[i] = -1.f; - tmp = trans(LocalGetSupportingVertex(vec*trans.getBasis())); - aabbMin[i] = tmp[i]-m_collisionMargin; + tmp = LocalGetSupportingVertex(vec); + m_localAabbMin[i] = tmp[i]-m_collisionMargin; } } -TriangleCallback::~TriangleCallback() -{ - -} class SupportVertexCallback : public TriangleCallback { @@ -98,6 +116,7 @@ public: void TriangleMeshShape::setLocalScaling(const SimdVector3& scaling) { m_meshInterface->setScaling(scaling); + RecalcLocalAabb(); } const SimdVector3& TriangleMeshShape::getLocalScaling() const @@ -107,57 +126,43 @@ const SimdVector3& TriangleMeshShape::getLocalScaling() const + + + +//#define DEBUG_TRIANGLE_MESH + + void TriangleMeshShape::ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const { - SimdVector3 meshScaling = m_meshInterface->getScaling(); - int numtotalphysicsverts = 0; - int part,graphicssubparts = m_meshInterface->getNumSubParts(); - for (part=0;part<graphicssubparts ;part++) + struct FilteredCallback : public InternalTriangleIndexCallback { - unsigned char * vertexbase; - unsigned char * indexbase; - int indexstride; - PHY_ScalarType type; - PHY_ScalarType gfxindextype; - int stride,numverts,numtriangles; - m_meshInterface->getLockedVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part); - numtotalphysicsverts+=numtriangles*3; //upper bound - - - int gfxindex; - SimdVector3 triangle[3]; - - for (gfxindex=0;gfxindex<numtriangles;gfxindex++) + TriangleCallback* m_callback; + SimdVector3 m_aabbMin; + SimdVector3 m_aabbMax; + + FilteredCallback(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) + :m_callback(callback), + m_aabbMin(aabbMin), + m_aabbMax(aabbMax) { - - int graphicsindex=0; - - for (int j=2;j>=0;j--) - { - ASSERT(gfxindextype == PHY_INTEGER); - int* gfxbase = (int*)(indexbase+gfxindex*indexstride); - graphicsindex = gfxbase[j]; - float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); - - triangle[j] = SimdVector3( - graphicsbase[0]*meshScaling.getX(), - graphicsbase[1]*meshScaling.getY(), - graphicsbase[2]*meshScaling.getZ()); - } + } - if (TestTriangleAgainstAabb2(&triangle[0],aabbMin,aabbMax)) + virtual void InternalProcessTriangleIndex(SimdVector3* triangle,int partId,int triangleIndex) + { + if (TestTriangleAgainstAabb2(&triangle[0],m_aabbMin,m_aabbMax)) { //check aabb in triangle-space, before doing this - callback->ProcessTriangle(triangle); - + m_callback->ProcessTriangle(triangle); } } - - m_meshInterface->unLockVertexBase(part); - } + }; + + FilteredCallback filterCallback(callback,aabbMin,aabbMax); + + m_meshInterface->InternalProcessAllTriangles(&filterCallback,aabbMin,aabbMax); } diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleMeshShape.h b/extern/bullet/Bullet/CollisionShapes/TriangleMeshShape.h index 926191bddbb..4f42458f062 100644 --- a/extern/bullet/Bullet/CollisionShapes/TriangleMeshShape.h +++ b/extern/bullet/Bullet/CollisionShapes/TriangleMeshShape.h @@ -22,8 +22,10 @@ ///Concave triangle mesh. Uses an interface to access the triangles to allow for sharing graphics/physics triangles. class TriangleMeshShape : public CollisionShape { - +protected: StridingMeshInterface* m_meshInterface; + SimdVector3 m_localAabbMin; + SimdVector3 m_localAabbMax; float m_collisionMargin; public: @@ -41,6 +43,8 @@ public: return LocalGetSupportingVertex(vec); } + void RecalcLocalAabb(); + virtual int GetShapeType() const { return TRIANGLE_MESH_SHAPE_PROXYTYPE; @@ -48,7 +52,7 @@ public: virtual void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const; - void ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const; + virtual void ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const; virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia); diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleShape.h b/extern/bullet/Bullet/CollisionShapes/TriangleShape.h index 60ea95da5d0..570a312da1a 100644 --- a/extern/bullet/Bullet/CollisionShapes/TriangleShape.h +++ b/extern/bullet/Bullet/CollisionShapes/TriangleShape.h @@ -143,4 +143,5 @@ public: }; -#endif //OBB_TRIANGLE_MINKOWSKI_H
\ No newline at end of file +#endif //OBB_TRIANGLE_MINKOWSKI_H + diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/ContinuousConvexCollision.h b/extern/bullet/Bullet/NarrowPhaseCollision/ContinuousConvexCollision.h index b8b31377aa7..94f1dafe1bb 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/ContinuousConvexCollision.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/ContinuousConvexCollision.h @@ -43,4 +43,5 @@ public: }; -#endif //CONTINUOUS_COLLISION_CONVEX_CAST_H
\ No newline at end of file +#endif //CONTINUOUS_COLLISION_CONVEX_CAST_H + diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/ConvexPenetrationDepthSolver.h b/extern/bullet/Bullet/NarrowPhaseCollision/ConvexPenetrationDepthSolver.h index 8af37e08032..a8fdbc55414 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/ConvexPenetrationDepthSolver.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/ConvexPenetrationDepthSolver.h @@ -30,4 +30,5 @@ public: }; -#endif //CONVEX_PENETRATION_DEPTH_H
\ No newline at end of file +#endif //CONVEX_PENETRATION_DEPTH_H + diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.cpp index 45d7403586f..4c129848fe0 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.cpp +++ b/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.cpp @@ -154,4 +154,5 @@ bool GjkConvexCast::calcTimeOfImpact( } return false; -}
\ No newline at end of file +} + diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.h b/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.h index a1bcc615010..3d3c5de4110 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/GjkConvexCast.h @@ -13,7 +13,8 @@ #ifndef GJK_CONVEX_CAST_H #define GJK_CONVEX_CAST_H -#include "CollisionMargin.h" +#include <CollisionShapes/CollisionMargin.h> + #include "SimdVector3.h" #include "ConvexCast.h" class ConvexShape; diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.h b/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.h index f6311a9eba5..bfef4a91682 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/GjkPairDetector.h @@ -17,7 +17,7 @@ #include "DiscreteCollisionDetectorInterface.h" #include "SimdPoint3.h" -#include "CollisionMargin.h" +#include <CollisionShapes/CollisionMargin.h> class ConvexShape; #include "SimplexSolverInterface.h" diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp index bb45e5215f3..98e45f6d1df 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp +++ b/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp @@ -30,4 +30,5 @@ void ManifoldContactAddResult::AddContactPoint(const SimdVector3& normalOnBInWor { m_manifoldPtr->AddManifoldPoint(newPt); } -}
\ No newline at end of file +} + diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cpp index 1926501b84b..6ff503e7322 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cpp +++ b/extern/bullet/Bullet/NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.cpp @@ -131,7 +131,7 @@ bool MinkowskiPenetrationDepthSolver::CalcPenDepth(SimplexSolverInterface& simpl if (res.m_hasResult) { - pa = res.m_pointInWorld - res.m_normalOnBInWorld*res.m_depth; + pa = res.m_pointInWorld - res.m_normalOnBInWorld*0.1f*res.m_depth; pb = res.m_pointInWorld; } return res.m_hasResult; diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/PointCollector.h b/extern/bullet/Bullet/NarrowPhaseCollision/PointCollector.h index f39fa090ae4..e4f22b69f46 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/PointCollector.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/PointCollector.h @@ -33,4 +33,5 @@ struct PointCollector : public DiscreteCollisionDetectorInterface::Result } }; -#endif //POINT_COLLECTOR_H
\ No newline at end of file +#endif //POINT_COLLECTOR_H + diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.h b/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.h index 8fc97bb3b40..a1d34dcb2f6 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.h @@ -37,4 +37,5 @@ public: virtual void ProcessTriangle(SimdVector3* triangle); }; -#endif //RAYCAST_TRI_CALLBACK_H
\ No newline at end of file +#endif //RAYCAST_TRI_CALLBACK_H + diff --git a/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.cpp b/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.cpp index 3f356c703d7..fef5ef281b2 100644 --- a/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.cpp +++ b/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.cpp @@ -38,7 +38,7 @@ ///It improves the penetration depth handling dramatically //#define USE_EPA #ifdef USE_EPA -#include "NarrowPhaseCollision/Solid3EpaPenetrationDepth.h" +#include "../Extras/ExtraSolid35/Solid3EpaPenetrationDepth.h" bool gUseEpa = true; #else bool gUseEpa = false; @@ -68,11 +68,10 @@ ConvexConvexAlgorithm::ConvexConvexAlgorithm(PersistentManifold* mf,const Collis m_gjkPairDetector(0,0,&m_simplexSolver,0), m_box0(*proxy0), m_box1(*proxy1), -m_collisionImpulse(0.f), m_ownManifold (false), m_manifoldPtr(mf), m_lowLevelOfDetail(false), -m_useEpa(gUseEpa) +m_useEpa(!gUseEpa) { CheckPenetrationDepthSolver(); @@ -137,30 +136,34 @@ public: }; +static MinkowskiPenetrationDepthSolver gPenetrationDepthSolver; + +#ifdef USE_EPA +Solid3EpaPenetrationDepth gSolidEpaPenetrationSolver; +#endif //USE_EPA + void ConvexConvexAlgorithm::CheckPenetrationDepthSolver() { -// if (m_useEpa != gUseEpa) + if (m_useEpa != gUseEpa) { m_useEpa = gUseEpa; if (m_useEpa) { //not distributed, see top of this file #ifdef USE_EPA - m_gjkPairDetector.SetPenetrationDepthSolver(new Solid3EpaPenetrationDepth); + m_gjkPairDetector.SetPenetrationDepthSolver(&gSolidEpaPenetrationSolver); #else - m_gjkPairDetector.SetPenetrationDepthSolver(new MinkowskiPenetrationDepthSolver); + m_gjkPairDetector.SetPenetrationDepthSolver(&gPenetrationDepthSolver); #endif } else { - m_gjkPairDetector.SetPenetrationDepthSolver(new MinkowskiPenetrationDepthSolver); + m_gjkPairDetector.SetPenetrationDepthSolver(&gPenetrationDepthSolver); } } } -bool extra = false; -float gFriction = 0.5f; // // box-box collision algorithm, for simplicity also applies resolution-impulse // @@ -169,7 +172,7 @@ void ConvexConvexAlgorithm ::ProcessCollision (BroadphaseProxy* ,BroadphaseProxy CheckPenetrationDepthSolver(); // printf("ConvexConvexAlgorithm::ProcessCollision\n"); -m_collisionImpulse = 0.f; + RigidBody* body0 = (RigidBody*)m_box0.m_clientObject; RigidBody* body1 = (RigidBody*)m_box1.m_clientObject; @@ -227,7 +230,7 @@ float ConvexConvexAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* proxy0,Broad CheckPenetrationDepthSolver(); - m_collisionImpulse = 0.f; + RigidBody* body0 = (RigidBody*)m_box0.m_clientObject; RigidBody* body1 = (RigidBody*)m_box1.m_clientObject; diff --git a/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.h b/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.h index 8b16687f192..b560e8d4c15 100644 --- a/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.h +++ b/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.h @@ -29,7 +29,7 @@ class ConvexConvexAlgorithm : public CollisionAlgorithm public: BroadphaseProxy m_box0; BroadphaseProxy m_box1; - float m_collisionImpulse; + bool m_ownManifold; PersistentManifold* m_manifoldPtr; bool m_lowLevelOfDetail; diff --git a/extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp b/extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp index 01c2dbf031d..0c400a84dca 100644 --- a/extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp +++ b/extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp @@ -27,8 +27,8 @@ SimdScalar contactTau = .02f;//0.02f;//*0.02f; SimdScalar restitutionCurve(SimdScalar rel_vel, SimdScalar restitution) { - return 0.f; -// return restitution * GEN_min(1.0f, rel_vel / ContactThreshold); +// return 0.f; + return restitution * GEN_min(1.0f, rel_vel / ContactThreshold); } @@ -139,28 +139,31 @@ SimdScalar rel_vel; */ rel_vel = normal.dot(vel); -// if (rel_vel< 0.f)//-SIMD_EPSILON) -// { float combinedRestitution = body1.getRestitution() * body2.getRestitution(); - SimdScalar rest = restitutionCurve(rel_vel, combinedRestitution); -// SimdScalar massTerm = 1.f / (body1.getInvMass() + body2.getInvMass()); + SimdScalar restitution = restitutionCurve(rel_vel, combinedRestitution); - SimdScalar timeCorrection = 0.5f / solverInfo.m_timeStep ; + SimdScalar Kfps = 1.f / solverInfo.m_timeStep ; float damping = solverInfo.m_damping ; - float tau = solverInfo.m_tau; - + float Kerp = solverInfo.m_tau; + if (useGlobalSettingContacts) { damping = contactDamping; - tau = contactTau; + Kerp = contactTau; } - SimdScalar penetrationImpulse = (-distance* tau *timeCorrection) * jacDiagABInv; - + float Kcor = Kerp *Kfps; + + + SimdScalar positionalError = Kcor *-distance; + //jacDiagABInv; + SimdScalar velocityError = -(1.0f + restitution) * damping * rel_vel; + + SimdScalar penetrationImpulse = positionalError * jacDiagABInv; - SimdScalar velocityImpulse = -(1.0f + rest) * damping * rel_vel * jacDiagABInv; + SimdScalar velocityImpulse = velocityError * jacDiagABInv; SimdScalar friction_impulse = 0.f; @@ -177,11 +180,11 @@ SimdScalar rel_vel; { - SimdVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1); - SimdVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2); - SimdVector3 vel = vel1 - vel2; - - rel_vel = normal.dot(vel); + SimdVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1); + SimdVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2); + SimdVector3 vel = vel1 - vel2; + + rel_vel = normal.dot(vel); #define PER_CONTACT_FRICTION #ifdef PER_CONTACT_FRICTION diff --git a/extern/bullet/BulletDynamics/ConstraintSolver/JacobianEntry.h b/extern/bullet/BulletDynamics/ConstraintSolver/JacobianEntry.h index ebf58c34485..3a89f2ad1fd 100644 --- a/extern/bullet/BulletDynamics/ConstraintSolver/JacobianEntry.h +++ b/extern/bullet/BulletDynamics/ConstraintSolver/JacobianEntry.h @@ -16,7 +16,7 @@ //notes: -// Another memory optimization would be to store m_MbJ in the remaining 3 w components +// Another memory optimization would be to store m_1MinvJt in the remaining 3 w components // which makes the JacobianEntry memory layout 16 bytes // if you only are interested in angular part, just feed massInvA and massInvB zero @@ -32,59 +32,59 @@ public: const SimdMatrix3x3& world2A, const SimdMatrix3x3& world2B, const SimdVector3& rel_pos1,const SimdVector3& rel_pos2, - const SimdVector3& normal, + const SimdVector3& jointAxis, const SimdVector3& inertiaInvA, const SimdScalar massInvA, const SimdVector3& inertiaInvB, const SimdScalar massInvB) - :m_normalAxis(normal) + :m_jointAxis(jointAxis) { - m_aJ = world2A*(rel_pos1.cross(normal)); - m_bJ = world2B*(rel_pos2.cross(normal)); - m_MaJ = inertiaInvA * m_aJ; - m_MbJ = inertiaInvB * m_bJ; - m_jacDiagAB = massInvA + m_MaJ.dot(m_aJ) + massInvB + m_MbJ.dot(m_bJ); + m_aJ = world2A*(rel_pos1.cross(m_jointAxis)); + m_bJ = world2B*(rel_pos2.cross(m_jointAxis)); + m_0MinvJt = inertiaInvA * m_aJ; + m_1MinvJt = inertiaInvB * m_bJ; + m_Adiag = massInvA + m_0MinvJt.dot(m_aJ) + massInvB + m_1MinvJt.dot(m_bJ); } //angular constraint between two different rigidbodies - JacobianEntry(const SimdVector3& normal, + JacobianEntry(const SimdVector3& jointAxis, const SimdMatrix3x3& world2A, const SimdMatrix3x3& world2B, const SimdVector3& inertiaInvA, const SimdVector3& inertiaInvB) - :m_normalAxis(normal) + :m_jointAxis(m_jointAxis) { - m_aJ= world2A*normal; - m_bJ = world2B*-normal; - m_MaJ = inertiaInvA * m_aJ; - m_MbJ = inertiaInvB * m_bJ; - m_jacDiagAB = m_MaJ.dot(m_aJ) + m_MbJ.dot(m_bJ); + m_aJ= world2A*m_jointAxis; + m_bJ = world2B*-m_jointAxis; + m_0MinvJt = inertiaInvA * m_aJ; + m_1MinvJt = inertiaInvB * m_bJ; + m_Adiag = m_0MinvJt.dot(m_aJ) + m_1MinvJt.dot(m_bJ); } //constraint on one rigidbody JacobianEntry( const SimdMatrix3x3& world2A, const SimdVector3& rel_pos1,const SimdVector3& rel_pos2, - const SimdVector3& normal, + const SimdVector3& jointAxis, const SimdVector3& inertiaInvA, const SimdScalar massInvA) - :m_normalAxis(normal) + :m_jointAxis(jointAxis) { - m_aJ= world2A*(rel_pos1.cross(normal)); - m_bJ = world2A*(rel_pos2.cross(normal)); - m_MaJ = inertiaInvA * m_aJ; - m_MbJ = SimdVector3(0.f,0.f,0.f); - m_jacDiagAB = massInvA + m_MaJ.dot(m_aJ); + m_aJ= world2A*(rel_pos1.cross(m_jointAxis)); + m_bJ = world2A*(rel_pos2.cross(m_jointAxis)); + m_0MinvJt = inertiaInvA * m_aJ; + m_1MinvJt = SimdVector3(0.f,0.f,0.f); + m_Adiag = massInvA + m_0MinvJt.dot(m_aJ); } - SimdScalar getDiagonal() const { return m_jacDiagAB; } + SimdScalar getDiagonal() const { return m_Adiag; } // for two constraints on the same rigidbody (for example vehicle friction) SimdScalar getNonDiagonal(const JacobianEntry& jacB, const SimdScalar massInvA) const { const JacobianEntry& jacA = *this; - SimdScalar lin = massInvA * jacA.m_normalAxis.dot(jacB.m_normalAxis); - SimdScalar ang = jacA.m_MaJ.dot(jacB.m_aJ); + SimdScalar lin = massInvA * jacA.m_jointAxis.dot(jacB.m_jointAxis); + SimdScalar ang = jacA.m_0MinvJt.dot(jacB.m_aJ); return lin + ang; } @@ -94,9 +94,9 @@ public: SimdScalar getNonDiagonal(const JacobianEntry& jacB,const SimdScalar massInvA,const SimdScalar massInvB) const { const JacobianEntry& jacA = *this; - SimdVector3 lin = jacA.m_normalAxis * jacB.m_normalAxis; - SimdVector3 ang0 = jacA.m_MaJ * jacB.m_aJ; - SimdVector3 ang1 = jacA.m_MbJ * jacB.m_bJ; + SimdVector3 lin = jacA.m_jointAxis* jacB.m_jointAxis; + SimdVector3 ang0 = jacA.m_0MinvJt * jacB.m_aJ; + SimdVector3 ang1 = jacA.m_1MinvJt * jacB.m_bJ; SimdVector3 lin0 = massInvA * lin ; SimdVector3 lin1 = massInvB * lin; SimdVector3 sum = ang0+ang1+lin0+lin1; @@ -108,7 +108,7 @@ public: SimdVector3 linrel = linvelA - linvelB; SimdVector3 angvela = angvelA * m_aJ; SimdVector3 angvelb = angvelB * m_bJ; - linrel *= m_normalAxis; + linrel *= m_jointAxis; angvela += angvelb; angvela += linrel; SimdScalar rel_vel2 = angvela[0]+angvela[1]+angvela[2]; @@ -116,13 +116,13 @@ public: } //private: - SimdVector3 m_normalAxis; + SimdVector3 m_jointAxis; SimdVector3 m_aJ; SimdVector3 m_bJ; - SimdVector3 m_MaJ; - SimdVector3 m_MbJ; + SimdVector3 m_0MinvJt; + SimdVector3 m_1MinvJt; //Optimization: can be stored in the w/last component of one of the vectors - SimdScalar m_jacDiagAB; + SimdScalar m_Adiag; }; diff --git a/extern/bullet/BulletDynamics/ConstraintSolver/OdeConstraintSolver.cpp b/extern/bullet/BulletDynamics/ConstraintSolver/OdeConstraintSolver.cpp index aa0beab7786..acb6728deeb 100644 --- a/extern/bullet/BulletDynamics/ConstraintSolver/OdeConstraintSolver.cpp +++ b/extern/bullet/BulletDynamics/ConstraintSolver/OdeConstraintSolver.cpp @@ -33,11 +33,15 @@ #include <string.h> #include <stdio.h> -#ifdef WIN32 +#if defined (WIN32) #include <malloc.h> #else +#if defined (__FreeBSD__) +#include <stdlib.h> +#else #include <alloca.h> #endif +#endif class BU_Joint; @@ -45,7 +49,7 @@ class BU_Joint; OdeConstraintSolver::OdeConstraintSolver(): m_cfm(1e-5f), -m_erp(0.3f) +m_erp(0.4f) { } diff --git a/extern/bullet/BulletDynamics/ConstraintSolver/Solve2LinearConstraint.cpp b/extern/bullet/BulletDynamics/ConstraintSolver/Solve2LinearConstraint.cpp index 4111de679d0..849e57d1088 100644 --- a/extern/bullet/BulletDynamics/ConstraintSolver/Solve2LinearConstraint.cpp +++ b/extern/bullet/BulletDynamics/ConstraintSolver/Solve2LinearConstraint.cpp @@ -231,4 +231,5 @@ void Solve2LinearConstraint::resolveAngularConstraint( const SimdMatrix3x3& invI SimdScalar& imp0,SimdScalar& imp1) { -}
\ No newline at end of file +} + diff --git a/extern/bullet/BulletDynamics/ConstraintSolver/SorLcp.cpp b/extern/bullet/BulletDynamics/ConstraintSolver/SorLcp.cpp index ea9240c2bcf..311fd8b5eed 100644 --- a/extern/bullet/BulletDynamics/ConstraintSolver/SorLcp.cpp +++ b/extern/bullet/BulletDynamics/ConstraintSolver/SorLcp.cpp @@ -39,11 +39,15 @@ #include <string.h> #include <stdio.h> -#ifdef WIN32 +#if defined (WIN32) #include <malloc.h> #else +#if defined (__FreeBSD__) +#include <stdlib.h> +#else #include <alloca.h> #endif +#endif #include "Dynamics/BU_Joint.h" #include "ContactSolverInfo.h" @@ -838,4 +842,4 @@ void SolveInternal1 (float global_cfm, } -#endif //USE_SOR_SOLVER
\ No newline at end of file +#endif //USE_SOR_SOLVER diff --git a/extern/bullet/BulletDynamics/ConstraintSolver/SorLcp.h b/extern/bullet/BulletDynamics/ConstraintSolver/SorLcp.h index 7edeaba3dd1..37fe09c2607 100644 --- a/extern/bullet/BulletDynamics/ConstraintSolver/SorLcp.h +++ b/extern/bullet/BulletDynamics/ConstraintSolver/SorLcp.h @@ -41,4 +41,5 @@ int dRandInt2 (int n); #endif //SOR_LCP_H -#endif //USE_SOR_SOLVER
\ No newline at end of file +#endif //USE_SOR_SOLVER + diff --git a/extern/bullet/BulletDynamics/Dynamics/ContactJoint.cpp b/extern/bullet/BulletDynamics/Dynamics/ContactJoint.cpp index b60b4eefe34..0a988adcc75 100644 --- a/extern/bullet/BulletDynamics/Dynamics/ContactJoint.cpp +++ b/extern/bullet/BulletDynamics/Dynamics/ContactJoint.cpp @@ -165,7 +165,7 @@ void ContactJoint::GetInfo2(Info2 *info) c2[2] = ccc2[2]; - float friction = 10.1f;//FRICTION_CONSTANT*m_body0->getFriction() * m_body1->getFriction(); + float friction = FRICTION_CONSTANT*m_body0->getFriction() * m_body1->getFriction(); // first friction direction if (m_numRows >= 2) diff --git a/extern/bullet/BulletDynamics/Dynamics/ContactJoint.h b/extern/bullet/BulletDynamics/Dynamics/ContactJoint.h index 54cc5283da0..4e1dc8e1669 100644 --- a/extern/bullet/BulletDynamics/Dynamics/ContactJoint.h +++ b/extern/bullet/BulletDynamics/Dynamics/ContactJoint.h @@ -30,4 +30,6 @@ public: }; -#endif //CONTACT_JOINT_H
\ No newline at end of file + +#endif //CONTACT_JOINT_H + diff --git a/extern/bullet/BulletDynamics/Dynamics/MassProps.h b/extern/bullet/BulletDynamics/Dynamics/MassProps.h index 892e1c0b9a8..e0e4e87bc8a 100644 --- a/extern/bullet/BulletDynamics/Dynamics/MassProps.h +++ b/extern/bullet/BulletDynamics/Dynamics/MassProps.h @@ -15,4 +15,5 @@ struct MassProps { }; -#endif
\ No newline at end of file +#endif + diff --git a/extern/bullet/BulletDynamics/Dynamics/RigidBody.cpp b/extern/bullet/BulletDynamics/Dynamics/RigidBody.cpp index a6c0fda96f3..f7c31dd0d68 100644 --- a/extern/bullet/BulletDynamics/Dynamics/RigidBody.cpp +++ b/extern/bullet/BulletDynamics/Dynamics/RigidBody.cpp @@ -58,11 +58,6 @@ void RigidBody::getAabb(SimdVector3& aabbMin,SimdVector3& aabbMax) const void RigidBody::SetCollisionShape(CollisionShape* mink) { m_collisionShape = mink; - SimdTransform ident; - ident.setIdentity(); - SimdVector3 aabbMin,aabbMax; - m_collisionShape ->GetAabb(ident,aabbMin,aabbMax); - SimdVector3 diag = (aabbMax-aabbMin)*0.5f; } diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp index 5ddacd05d05..919d1f9e58c 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp @@ -39,10 +39,12 @@ CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci) MassProps mp(ci.m_mass, ci.m_localInertiaTensor); m_body = new RigidBody(mp,0,0,ci.m_friction,ci.m_restitution); + + m_body->SetCollisionShape( ci.m_collisionShape); + m_broadphaseHandle = ci.m_broadphaseHandle; - m_collisionShape = ci.m_collisionShape; // // init the rigidbody properly @@ -67,7 +69,6 @@ CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci) CcdPhysicsController::~CcdPhysicsController() { //will be reference counted, due to sharing - //delete m_collisionShape; delete m_MotionState; delete m_body; } @@ -89,12 +90,18 @@ bool CcdPhysicsController::SynchronizeMotionStates(float time) m_MotionState->getWorldScaling(scale[0],scale[1],scale[2]); SimdVector3 scaling(scale[0],scale[1],scale[2]); - m_collisionShape->setLocalScaling(scaling); - + m_body->GetCollisionShape()->setLocalScaling(scaling); return true; } +CollisionShape* CcdPhysicsController::GetCollisionShape() +{ + return m_body->GetCollisionShape(); +} + + + /** WriteMotionStateToDynamics synchronizes dynas, kinematic and deformable entities (and do 'late binding') */ diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.h b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.h index 4f189b7f324..478e0e66a39 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.h +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.h @@ -53,7 +53,6 @@ class CcdPhysicsController : public PHY_IPhysicsController { RigidBody* m_body; class PHY_IMotionState* m_MotionState; - CollisionShape* m_collisionShape; void* m_newClientInfo; void GetWorldOrientation(SimdMatrix3x3& mat); @@ -71,7 +70,7 @@ class CcdPhysicsController : public PHY_IPhysicsController RigidBody* GetRigidBody() { return m_body;} - CollisionShape* GetCollisionShape() { return m_collisionShape;} + CollisionShape* GetCollisionShape(); //////////////////////////////////// // PHY_IPhysicsController interface //////////////////////////////////// diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp index b68e730b4c6..558f294344a 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp @@ -118,6 +118,7 @@ void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl) BroadphaseInterface* scene = m_broadphase; + CollisionShape* shapeinterface = ctrl->GetCollisionShape(); assert(shapeinterface); @@ -171,7 +172,7 @@ void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl) maxAabb); } - body->SetCollisionShape( shapeinterface ); + diff --git a/extern/bullet/Extras/PhysicsInterface/Common/PHY_IMotionState.cpp b/extern/bullet/Extras/PhysicsInterface/Common/PHY_IMotionState.cpp index b8521ffaf87..1bf92b4effc 100644 --- a/extern/bullet/Extras/PhysicsInterface/Common/PHY_IMotionState.cpp +++ b/extern/bullet/Extras/PhysicsInterface/Common/PHY_IMotionState.cpp @@ -13,10 +13,6 @@ #include "PHY_IMotionState.h" -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - PHY_IMotionState::~PHY_IMotionState() { diff --git a/extern/bullet/Extras/PhysicsInterface/Common/PHY_IPhysicsController.cpp b/extern/bullet/Extras/PhysicsInterface/Common/PHY_IPhysicsController.cpp index b051a45bd13..655763d0bf6 100644 --- a/extern/bullet/Extras/PhysicsInterface/Common/PHY_IPhysicsController.cpp +++ b/extern/bullet/Extras/PhysicsInterface/Common/PHY_IPhysicsController.cpp @@ -13,10 +13,6 @@ #include "PHY_IPhysicsController.h" -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - PHY_IPhysicsController::~PHY_IPhysicsController() { diff --git a/extern/bullet/Extras/PhysicsInterface/Common/PHY_IPhysicsEnvironment.cpp b/extern/bullet/Extras/PhysicsInterface/Common/PHY_IPhysicsEnvironment.cpp index 1794606edf3..f59efad561a 100644 --- a/extern/bullet/Extras/PhysicsInterface/Common/PHY_IPhysicsEnvironment.cpp +++ b/extern/bullet/Extras/PhysicsInterface/Common/PHY_IPhysicsEnvironment.cpp @@ -13,10 +13,6 @@ #include "PHY_IPhysicsEnvironment.h" -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - /** * Physics Environment takes care of stepping the simulation and is a container for physics entities (rigidbodies,constraints, materials etc.) * A derived class may be able to 'construct' entities by loading and/or converting diff --git a/extern/bullet/LinearMath/AabbUtil2.h b/extern/bullet/LinearMath/AabbUtil2.h index 27172f93139..77271e13202 100644 --- a/extern/bullet/LinearMath/AabbUtil2.h +++ b/extern/bullet/LinearMath/AabbUtil2.h @@ -64,4 +64,5 @@ SIMD_FORCE_INLINE bool TestTriangleAgainstAabb2(const SimdVector3 *vertices, return true; } -#endif
\ No newline at end of file +#endif + diff --git a/extern/bullet/LinearMath/IDebugDraw.h b/extern/bullet/LinearMath/IDebugDraw.h index be2e421a77e..7734eccf510 100644 --- a/extern/bullet/LinearMath/IDebugDraw.h +++ b/extern/bullet/LinearMath/IDebugDraw.h @@ -57,4 +57,5 @@ class IDebugDraw }; -#endif //IDEBUG_DRAW__H
\ No newline at end of file +#endif //IDEBUG_DRAW__H + diff --git a/extern/bullet/LinearMath/SimdQuadWord.h b/extern/bullet/LinearMath/SimdQuadWord.h index 492981fb303..a9967682d61 100644 --- a/extern/bullet/LinearMath/SimdQuadWord.h +++ b/extern/bullet/LinearMath/SimdQuadWord.h @@ -109,6 +109,38 @@ class SimdQuadWord } + SIMD_FORCE_INLINE void setMax(const SimdQuadWord& other) + { + if (other.m_x > m_x) + m_x = other.m_x; + + if (other.m_y > m_y) + m_y = other.m_y; + + if (other.m_z > m_z) + m_z = other.m_z; + + if (other.m_unusedW > m_unusedW) + m_unusedW = other.m_unusedW; + } + + SIMD_FORCE_INLINE void setMin(const SimdQuadWord& other) + { + if (other.m_x < m_x) + m_x = other.m_x; + + if (other.m_y < m_y) + m_y = other.m_y; + + if (other.m_z < m_z) + m_z = other.m_z; + + if (other.m_unusedW < m_unusedW) + m_unusedW = other.m_unusedW; + } + + + }; #endif //SIMD_QUADWORD_H diff --git a/extern/bullet/LinearMath/SimdScalar.h b/extern/bullet/LinearMath/SimdScalar.h index 4ea359db1b6..f20de0d06d9 100644 --- a/extern/bullet/LinearMath/SimdScalar.h +++ b/extern/bullet/LinearMath/SimdScalar.h @@ -39,7 +39,8 @@ DEALINGS IN THE SOFTWARE. #include <float.h> #ifdef WIN32 - +#pragma warning(disable:4530) +#pragma warning(disable:4996) #ifdef __MINGW32__ #define SIMD_FORCE_INLINE inline #else @@ -59,8 +60,6 @@ DEALINGS IN THE SOFTWARE. #endif - - #define ASSERT assert #endif @@ -119,6 +118,16 @@ SIMD_FORCE_INLINE bool SimdEqual(SimdScalar a, SimdScalar eps) { SIMD_FORCE_INLINE bool SimdGreaterEqual (SimdScalar a, SimdScalar eps) { return (!((a) <= eps)); } + +/*SIMD_FORCE_INLINE SimdScalar SimdCos(SimdScalar x) { return cosf(x); } +SIMD_FORCE_INLINE SimdScalar SimdSin(SimdScalar x) { return sinf(x); } +SIMD_FORCE_INLINE SimdScalar SimdTan(SimdScalar x) { return tanf(x); } +SIMD_FORCE_INLINE SimdScalar SimdAcos(SimdScalar x) { return acosf(x); } +SIMD_FORCE_INLINE SimdScalar SimdAsin(SimdScalar x) { return asinf(x); } +SIMD_FORCE_INLINE SimdScalar SimdAtan(SimdScalar x) { return atanf(x); } +SIMD_FORCE_INLINE SimdScalar SimdAtan2(SimdScalar x, SimdScalar y) { return atan2f(x, y); } +*/ + SIMD_FORCE_INLINE int SimdSign(SimdScalar x) { return x < 0.0f ? -1 : x > 0.0f ? 1 : 0; } diff --git a/extern/bullet/LinearMath/SimdTransformUtil.h b/extern/bullet/LinearMath/SimdTransformUtil.h index 179e2f51daa..ab3d3f45a30 100644 --- a/extern/bullet/LinearMath/SimdTransformUtil.h +++ b/extern/bullet/LinearMath/SimdTransformUtil.h @@ -91,4 +91,5 @@ public: }; -#endif //SIMD_TRANSFORM_UTIL_H
\ No newline at end of file +#endif //SIMD_TRANSFORM_UTIL_H + |