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