Remove unnecessary collision margin for some shapes

This commit is contained in:
Daniel Chappuis 2017-09-03 19:06:02 +02:00
parent 8bab9c1348
commit 946e62dd4b
18 changed files with 22 additions and 45 deletions

View File

@ -65,9 +65,6 @@ ContactManifold::~ContactManifold() {
ContactPoint* nextContactPoint = contactPoint->getNext();
// TODO : Delete this
bool test = mMemoryAllocator.isReleaseNeeded();
// Delete the contact point
contactPoint->~ContactPoint();
mMemoryAllocator.release(contactPoint, sizeof(ContactPoint));

View File

@ -34,10 +34,9 @@ void MiddlePhaseTriangleCallback::testTriangle(uint meshSubPart, uint triangleIn
// Create a triangle collision shape (the allocated memory for the TriangleShape will be released in the
// destructor of the corresponding NarrowPhaseInfo.
decimal margin = mConcaveShape->getTriangleMargin();
TriangleShape* triangleShape = new (mAllocator.allocate(sizeof(TriangleShape)))
TriangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2],
verticesNormals, meshSubPart, triangleIndex, margin);
verticesNormals, meshSubPart, triangleIndex);
// Create a narrow phase info for the narrow-phase collision detection
NarrowPhaseInfo* firstNarrowPhaseInfo = narrowPhaseInfoList;

View File

