Modificaitons in ConcaveMeshShape
This commit is contained in:
parent
b7769e5211
commit
ec3a9cef87
|
@ -68,10 +68,12 @@ void ConcaveVsConvexAlgorithm::testCollision(const CollisionShapeInfo& shape1Inf
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the parameters of the callback object
|
// Set the parameters of the callback object
|
||||||
mConvexVsTriangleCallback.setCollisionDetection(mCollisionDetection);
|
ConvexVsTriangleCallback convexVsTriangleCallback;
|
||||||
mConvexVsTriangleCallback.setConvexShape(convexShape);
|
convexVsTriangleCallback.setCollisionDetection(mCollisionDetection);
|
||||||
mConvexVsTriangleCallback.setProxyShapes(convexProxyShape, concaveProxyShape);
|
convexVsTriangleCallback.setConvexShape(convexShape);
|
||||||
mConvexVsTriangleCallback.setOverlappingPair(shape1Info.overlappingPair);
|
convexVsTriangleCallback.setConcaveShape(concaveShape);
|
||||||
|
convexVsTriangleCallback.setProxyShapes(convexProxyShape, concaveProxyShape);
|
||||||
|
convexVsTriangleCallback.setOverlappingPair(shape1Info.overlappingPair);
|
||||||
|
|
||||||
// Compute the convex shape AABB in the local-space of the convex shape
|
// Compute the convex shape AABB in the local-space of the convex shape
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
|
@ -84,20 +86,20 @@ void ConcaveVsConvexAlgorithm::testCollision(const CollisionShapeInfo& shape1Inf
|
||||||
|
|
||||||
SmoothCollisionNarrowPhaseCallback smoothNarrowPhaseCallback(contactPoints);
|
SmoothCollisionNarrowPhaseCallback smoothNarrowPhaseCallback(contactPoints);
|
||||||
|
|
||||||
mConvexVsTriangleCallback.setNarrowPhaseCallback(&smoothNarrowPhaseCallback);
|
convexVsTriangleCallback.setNarrowPhaseCallback(&smoothNarrowPhaseCallback);
|
||||||
|
|
||||||
// Call the convex vs triangle callback for each triangle of the concave shape
|
// Call the convex vs triangle callback for each triangle of the concave shape
|
||||||
concaveShape->testAllTriangles(mConvexVsTriangleCallback, aabb);
|
concaveShape->testAllTriangles(convexVsTriangleCallback, aabb);
|
||||||
|
|
||||||
// Run the smooth mesh collision algorithm
|
// Run the smooth mesh collision algorithm
|
||||||
processSmoothMeshCollision(shape1Info.overlappingPair, contactPoints, narrowPhaseCallback);
|
processSmoothMeshCollision(shape1Info.overlappingPair, contactPoints, narrowPhaseCallback);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
mConvexVsTriangleCallback.setNarrowPhaseCallback(narrowPhaseCallback);
|
convexVsTriangleCallback.setNarrowPhaseCallback(narrowPhaseCallback);
|
||||||
|
|
||||||
// Call the convex vs triangle callback for each triangle of the concave shape
|
// Call the convex vs triangle callback for each triangle of the concave shape
|
||||||
concaveShape->testAllTriangles(mConvexVsTriangleCallback, aabb);
|
concaveShape->testAllTriangles(convexVsTriangleCallback, aabb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +107,8 @@ void ConcaveVsConvexAlgorithm::testCollision(const CollisionShapeInfo& shape1Inf
|
||||||
void ConvexVsTriangleCallback::testTriangle(const Vector3* trianglePoints) {
|
void ConvexVsTriangleCallback::testTriangle(const Vector3* trianglePoints) {
|
||||||
|
|
||||||
// Create a triangle collision shape
|
// Create a triangle collision shape
|
||||||
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2]);
|
decimal margin = mConcaveShape->getTriangleMargin();
|
||||||
|
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2], margin);
|
||||||
|
|
||||||
// Select the collision algorithm to use between the triangle and the convex shape
|
// Select the collision algorithm to use between the triangle and the convex shape
|
||||||
NarrowPhaseAlgorithm* algo = mCollisionDetection->getCollisionAlgorithm(triangleShape.getType(),
|
NarrowPhaseAlgorithm* algo = mCollisionDetection->getCollisionAlgorithm(triangleShape.getType(),
|
||||||
|
|
|
@ -54,6 +54,9 @@ class ConvexVsTriangleCallback : public TriangleCallback {
|
||||||
/// Convex collision shape to test collision with
|
/// Convex collision shape to test collision with
|
||||||
const ConvexShape* mConvexShape;
|
const ConvexShape* mConvexShape;
|
||||||
|
|
||||||
|
/// Concave collision shape
|
||||||
|
const ConcaveShape* mConcaveShape;
|
||||||
|
|
||||||
/// Proxy shape of the convex collision shape
|
/// Proxy shape of the convex collision shape
|
||||||
ProxyShape* mConvexProxyShape;
|
ProxyShape* mConvexProxyShape;
|
||||||
|
|
||||||
|
@ -84,6 +87,11 @@ class ConvexVsTriangleCallback : public TriangleCallback {
|
||||||
mConvexShape = convexShape;
|
mConvexShape = convexShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the concave collision shape
|
||||||
|
void setConcaveShape(const ConcaveShape* concaveShape) {
|
||||||
|
mConcaveShape = concaveShape;
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the broadphase overlapping pair
|
/// Set the broadphase overlapping pair
|
||||||
void setOverlappingPair(OverlappingPair* overlappingPair) {
|
void setOverlappingPair(OverlappingPair* overlappingPair) {
|
||||||
mOverlappingPair = overlappingPair;
|
mOverlappingPair = overlappingPair;
|
||||||
|
@ -97,7 +105,6 @@ class ConvexVsTriangleCallback : public TriangleCallback {
|
||||||
|
|
||||||
/// Test collision between a triangle and the convex mesh shape
|
/// Test collision between a triangle and the convex mesh shape
|
||||||
virtual void testTriangle(const Vector3* trianglePoints);
|
virtual void testTriangle(const Vector3* trianglePoints);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class SmoothMeshContactInfo
|
// Class SmoothMeshContactInfo
|
||||||
|
@ -177,10 +184,7 @@ class ConcaveVsConvexAlgorithm : public NarrowPhaseAlgorithm {
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// Convex vs Triangle callback
|
|
||||||
ConvexVsTriangleCallback mConvexVsTriangleCallback;
|
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ConcaveMeshShape::ConcaveMeshShape(TriangleMesh* triangleMesh) : ConcaveShape(CONCAVE_MESH) {
|
ConcaveMeshShape::ConcaveMeshShape(TriangleMesh* triangleMesh)
|
||||||
|
: ConcaveShape(CONCAVE_MESH) {
|
||||||
mTriangleMesh = triangleMesh;
|
mTriangleMesh = triangleMesh;
|
||||||
mRaycastTestType = FRONT;
|
mRaycastTestType = FRONT;
|
||||||
|
|
||||||
|
@ -95,6 +96,7 @@ 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);
|
||||||
|
@ -202,7 +204,8 @@ void ConcaveMeshRaycastCallback::raycastTriangles() {
|
||||||
mConcaveMeshShape.getTriangleVerticesWithIndexPointer(data[0], data[1], trianglePoints);
|
mConcaveMeshShape.getTriangleVerticesWithIndexPointer(data[0], data[1], trianglePoints);
|
||||||
|
|
||||||
// Create a triangle collision shape
|
// Create a triangle collision shape
|
||||||
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2]);
|
decimal margin = mConcaveMeshShape.getTriangleMargin();
|
||||||
|
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2], margin);
|
||||||
triangleShape.setRaycastTestType(mConcaveMeshShape.getRaycastTestType());
|
triangleShape.setRaycastTestType(mConcaveMeshShape.getRaycastTestType());
|
||||||
|
|
||||||
// Ray casting test against the collision shape
|
// Ray casting test against the collision shape
|
||||||
|
|
|
@ -31,8 +31,10 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ConcaveShape::ConcaveShape(CollisionShapeType type) : CollisionShape(type) {
|
ConcaveShape::ConcaveShape(CollisionShapeType type)
|
||||||
mIsSmoothMeshCollisionEnabled = false;
|
: CollisionShape(type), mIsSmoothMeshCollisionEnabled(false),
|
||||||
|
mTriangleMargin(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
|
@ -61,6 +61,9 @@ class ConcaveShape : public CollisionShape {
|
||||||
/// True if the smooth mesh collision algorithm is enabled
|
/// True if the smooth mesh collision algorithm is enabled
|
||||||
bool mIsSmoothMeshCollisionEnabled;
|
bool mIsSmoothMeshCollisionEnabled;
|
||||||
|
|
||||||
|
// Margin use for collision detection for each triangle
|
||||||
|
decimal mTriangleMargin;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Private copy-constructor
|
/// Private copy-constructor
|
||||||
|
@ -82,6 +85,9 @@ class ConcaveShape : public CollisionShape {
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~ConcaveShape();
|
virtual ~ConcaveShape();
|
||||||
|
|
||||||
|
/// Return the triangle margin
|
||||||
|
decimal getTriangleMargin() const;
|
||||||
|
|
||||||
/// 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
|
||||||
virtual bool isConvex() const;
|
virtual bool isConvex() const;
|
||||||
|
|
||||||
|
@ -95,6 +101,11 @@ class ConcaveShape : public CollisionShape {
|
||||||
void setIsSmoothMeshCollisionEnabled(bool isEnabled);
|
void setIsSmoothMeshCollisionEnabled(bool isEnabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user