diff --git a/src/collision/shapes/ConcaveMeshShape.h b/src/collision/shapes/ConcaveMeshShape.h index 0efbcfeb..b234fc3c 100644 --- a/src/collision/shapes/ConcaveMeshShape.h +++ b/src/collision/shapes/ConcaveMeshShape.h @@ -102,7 +102,7 @@ class ConcaveMeshRaycastCallback : public DynamicAABBTreeRaycastCallback { // Class ConcaveMeshShape /** - * This class represents a concave mesh shape. Note that collision detection + * This class represents a static concave mesh shape. Note that collision detection * with a concave mesh shape can be very expensive. You should use only use * this shape for a static mesh. */ @@ -129,14 +129,6 @@ class ConcaveMeshShape : public ConcaveShape { /// Private assignment operator ConcaveMeshShape& operator=(const ConcaveMeshShape& shape); - /// Return a local support point in a given direction with the object margin - virtual Vector3 getLocalSupportPointWithMargin(const Vector3& direction, - void** cachedCollisionData) const; - - /// Return a local support point in a given direction without the object margin - virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const; - /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; @@ -188,23 +180,6 @@ inline size_t ConcaveMeshShape::getSizeInBytes() const { return sizeof(ConcaveMeshShape); } -// Return a local support point in a given direction with the object margin -inline Vector3 ConcaveMeshShape::getLocalSupportPointWithMargin(const Vector3& direction, - void** cachedCollisionData) const { - - // Should not be used - assert(false); - return Vector3(0, 0, 0); -} - -// Return a local support point in a given direction without the object margin -inline Vector3 ConcaveMeshShape::getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const { - // Should not be used - assert(false); - return Vector3(0.0, 0.0, 0.0); -} - // Return the local bounds of the shape in x, y and z directions. // This method is used to compute the AABB of the box /** @@ -232,7 +207,7 @@ inline void ConcaveMeshShape::setLocalScaling(const Vector3& scaling) { initBVHTree(); } -// Return the local inertia tensor of the sphere +// Return the local inertia tensor of the shape /** * @param[out] tensor The 3x3 inertia tensor matrix of the shape in local-space * coordinates diff --git a/src/collision/shapes/ConvexMeshShape.cpp b/src/collision/shapes/ConvexMeshShape.cpp index c46881a2..35bf5bc1 100644 --- a/src/collision/shapes/ConvexMeshShape.cpp +++ b/src/collision/shapes/ConvexMeshShape.cpp @@ -38,8 +38,7 @@ 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(const decimal* arrayVertices, uint nbVertices, int stride, - decimal margin) +ConvexMeshShape::ConvexMeshShape(const decimal* arrayVertices, uint nbVertices, int stride, decimal margin) : ConvexShape(CONVEX_MESH, margin), mNbVertices(nbVertices), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(false) { assert(nbVertices > 0); @@ -268,6 +267,10 @@ void ConvexMeshShape::recalculateBounds() { if (mVertices[i].z < mMinBounds.z) mMinBounds.z = mVertices[i].z; } + // Apply the local scaling factor + mMaxBounds = mMaxBounds * mScaling; + mMinBounds = mMinBounds * mScaling; + // Add the object margin to the bounds mMaxBounds += Vector3(mMargin, mMargin, mMargin); mMinBounds -= Vector3(mMargin, mMargin, mMargin); diff --git a/src/collision/shapes/ConvexMeshShape.h b/src/collision/shapes/ConvexMeshShape.h index 13b11ee0..cfdd22db 100644 --- a/src/collision/shapes/ConvexMeshShape.h +++ b/src/collision/shapes/ConvexMeshShape.h @@ -42,11 +42,6 @@ namespace reactphysics3d { // Declaration class CollisionWorld; -// TODO : Make possible to create a ConvexMeshShape using a TriangleMesh as for -// the ConcaveMeshShape - -// TODO : Check that scaling factor is working after the change of the previous TODO - // Class ConvexMeshShape /** * This class represents a convex mesh shape. In order to create a convex mesh shape, you @@ -99,6 +94,9 @@ class ConvexMeshShape : public ConvexShape { /// Recompute the bounds of the mesh void recalculateBounds(); + /// Set the scaling vector of the collision shape + virtual void setLocalScaling(const Vector3& scaling); + /// Return a local support point in a given direction with the object margin virtual Vector3 getLocalSupportPointWithMargin(const Vector3& direction, void** cachedCollisionData) const; @@ -154,6 +152,12 @@ class ConvexMeshShape : public ConvexShape { void setIsEdgesInformationUsed(bool isEdgesUsed); }; +/// Set the scaling vector of the collision shape +inline void ConvexMeshShape::setLocalScaling(const Vector3& scaling) { + ConvexShape::setLocalScaling(scaling); + recalculateBounds(); +} + // Return the number of bytes used by the collision shape inline size_t ConvexMeshShape::getSizeInBytes() const { return sizeof(ConvexMeshShape); @@ -200,12 +204,12 @@ inline void ConvexMeshShape::addVertex(const Vector3& vertex) { mNbVertices++; // Update the bounds of the mesh - if (vertex.x > mMaxBounds.x) mMaxBounds.x = vertex.x; - if (vertex.x < mMinBounds.x) mMinBounds.x = vertex.x; - if (vertex.y > mMaxBounds.y) mMaxBounds.y = vertex.y; - if (vertex.y < mMinBounds.y) mMinBounds.y = vertex.y; - if (vertex.z > mMaxBounds.z) mMaxBounds.z = vertex.z; - if (vertex.z < mMinBounds.z) mMinBounds.z = vertex.z; + if (vertex.x * mScaling.x > mMaxBounds.x) mMaxBounds.x = vertex.x * mScaling.x; + if (vertex.x * mScaling.x < mMinBounds.x) mMinBounds.x = vertex.x * mScaling.x; + if (vertex.y * mScaling.y > mMaxBounds.y) mMaxBounds.y = vertex.y * mScaling.y; + if (vertex.y * mScaling.y < mMinBounds.y) mMinBounds.y = vertex.y * mScaling.y; + if (vertex.z * mScaling.z > mMaxBounds.z) mMaxBounds.z = vertex.z * mScaling.z; + if (vertex.z * mScaling.z < mMinBounds.z) mMinBounds.z = vertex.z * mScaling.z; } // Add an edge into the convex mesh by specifying the two vertex indices of the edge.