@ -37,11 +37,11 @@ using namespace reactphysics3d;
* @param extent The vector with the three extents of the box (in meters)
* @param margin The collision margin (in meters) around the collision shape
*/
BoxShape::BoxShape(const Vector3& extent, decimal margin)
: ConvexPolyhedronShape(CollisionShapeName::BOX, margin), mExtent(extent - Vector3(margin, margin, margin)) {
assert(extent.x > decimal(0.0) && extent.x > margin);
assert(extent.y > decimal(0.0) && extent.y > margin);
assert(extent.z > decimal(0.0) && extent.z > margin);
BoxShape::BoxShape(const Vector3& extent)
: ConvexPolyhedronShape(CollisionShapeName::BOX), mExtent(extent) {
assert(extent.x > decimal(0.0));
assert(extent.y > decimal(0.0));
assert(extent.z > decimal(0.0));
// Vertices
mHalfEdgeStructure.addVertex(0);

View File

@ -81,7 +81,7 @@ class BoxShape : public ConvexPolyhedronShape {
// -------------------- Methods -------------------- //
/// Constructor
BoxShape(const Vector3& extent, decimal margin = OBJECT_MARGIN);
BoxShape(const Vector3& extent);
/// Destructor
virtual ~BoxShape() override = default;

View File

@ -59,7 +59,6 @@ void ConcaveMeshShape::initBVHTree() {
// Create the AABB for the triangle
AABB aabb = AABB::createAABBForTriangle(trianglePoints);
aabb.inflate(mTriangleMargin, mTriangleMargin, mTriangleMargin);
// Add the AABB with the index of the triangle into the dynamic AABB tree
mDynamicAABBTree.addObject(aabb, subPart, triangleIndex);
@ -152,9 +151,8 @@ void ConcaveMeshRaycastCallback::raycastTriangles() {
Vector3 verticesNormals[3];
mConcaveMeshShape.getTriangleVerticesNormals(data[0], data[1], verticesNormals);
// Create a triangle collision shape
decimal margin = mConcaveMeshShape.getTriangleMargin();
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2],
verticesNormals, data[0], data[1], margin);
verticesNormals, data[0], data[1]);
triangleShape.setRaycastTestType(mConcaveMeshShape.getRaycastTestType());
// Ray casting test against the collision shape

View File

@ -32,6 +32,6 @@ using namespace reactphysics3d;
// Constructor
ConcaveShape::ConcaveShape(CollisionShapeName name)
: CollisionShape(name, CollisionShapeType::CONCAVE_SHAPE), mTriangleMargin(0), mRaycastTestType(TriangleRaycastSide::FRONT) {
: CollisionShape(name, CollisionShapeType::CONCAVE_SHAPE), mRaycastTestType(TriangleRaycastSide::FRONT) {
}

View File

@ -63,9 +63,6 @@ class ConcaveShape : public CollisionShape {
// -------------------- Attributes -------------------- //
// Margin use for collision detection for each triangle
decimal mTriangleMargin;
/// Raycast test type for the triangle (front, back, front-back)
TriangleRaycastSide mRaycastTestType;
@ -90,9 +87,6 @@ class ConcaveShape : public CollisionShape {
/// Deleted assignment operator
ConcaveShape& operator=(const ConcaveShape& shape) = delete;
/// Return the triangle margin
decimal getTriangleMargin() const;
/// Return the raycast test type (front, back, front-back)
TriangleRaycastSide getRaycastTestType() const;
@ -109,11 +103,6 @@ class ConcaveShape : public CollisionShape {
virtual void testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const=0;
};
// Return the triangle margin
inline decimal ConcaveShape::getTriangleMargin() const {
return mTriangleMargin;
}
// Return true if the collision shape is convex, false if it is concave
inline bool ConcaveShape::isConvex() const {
return false;

View File

@ -41,8 +41,8 @@ using namespace reactphysics3d;
* @param stride Stride between the beginning of two elements in the vertices array
* @param margin Collision margin (in meters) around the collision shape
*/
ConvexMeshShape::ConvexMeshShape(PolyhedronMesh* polyhedronMesh, decimal margin)
: ConvexPolyhedronShape(CollisionShapeName::CONVEX_MESH, margin), mPolyhedronMesh(polyhedronMesh), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0) {
ConvexMeshShape::ConvexMeshShape(PolyhedronMesh* polyhedronMesh)
: ConvexPolyhedronShape(CollisionShapeName::CONVEX_MESH), mPolyhedronMesh(polyhedronMesh), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0) {
// Recalculate the bounds of the mesh
recalculateBounds();

View File

@ -99,9 +99,7 @@ class ConvexMeshShape : public ConvexPolyhedronShape {
// -------------------- Methods -------------------- //
/// Constructor
// TODO : Do we really need to use the margin anymore ? Maybe for raycasting ? If not, remove all the
// comments documentation about margin
ConvexMeshShape(PolyhedronMesh* polyhedronMesh, decimal margin = OBJECT_MARGIN);
ConvexMeshShape(PolyhedronMesh* polyhedronMesh);
/// Destructor
virtual ~ConvexMeshShape() override = default;

View File

@ -31,7 +31,7 @@
using namespace reactphysics3d;
// Constructor
ConvexPolyhedronShape::ConvexPolyhedronShape(CollisionShapeName name, decimal margin)
: ConvexShape(name, CollisionShapeType::CONVEX_POLYHEDRON, margin) {
ConvexPolyhedronShape::ConvexPolyhedronShape(CollisionShapeName name)
: ConvexShape(name, CollisionShapeType::CONVEX_POLYHEDRON) {
}

View File

@ -47,7 +47,7 @@ class ConvexPolyhedronShape : public ConvexShape {
// -------------------- Methods -------------------- //
/// Constructor
ConvexPolyhedronShape(CollisionShapeName name, decimal margin);
ConvexPolyhedronShape(CollisionShapeName name);
/// Destructor
virtual ~ConvexPolyhedronShape() override = default;

View File

@ -59,7 +59,7 @@ class ConvexShape : public CollisionShape {
// -------------------- Methods -------------------- //
/// Constructor
ConvexShape(CollisionShapeName name, CollisionShapeType type, decimal margin);
ConvexShape(CollisionShapeName name, CollisionShapeType type, decimal margin = decimal(0.0));
/// Destructor
virtual ~ConvexShape() override = default;

View File

@ -260,9 +260,8 @@ void TriangleOverlapCallback::testTriangle(uint meshSubPart, uint triangleIndex,
const Vector3* verticesNormals) {
// Create a triangle collision shape
decimal margin = mHeightFieldShape.getTriangleMargin();
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2],
verticesNormals, meshSubPart, triangleIndex, margin);
verticesNormals, meshSubPart, triangleIndex);
triangleShape.setRaycastTestType(mHeightFieldShape.getRaycastTestType());
// Ray casting test against the collision shape

View File

@ -44,8 +44,8 @@ using namespace reactphysics3d;
* @param margin The collision margin (in meters) around the collision shape
*/
TriangleShape::TriangleShape(const Vector3& point1, const Vector3& point2, const Vector3& point3,
const Vector3* verticesNormals, uint meshSubPart, uint triangleIndex, decimal margin)
: ConvexPolyhedronShape(CollisionShapeName::TRIANGLE, margin), mMeshSubPart(meshSubPart), mTriangleIndex(triangleIndex) {
const Vector3* verticesNormals, uint meshSubPart, uint triangleIndex)
: ConvexPolyhedronShape(CollisionShapeName::TRIANGLE), mMeshSubPart(meshSubPart), mTriangleIndex(triangleIndex) {
mPoints[0] = point1;
mPoints[1] = point2;

View File

@ -108,7 +108,7 @@ class TriangleShape : public ConvexPolyhedronShape {
/// Constructor
TriangleShape(const Vector3& point1, const Vector3& point2, const Vector3& point3,
const Vector3* verticesNormals, uint meshSubPart, uint triangleIndex, decimal margin = OBJECT_MARGIN);
const Vector3* verticesNormals, uint meshSubPart, uint triangleIndex);
/// Destructor
virtual ~TriangleShape() override = default;

View File

@ -100,9 +100,6 @@ constexpr decimal DEFAULT_ROLLING_RESISTANCE = decimal(0.0);
/// True if the spleeping technique is enabled
constexpr bool SPLEEPING_ENABLED = true;
/// Object margin for collision detection in meters (for the GJK-EPA Algorithm)
constexpr decimal OBJECT_MARGIN = decimal(0.04);
/// Distance threshold for two contact points for a valid persistent contact (in meters)
constexpr decimal PERSISTENT_CONTACT_DIST_THRESHOLD = decimal(0.03);

View File

@ -115,7 +115,7 @@ class TestPointInside : public Test {
mLocalShapeToWorld = mBodyTransform * mShapeTransform;
// Create collision shapes
mBoxShape = new BoxShape(Vector3(2, 3, 4), 0);
mBoxShape = new BoxShape(Vector3(2, 3, 4));
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform);
mSphereShape = new SphereShape(3);

View File

@ -192,7 +192,7 @@ class TestRaycast : public Test {
mLocalShapeToWorld = mBodyTransform * mShapeTransform;
// Create collision shapes
mBoxShape = new BoxShape(Vector3(2, 3, 4), 0);
mBoxShape = new BoxShape(Vector3(2, 3, 4));
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform);
mSphereShape = new SphereShape(3);