Remove unnecessary collision margin for some shapes
This commit is contained in:
parent
8bab9c1348
commit
946e62dd4b
|
@ -65,9 +65,6 @@ ContactManifold::~ContactManifold() {
|
||||||
|
|
||||||
ContactPoint* nextContactPoint = contactPoint->getNext();
|
ContactPoint* nextContactPoint = contactPoint->getNext();
|
||||||
|
|
||||||
// TODO : Delete this
|
|
||||||
bool test = mMemoryAllocator.isReleaseNeeded();
|
|
||||||
|
|
||||||
// Delete the contact point
|
// Delete the contact point
|
||||||
contactPoint->~ContactPoint();
|
contactPoint->~ContactPoint();
|
||||||
mMemoryAllocator.release(contactPoint, sizeof(ContactPoint));
|
mMemoryAllocator.release(contactPoint, sizeof(ContactPoint));
|
||||||
|
|
|
@ -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
|
// Create a triangle collision shape (the allocated memory for the TriangleShape will be released in the
|
||||||
// destructor of the corresponding NarrowPhaseInfo.
|
// destructor of the corresponding NarrowPhaseInfo.
|
||||||
decimal margin = mConcaveShape->getTriangleMargin();
|
|
||||||
TriangleShape* triangleShape = new (mAllocator.allocate(sizeof(TriangleShape)))
|
TriangleShape* triangleShape = new (mAllocator.allocate(sizeof(TriangleShape)))
|
||||||
TriangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2],
|
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
|
// Create a narrow phase info for the narrow-phase collision detection
|
||||||
NarrowPhaseInfo* firstNarrowPhaseInfo = narrowPhaseInfoList;
|
NarrowPhaseInfo* firstNarrowPhaseInfo = narrowPhaseInfoList;
|
||||||
|
|
|
@ -37,11 +37,11 @@ using namespace reactphysics3d;
|
||||||
* @param extent The vector with the three extents of the box (in meters)
|
* @param extent The vector with the three extents of the box (in meters)
|
||||||
* @param margin The collision margin (in meters) around the collision shape
|
* @param margin The collision margin (in meters) around the collision shape
|
||||||
*/
|
*/
|
||||||
BoxShape::BoxShape(const Vector3& extent, decimal margin)
|
BoxShape::BoxShape(const Vector3& extent)
|
||||||
: ConvexPolyhedronShape(CollisionShapeName::BOX, margin), mExtent(extent - Vector3(margin, margin, margin)) {
|
: ConvexPolyhedronShape(CollisionShapeName::BOX), mExtent(extent) {
|
||||||
assert(extent.x > decimal(0.0) && extent.x > margin);
|
assert(extent.x > decimal(0.0));
|
||||||
assert(extent.y > decimal(0.0) && extent.y > margin);
|
assert(extent.y > decimal(0.0));
|
||||||
assert(extent.z > decimal(0.0) && extent.z > margin);
|
assert(extent.z > decimal(0.0));
|
||||||
|
|
||||||
// Vertices
|
// Vertices
|
||||||
mHalfEdgeStructure.addVertex(0);
|
mHalfEdgeStructure.addVertex(0);
|
||||||
|
|
|
@ -81,7 +81,7 @@ class BoxShape : public ConvexPolyhedronShape {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
BoxShape(const Vector3& extent, decimal margin = OBJECT_MARGIN);
|
BoxShape(const Vector3& extent);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~BoxShape() override = default;
|
virtual ~BoxShape() override = default;
|
||||||
|
|
|
@ -59,7 +59,6 @@ void ConcaveMeshShape::initBVHTree() {
|
||||||
|
|
||||||
// Create the AABB for the triangle
|
// Create the AABB for the triangle
|
||||||
AABB aabb = AABB::createAABBForTriangle(trianglePoints);
|
AABB aabb = AABB::createAABBForTriangle(trianglePoints);
|
||||||
aabb.inflate(mTriangleMargin, mTriangleMargin, mTriangleMargin);
|
|
||||||
|
|
||||||
// Add the AABB with the index of the triangle into the dynamic AABB tree
|
// Add the AABB with the index of the triangle into the dynamic AABB tree
|
||||||
mDynamicAABBTree.addObject(aabb, subPart, triangleIndex);
|
mDynamicAABBTree.addObject(aabb, subPart, triangleIndex);
|
||||||
|
@ -152,9 +151,8 @@ void ConcaveMeshRaycastCallback::raycastTriangles() {
|
||||||
Vector3 verticesNormals[3];
|
Vector3 verticesNormals[3];
|
||||||
mConcaveMeshShape.getTriangleVerticesNormals(data[0], data[1], verticesNormals);
|
mConcaveMeshShape.getTriangleVerticesNormals(data[0], data[1], verticesNormals);
|
||||||
// Create a triangle collision shape
|
// Create a triangle collision shape
|
||||||
decimal margin = mConcaveMeshShape.getTriangleMargin();
|
|
||||||
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2],
|
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2],
|
||||||
verticesNormals, data[0], data[1], margin);
|
verticesNormals, data[0], data[1]);
|
||||||
triangleShape.setRaycastTestType(mConcaveMeshShape.getRaycastTestType());
|
triangleShape.setRaycastTestType(mConcaveMeshShape.getRaycastTestType());
|
||||||
|
|
||||||
// Ray casting test against the collision shape
|
// Ray casting test against the collision shape
|
||||||
|
|
|
@ -32,6 +32,6 @@ using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ConcaveShape::ConcaveShape(CollisionShapeName name)
|
ConcaveShape::ConcaveShape(CollisionShapeName name)
|
||||||
: CollisionShape(name, CollisionShapeType::CONCAVE_SHAPE), mTriangleMargin(0), mRaycastTestType(TriangleRaycastSide::FRONT) {
|
: CollisionShape(name, CollisionShapeType::CONCAVE_SHAPE), mRaycastTestType(TriangleRaycastSide::FRONT) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,6 @@ class ConcaveShape : public CollisionShape {
|
||||||
|
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
// Margin use for collision detection for each triangle
|
|
||||||
decimal mTriangleMargin;
|
|
||||||
|
|
||||||
/// Raycast test type for the triangle (front, back, front-back)
|
/// Raycast test type for the triangle (front, back, front-back)
|
||||||
TriangleRaycastSide mRaycastTestType;
|
TriangleRaycastSide mRaycastTestType;
|
||||||
|
|
||||||
|
@ -90,9 +87,6 @@ class ConcaveShape : public CollisionShape {
|
||||||
/// Deleted assignment operator
|
/// Deleted assignment operator
|
||||||
ConcaveShape& operator=(const ConcaveShape& shape) = delete;
|
ConcaveShape& operator=(const ConcaveShape& shape) = delete;
|
||||||
|
|
||||||
/// Return the triangle margin
|
|
||||||
decimal getTriangleMargin() const;
|
|
||||||
|
|
||||||
/// Return the raycast test type (front, back, front-back)
|
/// Return the raycast test type (front, back, front-back)
|
||||||
TriangleRaycastSide getRaycastTestType() const;
|
TriangleRaycastSide getRaycastTestType() const;
|
||||||
|
|
||||||
|
@ -109,11 +103,6 @@ class ConcaveShape : public CollisionShape {
|
||||||
virtual void testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const=0;
|
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
|
// Return true if the collision shape is convex, false if it is concave
|
||||||
inline bool ConcaveShape::isConvex() const {
|
inline bool ConcaveShape::isConvex() const {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -41,8 +41,8 @@ using namespace reactphysics3d;
|
||||||
* @param stride Stride between the beginning of two elements in the vertices array
|
* @param stride Stride between the beginning of two elements in the vertices array
|
||||||
* @param margin Collision margin (in meters) around the collision shape
|
* @param margin Collision margin (in meters) around the collision shape
|
||||||
*/
|
*/
|
||||||
ConvexMeshShape::ConvexMeshShape(PolyhedronMesh* polyhedronMesh, decimal margin)
|
ConvexMeshShape::ConvexMeshShape(PolyhedronMesh* polyhedronMesh)
|
||||||
: ConvexPolyhedronShape(CollisionShapeName::CONVEX_MESH, margin), mPolyhedronMesh(polyhedronMesh), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0) {
|
: ConvexPolyhedronShape(CollisionShapeName::CONVEX_MESH), mPolyhedronMesh(polyhedronMesh), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0) {
|
||||||
|
|
||||||
// Recalculate the bounds of the mesh
|
// Recalculate the bounds of the mesh
|
||||||
recalculateBounds();
|
recalculateBounds();
|
||||||
|
|
|
@ -99,9 +99,7 @@ class ConvexMeshShape : public ConvexPolyhedronShape {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
// TODO : Do we really need to use the margin anymore ? Maybe for raycasting ? If not, remove all the
|
ConvexMeshShape(PolyhedronMesh* polyhedronMesh);
|
||||||
// comments documentation about margin
|
|
||||||
ConvexMeshShape(PolyhedronMesh* polyhedronMesh, decimal margin = OBJECT_MARGIN);
|
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~ConvexMeshShape() override = default;
|
virtual ~ConvexMeshShape() override = default;
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ConvexPolyhedronShape::ConvexPolyhedronShape(CollisionShapeName name, decimal margin)
|
ConvexPolyhedronShape::ConvexPolyhedronShape(CollisionShapeName name)
|
||||||
: ConvexShape(name, CollisionShapeType::CONVEX_POLYHEDRON, margin) {
|
: ConvexShape(name, CollisionShapeType::CONVEX_POLYHEDRON) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class ConvexPolyhedronShape : public ConvexShape {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
ConvexPolyhedronShape(CollisionShapeName name, decimal margin);
|
ConvexPolyhedronShape(CollisionShapeName name);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~ConvexPolyhedronShape() override = default;
|
virtual ~ConvexPolyhedronShape() override = default;
|
||||||
|
|
|
@ -59,7 +59,7 @@ class ConvexShape : public CollisionShape {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
ConvexShape(CollisionShapeName name, CollisionShapeType type, decimal margin);
|
ConvexShape(CollisionShapeName name, CollisionShapeType type, decimal margin = decimal(0.0));
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~ConvexShape() override = default;
|
virtual ~ConvexShape() override = default;
|
||||||
|
|
|
@ -260,9 +260,8 @@ void TriangleOverlapCallback::testTriangle(uint meshSubPart, uint triangleIndex,
|
||||||
const Vector3* verticesNormals) {
|
const Vector3* verticesNormals) {
|
||||||
|
|
||||||
// Create a triangle collision shape
|
// Create a triangle collision shape
|
||||||
decimal margin = mHeightFieldShape.getTriangleMargin();
|
|
||||||
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2],
|
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2],
|
||||||
verticesNormals, meshSubPart, triangleIndex, margin);
|
verticesNormals, meshSubPart, triangleIndex);
|
||||||
triangleShape.setRaycastTestType(mHeightFieldShape.getRaycastTestType());
|
triangleShape.setRaycastTestType(mHeightFieldShape.getRaycastTestType());
|
||||||
|
|
||||||
// Ray casting test against the collision shape
|
// Ray casting test against the collision shape
|
||||||
|
|
|
@ -44,8 +44,8 @@ using namespace reactphysics3d;
|
||||||
* @param margin The collision margin (in meters) around the collision shape
|
* @param margin The collision margin (in meters) around the collision shape
|
||||||
*/
|
*/
|
||||||
TriangleShape::TriangleShape(const Vector3& point1, const Vector3& point2, const Vector3& point3,
|
TriangleShape::TriangleShape(const Vector3& point1, const Vector3& point2, const Vector3& point3,
|
||||||
const Vector3* verticesNormals, uint meshSubPart, uint triangleIndex, decimal margin)
|
const Vector3* verticesNormals, uint meshSubPart, uint triangleIndex)
|
||||||
: ConvexPolyhedronShape(CollisionShapeName::TRIANGLE, margin), mMeshSubPart(meshSubPart), mTriangleIndex(triangleIndex) {
|
: ConvexPolyhedronShape(CollisionShapeName::TRIANGLE), mMeshSubPart(meshSubPart), mTriangleIndex(triangleIndex) {
|
||||||
|
|
||||||
mPoints[0] = point1;
|
mPoints[0] = point1;
|
||||||
mPoints[1] = point2;
|
mPoints[1] = point2;
|
||||||
|
|
|
@ -108,7 +108,7 @@ class TriangleShape : public ConvexPolyhedronShape {
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
TriangleShape(const Vector3& point1, const Vector3& point2, const Vector3& point3,
|
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
|
/// Destructor
|
||||||
virtual ~TriangleShape() override = default;
|
virtual ~TriangleShape() override = default;
|
||||||
|
|
|
@ -100,9 +100,6 @@ constexpr decimal DEFAULT_ROLLING_RESISTANCE = decimal(0.0);
|
||||||
/// True if the spleeping technique is enabled
|
/// True if the spleeping technique is enabled
|
||||||
constexpr bool SPLEEPING_ENABLED = true;
|
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)
|
/// Distance threshold for two contact points for a valid persistent contact (in meters)
|
||||||
constexpr decimal PERSISTENT_CONTACT_DIST_THRESHOLD = decimal(0.03);
|
constexpr decimal PERSISTENT_CONTACT_DIST_THRESHOLD = decimal(0.03);
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ class TestPointInside : public Test {
|
||||||
mLocalShapeToWorld = mBodyTransform * mShapeTransform;
|
mLocalShapeToWorld = mBodyTransform * mShapeTransform;
|
||||||
|
|
||||||
// Create collision shapes
|
// Create collision shapes
|
||||||
mBoxShape = new BoxShape(Vector3(2, 3, 4), 0);
|
mBoxShape = new BoxShape(Vector3(2, 3, 4));
|
||||||
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform);
|
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform);
|
||||||
|
|
||||||
mSphereShape = new SphereShape(3);
|
mSphereShape = new SphereShape(3);
|
||||||
|
|
|
@ -192,7 +192,7 @@ class TestRaycast : public Test {
|
||||||
mLocalShapeToWorld = mBodyTransform * mShapeTransform;
|
mLocalShapeToWorld = mBodyTransform * mShapeTransform;
|
||||||
|
|
||||||
// Create collision shapes
|
// Create collision shapes
|
||||||
mBoxShape = new BoxShape(Vector3(2, 3, 4), 0);
|
mBoxShape = new BoxShape(Vector3(2, 3, 4));
|
||||||
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform);
|
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform);
|
||||||
|
|
||||||
mSphereShape = new SphereShape(3);
|
mSphereShape = new SphereShape(3);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user