diff --git a/Demos/OpenGL/GL_ShapeDrawer.cpp b/Demos/OpenGL/GL_ShapeDrawer.cpp index 277a4e9f6..e4892744e 100644 --- a/Demos/OpenGL/GL_ShapeDrawer.cpp +++ b/Demos/OpenGL/GL_ShapeDrawer.cpp @@ -165,7 +165,7 @@ void OGL_displaylist_register_shape(btCollisionShape * shape) if (shape->isConcave()) { - ConcaveShape* concaveMesh = (ConcaveShape*) shape; + btConcaveShape* concaveMesh = (btConcaveShape*) shape; //todo pass camera, for some culling concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax); } @@ -470,7 +470,7 @@ void GL_ShapeDrawer::drawOpenGL(float* m, const btCollisionShape* shape, const b if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE) // if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) { - ConcaveShape* concaveMesh = (btTriangleMeshShape*) shape; + btConcaveShape* concaveMesh = (btTriangleMeshShape*) shape; //btVector3 aabbMax(1e30f,1e30f,1e30f); //btVector3 aabbMax(100,100,100);//1e30f,1e30f,1e30f); diff --git a/Extras/GIMPACTBullet/btConcaveConcaveCollisionAlgorithm.cpp b/Extras/GIMPACTBullet/btConcaveConcaveCollisionAlgorithm.cpp index 5e0163eb9..c83378ac3 100644 --- a/Extras/GIMPACTBullet/btConcaveConcaveCollisionAlgorithm.cpp +++ b/Extras/GIMPACTBullet/btConcaveConcaveCollisionAlgorithm.cpp @@ -332,8 +332,8 @@ void bt_concave_concave_collision(btConcaveConcaveCollisionAlgorithm * algorithm btCollisionObject* tribody1, btManifoldResult* resultOut) { - ConcaveShape* tri0b = static_cast( tribody0->getCollisionShape()); - ConcaveShape* tri1b = static_cast( tribody1->getCollisionShape()); + btConcaveShape* tri0b = static_cast( tribody0->getCollisionShape()); + btConcaveShape* tri1b = static_cast( tribody1->getCollisionShape()); //Get First AABB btVector3 aabbMin0,aabbMax0; diff --git a/Extras/GIMPACTBullet/btGIMPACTMeshShape.h b/Extras/GIMPACTBullet/btGIMPACTMeshShape.h index 3b4f92999..ce42629a4 100644 --- a/Extras/GIMPACTBullet/btGIMPACTMeshShape.h +++ b/Extras/GIMPACTBullet/btGIMPACTMeshShape.h @@ -65,7 +65,7 @@ public: /// ///Uses an interface to access the triangles to allow for sharing graphics/physics triangles. -class btGIMPACTMeshShape : public ConcaveShape +class btGIMPACTMeshShape : public btConcaveShape { protected: btGIMPACTMeshData * m_meshdata; diff --git a/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h b/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h index 7b35df09d..3ad246788 100644 --- a/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h +++ b/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h @@ -44,6 +44,8 @@ CONCAVE_SHAPES_START_HERE, TRIANGLE_MESH_SHAPE_PROXYTYPE, ///used for demo integration FAST/Swift collision library and Bullet FAST_CONCAVE_MESH_PROXYTYPE, + //terrain + TERRAIN_SHAPE_PROXYTYPE, ///Used for GIMPACT Trimesh integration GIMPACT_SHAPE_PROXYTYPE, diff --git a/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp b/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp index 8ad3967ba..06adb3a04 100644 --- a/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp +++ b/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp @@ -172,7 +172,7 @@ void btConvexConcaveCollisionAlgorithm::processCollision (btCollisionObject* bod btCollisionObject* triOb = triBody; - ConcaveShape* concaveShape = static_cast( triOb->getCollisionShape()); + btConcaveShape* concaveShape = static_cast( triOb->getCollisionShape()); if (convexBody->getCollisionShape()->isConvex()) { @@ -288,7 +288,7 @@ float btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject btCollisionObject* concavebody = triBody; - ConcaveShape* triangleMesh = (ConcaveShape*) concavebody->getCollisionShape(); + btConcaveShape* triangleMesh = (btConcaveShape*) concavebody->getCollisionShape(); if (triangleMesh) { diff --git a/src/BulletCollision/CollisionShapes/btConcaveShape.cpp b/src/BulletCollision/CollisionShapes/btConcaveShape.cpp index 29f62828d..7cd35a918 100644 --- a/src/BulletCollision/CollisionShapes/btConcaveShape.cpp +++ b/src/BulletCollision/CollisionShapes/btConcaveShape.cpp @@ -17,12 +17,12 @@ subject to the following restrictions: #include "btConcaveShape.h" -ConcaveShape::ConcaveShape() : m_collisionMargin(0.f) +btConcaveShape::btConcaveShape() : m_collisionMargin(0.f) { } -ConcaveShape::~ConcaveShape() +btConcaveShape::~btConcaveShape() { } diff --git a/src/BulletCollision/CollisionShapes/btConcaveShape.h b/src/BulletCollision/CollisionShapes/btConcaveShape.h index 304654531..2bbba88bc 100644 --- a/src/BulletCollision/CollisionShapes/btConcaveShape.h +++ b/src/BulletCollision/CollisionShapes/btConcaveShape.h @@ -24,15 +24,15 @@ subject to the following restrictions: ///Concave shape proves an interface concave shapes that can produce triangles that overlapping a given AABB. ///Static triangle mesh, infinite plane, height field/landscapes are example that implement this interface. -class ConcaveShape : public btCollisionShape +class btConcaveShape : public btCollisionShape { protected: float m_collisionMargin; public: - ConcaveShape(); + btConcaveShape(); - virtual ~ConcaveShape(); + virtual ~btConcaveShape(); virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const = 0; diff --git a/src/BulletCollision/CollisionShapes/btEmptyShape.h b/src/BulletCollision/CollisionShapes/btEmptyShape.h index c92f42cde..c16149e55 100644 --- a/src/BulletCollision/CollisionShapes/btEmptyShape.h +++ b/src/BulletCollision/CollisionShapes/btEmptyShape.h @@ -29,7 +29,7 @@ subject to the following restrictions: /// btEmptyShape is a collision shape without actual collision detection. ///It can be replaced by another shape during runtime -class btEmptyShape : public ConcaveShape +class btEmptyShape : public btConcaveShape { public: btEmptyShape(); diff --git a/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp new file mode 100644 index 000000000..6462ad55a --- /dev/null +++ b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp @@ -0,0 +1,92 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "btHeightfieldTerrainShape.h" + +#include "LinearMath/btTransformUtil.h" + + +btHeightfieldTerrainShape::btHeightfieldTerrainShape() +:m_localScaling(0.f,0.f,0.f) +{ +} + + +btHeightfieldTerrainShape::~btHeightfieldTerrainShape() +{ +} + + + +void btHeightfieldTerrainShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const +{ + aabbMin.setValue(-1e30f,-1e30f,-1e30f); + aabbMax.setValue(1e30f,1e30f,1e30f); + +} + + + + +void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const +{ + + btVector3 halfExtents = (aabbMax - aabbMin) * 0.5f; + btScalar radius = halfExtents.length(); + btVector3 center = (aabbMax + aabbMin) * 0.5f; + + //TODO + //this is where the triangles are generated, given AABB and plane equation (normal/constant) +/* + btVector3 tangentDir0,tangentDir1; + + //tangentDir0/tangentDir1 can be precalculated + btPlaneSpace1(m_planeNormal,tangentDir0,tangentDir1); + + btVector3 supVertex0,supVertex1; + + btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal; + + btVector3 triangle[3]; + 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,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); +*/ + +} + +void btHeightfieldTerrainShape::calculateLocalInertia(btScalar mass,btVector3& inertia) +{ + //moving concave objects not supported + + inertia.setValue(0.f,0.f,0.f); +} + +void btHeightfieldTerrainShape::setLocalScaling(const btVector3& scaling) +{ + m_localScaling = scaling; +} +const btVector3& btHeightfieldTerrainShape::getLocalScaling() const +{ + return m_localScaling; +} diff --git a/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h new file mode 100644 index 000000000..03f3f0e20 --- /dev/null +++ b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h @@ -0,0 +1,58 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef HEIGHTFIELD_TERRAIN_SHAPE_H +#define HEIGHTFIELD_TERRAIN_SHAPE_H + +#include "BulletCollision/CollisionShapes/btConcaveShape.h" + +///btHeightfieldTerrainShape simulates a 2D heightfield terrain +class btHeightfieldTerrainShape : public btConcaveShape +{ +protected: + btVector3 m_localAabbMin; + btVector3 m_localAabbMax; + + //todo: terrain data + + btVector3 m_localScaling; + +public: + btHeightfieldTerrainShape(); + + virtual ~btHeightfieldTerrainShape(); + + + virtual int getShapeType() const + { + return TERRAIN_SHAPE_PROXYTYPE; + } + + virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; + + virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const; + + virtual void calculateLocalInertia(btScalar mass,btVector3& inertia); + + virtual void setLocalScaling(const btVector3& scaling); + + virtual const btVector3& getLocalScaling() const; + + //debugging + virtual char* getName()const {return "HEIGHTFIELD";} + +}; + +#endif //HEIGHTFIELD_TERRAIN_SHAPE_H diff --git a/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h b/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h index 7414d470d..65b30e1ff 100644 --- a/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h +++ b/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h @@ -21,7 +21,7 @@ subject to the following restrictions: ///StaticPlaneShape simulates an 'infinite' plane by dynamically reporting triangles approximated by intersection of the plane with the AABB. ///Assumed is that the other objects is not also infinite, so a reasonable sized AABB. -class btStaticPlaneShape : public ConcaveShape +class btStaticPlaneShape : public btConcaveShape { protected: btVector3 m_localAabbMin; diff --git a/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h b/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h index 81cb1412d..4bf000f0c 100644 --- a/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h +++ b/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h @@ -21,7 +21,7 @@ subject to the following restrictions: ///Concave triangle mesh. Uses an interface to access the triangles to allow for sharing graphics/physics triangles. -class btTriangleMeshShape : public ConcaveShape +class btTriangleMeshShape : public btConcaveShape { protected: btStridingMeshInterface* m_meshInterface;