diff --git a/src/body/CollisionBody.cpp b/src/body/CollisionBody.cpp index 779cc747..1de04876 100644 --- a/src/body/CollisionBody.cpp +++ b/src/body/CollisionBody.cpp @@ -51,30 +51,27 @@ CollisionBody::~CollisionBody() { removeAllCollisionShapes(); } -// Add a collision shape to the body. -/// When you add a collision shape to the body, an internal copy of this -/// collision shape will be created internally. Therefore, you can delete it -/// right after calling this method or use it later to add it to another body. +// Add a collision shape to the body. Note that you can share a collision +// shape between several bodies using the same collision shape instance to +// when you add the shape to the different bodies. Do not forget to delete +// the collision shape you have created at the end of your program. /// This method will return a pointer to a new proxy shape. A proxy shape is /// an object that links a collision shape and a given body. You can use the /// returned proxy shape to get and set information about the corresponding /// collision shape for that body. /** - * @param collisionShape The collision shape you want to add to the body + * @param collisionShape A pointer to the collision shape you want to add to the body * @param transform The transformation of the collision shape that transforms the * local-space of the collision shape into the local-space of the body * @return A pointer to the proxy shape that has been created to link the body to * the new collision shape you have added. */ -ProxyShape* CollisionBody::addCollisionShape(const CollisionShape& collisionShape, +ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape, const Transform& transform) { - // Create an internal copy of the collision shape into the world (if it does not exist yet) - CollisionShape* newCollisionShape = mWorld.createCollisionShape(collisionShape); - // Create a new proxy collision shape to attach the collision shape to the body ProxyShape* proxyShape = new (mWorld.mMemoryAllocator.allocate( - sizeof(ProxyShape))) ProxyShape(this, newCollisionShape, + sizeof(ProxyShape))) ProxyShape(this, collisionShape, transform, decimal(1)); // Add it to the list of proxy collision shapes of the body @@ -88,7 +85,7 @@ ProxyShape* CollisionBody::addCollisionShape(const CollisionShape& collisionShap // Compute the world-space AABB of the new collision shape AABB aabb; - newCollisionShape->computeAABB(aabb, mTransform * transform); + collisionShape->computeAABB(aabb, mTransform * transform); // Notify the collision detection about this new collision shape mWorld.mCollisionDetection.addProxyCollisionShape(proxyShape, aabb); @@ -118,7 +115,6 @@ void CollisionBody::removeCollisionShape(const ProxyShape* proxyShape) { mWorld.mCollisionDetection.removeProxyCollisionShape(current); } - mWorld.removeCollisionShape(proxyShape->mCollisionShape); current->~ProxyShape(); mWorld.mMemoryAllocator.release(current, sizeof(ProxyShape)); mNbCollisionShapes--; @@ -140,7 +136,6 @@ void CollisionBody::removeCollisionShape(const ProxyShape* proxyShape) { mWorld.mCollisionDetection.removeProxyCollisionShape(elementToRemove); } - mWorld.removeCollisionShape(proxyShape->mCollisionShape); elementToRemove->~ProxyShape(); mWorld.mMemoryAllocator.release(elementToRemove, sizeof(ProxyShape)); mNbCollisionShapes--; @@ -169,7 +164,6 @@ void CollisionBody::removeAllCollisionShapes() { mWorld.mCollisionDetection.removeProxyCollisionShape(current); } - mWorld.removeCollisionShape(current->mCollisionShape); current->~ProxyShape(); mWorld.mMemoryAllocator.release(current, sizeof(ProxyShape)); diff --git a/src/body/CollisionBody.h b/src/body/CollisionBody.h index 955a2130..85a423cf 100644 --- a/src/body/CollisionBody.h +++ b/src/body/CollisionBody.h @@ -135,8 +135,8 @@ class CollisionBody : public Body { virtual void setTransform(const Transform& transform); /// Add a collision shape to the body. - virtual ProxyShape* addCollisionShape(const CollisionShape& collisionShape, - const Transform& transform); + virtual ProxyShape* addCollisionShape(CollisionShape* collisionShape, + const Transform& transform); /// Remove a collision shape from the body virtual void removeCollisionShape(const ProxyShape* proxyShape); diff --git a/src/body/RigidBody.cpp b/src/body/RigidBody.cpp index 32f540f8..76627694 100644 --- a/src/body/RigidBody.cpp +++ b/src/body/RigidBody.cpp @@ -209,18 +209,15 @@ void RigidBody::removeJointFromJointsList(MemoryAllocator& memoryAllocator, cons * @return A pointer to the proxy shape that has been created to link the body to * the new collision shape you have added. */ -ProxyShape* RigidBody::addCollisionShape(const CollisionShape& collisionShape, +ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape, const Transform& transform, decimal mass) { assert(mass > decimal(0.0)); - // Create an internal copy of the collision shape into the world if it is not there yet - CollisionShape* newCollisionShape = mWorld.createCollisionShape(collisionShape); - // Create a new proxy collision shape to attach the collision shape to the body ProxyShape* proxyShape = new (mWorld.mMemoryAllocator.allocate( - sizeof(ProxyShape))) ProxyShape(this, newCollisionShape, + sizeof(ProxyShape))) ProxyShape(this, collisionShape, transform, mass); // Add it to the list of proxy collision shapes of the body @@ -234,7 +231,7 @@ ProxyShape* RigidBody::addCollisionShape(const CollisionShape& collisionShape, // Compute the world-space AABB of the new collision shape AABB aabb; - newCollisionShape->computeAABB(aabb, mTransform * transform); + collisionShape->computeAABB(aabb, mTransform * transform); // Notify the collision detection about this new collision shape mWorld.mCollisionDetection.addProxyCollisionShape(proxyShape, aabb); diff --git a/src/body/RigidBody.h b/src/body/RigidBody.h index e8cc573b..63bede26 100644 --- a/src/body/RigidBody.h +++ b/src/body/RigidBody.h @@ -210,7 +210,7 @@ class RigidBody : public CollisionBody { void applyTorque(const Vector3& torque); /// Add a collision shape to the body. - virtual ProxyShape* addCollisionShape(const CollisionShape& collisionShape, + virtual ProxyShape* addCollisionShape(CollisionShape* collisionShape, const Transform& transform, decimal mass); diff --git a/src/collision/ProxyShape.cpp b/src/collision/ProxyShape.cpp index e8744912..f484d636 100644 --- a/src/collision/ProxyShape.cpp +++ b/src/collision/ProxyShape.cpp @@ -35,8 +35,7 @@ using namespace reactphysics3d; * @param transform Transformation from collision shape local-space to body local-space * @param mass Mass of the collision shape (in kilograms) */ -ProxyShape::ProxyShape(CollisionBody* body, CollisionShape* shape, const Transform& transform, - decimal mass) +ProxyShape::ProxyShape(CollisionBody* body, CollisionShape* shape, const Transform& transform, decimal mass) :mBody(body), mCollisionShape(shape), mLocalToBodyTransform(transform), mMass(mass), mNext(NULL), mBroadPhaseID(-1), mCachedCollisionData(NULL), mUserData(NULL), mCollisionCategoryBits(0x0001), mCollideWithMaskBits(0xFFFF) { diff --git a/src/collision/ProxyShape.h b/src/collision/ProxyShape.h index 0e9e4224..fcdef1f3 100644 --- a/src/collision/ProxyShape.h +++ b/src/collision/ProxyShape.h @@ -93,14 +93,8 @@ class ProxyShape { /// Private assignment operator ProxyShape& operator=(const ProxyShape& proxyShape); - // Return a local support point in a given direction with the object margin - Vector3 getLocalSupportPointWithMargin(const Vector3& direction); - - /// Return a local support point in a given direction without the object margin. - Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction); - - /// Return the collision shape margin - decimal getMargin() const; + /// Return the pointer to the cached collision data + void** getCachedCollisionData(); public: @@ -173,7 +167,12 @@ class ProxyShape { friend class ConvexMeshShape; }; -/// Return the collision shape +// Return the pointer to the cached collision data +inline void** ProxyShape::getCachedCollisionData() { + return &mCachedCollisionData; +} + +// Return the collision shape /** * @return Pointer to the internal collision shape */ @@ -231,21 +230,6 @@ inline const Transform ProxyShape::getLocalToWorldTransform() const { return mBody->mTransform * mLocalToBodyTransform; } -// Return a local support point in a given direction with the object margin -inline Vector3 ProxyShape::getLocalSupportPointWithMargin(const Vector3& direction) { - return mCollisionShape->getLocalSupportPointWithMargin(direction, &mCachedCollisionData); -} - -// Return a local support point in a given direction without the object margin. -inline Vector3 ProxyShape::getLocalSupportPointWithoutMargin(const Vector3& direction) { - return mCollisionShape->getLocalSupportPointWithoutMargin(direction, &mCachedCollisionData); -} - -// Return the collision shape margin -inline decimal ProxyShape::getMargin() const { - return mCollisionShape->getMargin(); -} - // Raycast method with feedback information /** * @param ray Ray to use for the raycasting diff --git a/src/collision/TriangleMesh.h b/src/collision/TriangleMesh.h index 7b6f29a8..8421b08a 100644 --- a/src/collision/TriangleMesh.h +++ b/src/collision/TriangleMesh.h @@ -28,6 +28,7 @@ // Libraries #include +#include #include "TriangleVertexArray.h" namespace reactphysics3d { diff --git a/src/collision/TriangleVertexArray.h b/src/collision/TriangleVertexArray.h index c6001277..f088acff 100644 --- a/src/collision/TriangleVertexArray.h +++ b/src/collision/TriangleVertexArray.h @@ -27,6 +27,7 @@ #define REACTPHYSICS3D_TRIANGLE_VERTEX_ARRAY_H // Libraries +#include "configuration.h" namespace reactphysics3d { diff --git a/src/collision/narrowphase/ConcaveVsConvexAlgorithm.h b/src/collision/narrowphase/ConcaveVsConvexAlgorithm.h index 4e637415..35ba8e36 100644 --- a/src/collision/narrowphase/ConcaveVsConvexAlgorithm.h +++ b/src/collision/narrowphase/ConcaveVsConvexAlgorithm.h @@ -27,6 +27,7 @@ #define REACTPHYSICS3D_CONCAVE_VS_CONVEX_ALGORITHM_H // Libraries +#include "NarrowPhaseAlgorithm.h" /// Namespace ReactPhysics3D namespace reactphysics3d { diff --git a/src/collision/narrowphase/EPA/EPAAlgorithm.cpp b/src/collision/narrowphase/EPA/EPAAlgorithm.cpp index 689407e0..4af3954a 100644 --- a/src/collision/narrowphase/EPA/EPAAlgorithm.cpp +++ b/src/collision/narrowphase/EPA/EPAAlgorithm.cpp @@ -82,12 +82,21 @@ int EPAAlgorithm::isOriginInTetrahedron(const Vector3& p1, const Vector3& p2, /// GJK algorithm. The EPA Algorithm will extend this simplex polytope to find /// the correct penetration depth bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simplex, - ProxyShape* collisionShape1, + ProxyShape* proxyShape1, const Transform& transform1, - ProxyShape* collisionShape2, + ProxyShape* proxyShape2, const Transform& transform2, Vector3& v, ContactPointInfo*& contactInfo) { + assert(proxyShape1->getCollisionShape()->isConvex()); + assert(proxyShape2->getCollisionShape()->isConvex()); + + const ConvexShape* shape1 = static_cast(proxyShape1->getCollisionShape()); + const ConvexShape* shape2 = static_cast(proxyShape2->getCollisionShape()); + + void** shape1CachedCollisionData = proxyShape1->getCachedCollisionData(); + void** shape2CachedCollisionData = proxyShape2->getCachedCollisionData(); + Vector3 suppPointsA[MAX_SUPPORT_POINTS]; // Support points of object A in local coordinates Vector3 suppPointsB[MAX_SUPPORT_POINTS]; // Support points of object B in local coordinates Vector3 points[MAX_SUPPORT_POINTS]; // Current points @@ -154,21 +163,21 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple Vector3 v3 = rotationQuat * v2; // Compute the support point in the direction of v1 - suppPointsA[2] = collisionShape1->getLocalSupportPointWithMargin(v1); + suppPointsA[2] = shape1->getLocalSupportPointWithMargin(v1, shape1CachedCollisionData); suppPointsB[2] = body2Tobody1 * - collisionShape2->getLocalSupportPointWithMargin(rotateToBody2 * (-v1)); + shape2->getLocalSupportPointWithMargin(rotateToBody2 * (-v1), shape2CachedCollisionData); points[2] = suppPointsA[2] - suppPointsB[2]; // Compute the support point in the direction of v2 - suppPointsA[3] = collisionShape1->getLocalSupportPointWithMargin(v2); + suppPointsA[3] = shape1->getLocalSupportPointWithMargin(v2, shape1CachedCollisionData); suppPointsB[3] = body2Tobody1 * - collisionShape2->getLocalSupportPointWithMargin(rotateToBody2 * (-v2)); + shape2->getLocalSupportPointWithMargin(rotateToBody2 * (-v2), shape2CachedCollisionData); points[3] = suppPointsA[3] - suppPointsB[3]; // Compute the support point in the direction of v3 - suppPointsA[4] = collisionShape1->getLocalSupportPointWithMargin(v3); + suppPointsA[4] = shape1->getLocalSupportPointWithMargin(v3, shape1CachedCollisionData); suppPointsB[4] = body2Tobody1 * - collisionShape2->getLocalSupportPointWithMargin(rotateToBody2 * (-v3)); + shape2->getLocalSupportPointWithMargin(rotateToBody2 * (-v3), shape2CachedCollisionData); points[4] = suppPointsA[4] - suppPointsB[4]; // Now we have an hexahedron (two tetrahedron glued together). We can simply keep the @@ -267,13 +276,13 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple Vector3 n = v1.cross(v2); // Compute the two new vertices to obtain a hexahedron - suppPointsA[3] = collisionShape1->getLocalSupportPointWithMargin(n); + suppPointsA[3] = shape1->getLocalSupportPointWithMargin(n, shape1CachedCollisionData); suppPointsB[3] = body2Tobody1 * - collisionShape2->getLocalSupportPointWithMargin(rotateToBody2 * (-n)); + shape2->getLocalSupportPointWithMargin(rotateToBody2 * (-n), shape2CachedCollisionData); points[3] = suppPointsA[3] - suppPointsB[3]; - suppPointsA[4] = collisionShape1->getLocalSupportPointWithMargin(-n); + suppPointsA[4] = shape1->getLocalSupportPointWithMargin(-n, shape1CachedCollisionData); suppPointsB[4] = body2Tobody1 * - collisionShape2->getLocalSupportPointWithMargin(rotateToBody2 * n); + shape2->getLocalSupportPointWithMargin(rotateToBody2 * n, shape2CachedCollisionData); points[4] = suppPointsA[4] - suppPointsB[4]; TriangleEPA* face0 = NULL; @@ -363,11 +372,11 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple // Compute the support point of the Minkowski // difference (A-B) in the closest point direction - suppPointsA[nbVertices] = collisionShape1->getLocalSupportPointWithMargin( - triangle->getClosestPoint()); + suppPointsA[nbVertices] = shape1->getLocalSupportPointWithMargin( + triangle->getClosestPoint(), shape1CachedCollisionData); suppPointsB[nbVertices] = body2Tobody1 * - collisionShape2->getLocalSupportPointWithMargin(rotateToBody2 * - (-triangle->getClosestPoint())); + shape2->getLocalSupportPointWithMargin(rotateToBody2 * + (-triangle->getClosestPoint()), shape2CachedCollisionData); points[nbVertices] = suppPointsA[nbVertices] - suppPointsB[nbVertices]; int indexNewVertex = nbVertices; @@ -418,7 +427,7 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple // Create the contact info object contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo))) - ContactPointInfo(collisionShape1, collisionShape2, normal, + ContactPointInfo(proxyShape1, proxyShape2, normal, penetrationDepth, pALocal, pBLocal); return true; diff --git a/src/collision/narrowphase/EPA/EPAAlgorithm.h b/src/collision/narrowphase/EPA/EPAAlgorithm.h index 69298d02..2a2dadcb 100644 --- a/src/collision/narrowphase/EPA/EPAAlgorithm.h +++ b/src/collision/narrowphase/EPA/EPAAlgorithm.h @@ -122,9 +122,9 @@ class EPAAlgorithm { /// Compute the penetration depth with EPA algorithm. bool computePenetrationDepthAndContactPoints(const Simplex& simplex, - ProxyShape* collisionShape1, + ProxyShape* proxyShape1, const Transform& transform1, - ProxyShape* collisionShape2, + ProxyShape* proxyShape2, const Transform& transform2, Vector3& v, ContactPointInfo*& contactInfo); }; diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp index b4d50ecd..c7bd43a8 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp @@ -56,7 +56,7 @@ GJKAlgorithm::~GJKAlgorithm() { /// algorithm on the enlarged object to obtain a simplex polytope that contains the /// origin, they we give that simplex polytope to the EPA algorithm which will compute /// the correct penetration depth and contact points between the enlarged objects. -bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collisionShape2, +bool GJKAlgorithm::testCollision(ProxyShape* proxyShape1, ProxyShape* proxyShape2, ContactPointInfo*& contactInfo) { Vector3 suppA; // Support point of object A @@ -67,11 +67,20 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis decimal vDotw; decimal prevDistSquare; + assert(proxyShape1->getCollisionShape()->isConvex()); + assert(proxyShape2->getCollisionShape()->isConvex()); + + const ConvexShape* shape1 = static_cast(proxyShape1->getCollisionShape()); + const ConvexShape* shape2 = static_cast(proxyShape2->getCollisionShape()); + + void** shape1CachedCollisionData = proxyShape1->getCachedCollisionData(); + void** shape2CachedCollisionData = proxyShape2->getCachedCollisionData(); + // Get the local-space to world-space transforms - const Transform transform1 = collisionShape1->getBody()->getTransform() * - collisionShape1->getLocalToBodyTransform(); - const Transform transform2 = collisionShape2->getBody()->getTransform() * - collisionShape2->getLocalToBodyTransform(); + const Transform transform1 = proxyShape1->getBody()->getTransform() * + proxyShape1->getLocalToBodyTransform(); + const Transform transform2 = proxyShape2->getBody()->getTransform() * + proxyShape2->getLocalToBodyTransform(); // Transform a point from local space of body 2 to local // space of body 1 (the GJK algorithm is done in local space of body 1) @@ -83,7 +92,7 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis transform1.getOrientation().getMatrix(); // Initialize the margin (sum of margins of both objects) - decimal margin = collisionShape1->getMargin() + collisionShape2->getMargin(); + decimal margin = shape1->getMargin() + shape2->getMargin(); decimal marginSquare = margin * margin; assert(margin > 0.0); @@ -99,9 +108,9 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis do { // Compute the support points for original objects (without margins) A and B - suppA = collisionShape1->getLocalSupportPointWithoutMargin(-v); + suppA = shape1->getLocalSupportPointWithoutMargin(-v, shape1CachedCollisionData); suppB = body2Tobody1 * - collisionShape2->getLocalSupportPointWithoutMargin(rotateToBody2 * v); + shape2->getLocalSupportPointWithoutMargin(rotateToBody2 * v, shape2CachedCollisionData); // Compute the support point for the Minkowski difference A-B w = suppA - suppB; @@ -128,8 +137,8 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // object with the margins decimal dist = sqrt(distSquare); assert(dist > 0.0); - pA = (pA - (collisionShape1->getMargin() / dist) * v); - pB = body2Tobody1.getInverse() * (pB + (collisionShape2->getMargin() / dist) * v); + pA = (pA - (shape1->getMargin() / dist) * v); + pB = body2Tobody1.getInverse() * (pB + (shape2->getMargin() / dist) * v); // Compute the contact info Vector3 normal = transform1.getOrientation() * (-v.getUnit()); @@ -140,7 +149,7 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // Create the contact info object contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo))) - ContactPointInfo(collisionShape1, collisionShape2, normal, + ContactPointInfo(proxyShape1, proxyShape2, normal, penetrationDepth, pA, pB); // There is an intersection, therefore we return true @@ -160,8 +169,8 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // object with the margins decimal dist = sqrt(distSquare); assert(dist > 0.0); - pA = (pA - (collisionShape1->getMargin() / dist) * v); - pB = body2Tobody1.getInverse() * (pB + (collisionShape2->getMargin() / dist) * v); + pA = (pA - (shape1->getMargin() / dist) * v); + pB = body2Tobody1.getInverse() * (pB + (shape2->getMargin() / dist) * v); // Compute the contact info Vector3 normal = transform1.getOrientation() * (-v.getUnit()); @@ -172,7 +181,7 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // Create the contact info object contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo))) - ContactPointInfo(collisionShape1, collisionShape2, normal, + ContactPointInfo(proxyShape1, proxyShape2, normal, penetrationDepth, pA, pB); // There is an intersection, therefore we return true @@ -190,8 +199,8 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // object with the margins decimal dist = sqrt(distSquare); assert(dist > 0.0); - pA = (pA - (collisionShape1->getMargin() / dist) * v); - pB = body2Tobody1.getInverse() * (pB + (collisionShape2->getMargin() / dist) * v); + pA = (pA - (shape1->getMargin() / dist) * v); + pB = body2Tobody1.getInverse() * (pB + (shape2->getMargin() / dist) * v); // Compute the contact info Vector3 normal = transform1.getOrientation() * (-v.getUnit()); @@ -202,7 +211,7 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // Create the contact info object contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo))) - ContactPointInfo(collisionShape1, collisionShape2, normal, + ContactPointInfo(proxyShape1, proxyShape2, normal, penetrationDepth, pA, pB); // There is an intersection, therefore we return true @@ -227,8 +236,8 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // object with the margins decimal dist = sqrt(distSquare); assert(dist > 0.0); - pA = (pA - (collisionShape1->getMargin() / dist) * v); - pB = body2Tobody1.getInverse() * (pB + (collisionShape2->getMargin() / dist) * v); + pA = (pA - (shape1->getMargin() / dist) * v); + pB = body2Tobody1.getInverse() * (pB + (shape2->getMargin() / dist) * v); // Compute the contact info Vector3 normal = transform1.getOrientation() * (-v.getUnit()); @@ -239,7 +248,7 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // Create the contact info object contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo))) - ContactPointInfo(collisionShape1, collisionShape2, normal, + ContactPointInfo(proxyShape1, proxyShape2, normal, penetrationDepth, pA, pB); // There is an intersection, therefore we return true @@ -252,7 +261,7 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis // again but on the enlarged objects to compute a simplex polytope that contains // the origin. Then, we give that simplex polytope to the EPA algorithm to compute // the correct penetration depth and contact points between the enlarged objects. - return computePenetrationDepthForEnlargedObjects(collisionShape1, transform1, collisionShape2, + return computePenetrationDepthForEnlargedObjects(proxyShape1, transform1, proxyShape2, transform2, contactInfo, v); } @@ -261,9 +270,9 @@ bool GJKAlgorithm::testCollision(ProxyShape* collisionShape1, ProxyShape* collis /// assumed to intersect in the original objects (without margin). Therefore such /// a polytope must exist. Then, we give that polytope to the EPA algorithm to /// compute the correct penetration depth and contact points of the enlarged objects. -bool GJKAlgorithm::computePenetrationDepthForEnlargedObjects(ProxyShape* collisionShape1, +bool GJKAlgorithm::computePenetrationDepthForEnlargedObjects(ProxyShape* proxyShape1, const Transform& transform1, - ProxyShape* collisionShape2, + ProxyShape* proxyShape2, const Transform& transform2, ContactPointInfo*& contactInfo, Vector3& v) { @@ -275,6 +284,15 @@ bool GJKAlgorithm::computePenetrationDepthForEnlargedObjects(ProxyShape* collisi decimal distSquare = DECIMAL_LARGEST; decimal prevDistSquare; + assert(proxyShape1->getCollisionShape()->isConvex()); + assert(proxyShape2->getCollisionShape()->isConvex()); + + const ConvexShape* shape1 = static_cast(proxyShape1->getCollisionShape()); + const ConvexShape* shape2 = static_cast(proxyShape2->getCollisionShape()); + + void** shape1CachedCollisionData = proxyShape1->getCachedCollisionData(); + void** shape2CachedCollisionData = proxyShape2->getCachedCollisionData(); + // Transform a point from local space of body 2 to local space // of body 1 (the GJK algorithm is done in local space of body 1) Transform body2ToBody1 = transform1.getInverse() * transform2; @@ -285,8 +303,8 @@ bool GJKAlgorithm::computePenetrationDepthForEnlargedObjects(ProxyShape* collisi do { // Compute the support points for the enlarged object A and B - suppA = collisionShape1->getLocalSupportPointWithMargin(-v); - suppB = body2ToBody1 * collisionShape2->getLocalSupportPointWithMargin(rotateToBody2 * v); + suppA = shape1->getLocalSupportPointWithMargin(-v, shape1CachedCollisionData); + suppB = body2ToBody1 * shape2->getLocalSupportPointWithMargin(rotateToBody2 * v, shape2CachedCollisionData); // Compute the support point for the Minkowski difference A-B w = suppA - suppB; @@ -325,18 +343,24 @@ bool GJKAlgorithm::computePenetrationDepthForEnlargedObjects(ProxyShape* collisi // Give the simplex computed with GJK algorithm to the EPA algorithm // which will compute the correct penetration depth and contact points // between the two enlarged objects - return mAlgoEPA.computePenetrationDepthAndContactPoints(simplex, collisionShape1, - transform1, collisionShape2, transform2, + return mAlgoEPA.computePenetrationDepthAndContactPoints(simplex, proxyShape1, + transform1, proxyShape2, transform2, v, contactInfo); } // Use the GJK Algorithm to find if a point is inside a convex collision shape -bool GJKAlgorithm::testPointInside(const Vector3& localPoint, ProxyShape* collisionShape) { +bool GJKAlgorithm::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) { Vector3 suppA; // Support point of object A Vector3 w; // Support point of Minkowski difference A-B decimal prevDistSquare; + assert(proxyShape->getCollisionShape()->isConvex()); + + const ConvexShape* shape = static_cast(proxyShape->getCollisionShape()); + + void** shapeCachedCollisionData = proxyShape->getCachedCollisionData(); + // Support point of object B (object B is a single point) const Vector3 suppB(localPoint); @@ -352,7 +376,7 @@ bool GJKAlgorithm::testPointInside(const Vector3& localPoint, ProxyShape* collis do { // Compute the support points for original objects (without margins) A and B - suppA = collisionShape->getLocalSupportPointWithoutMargin(-v); + suppA = shape->getLocalSupportPointWithoutMargin(-v, shapeCachedCollisionData); // Compute the support point for the Minkowski difference A-B w = suppA - suppB; @@ -393,7 +417,13 @@ bool GJKAlgorithm::testPointInside(const Vector3& localPoint, ProxyShape* collis // Ray casting algorithm agains a convex collision shape using the GJK Algorithm /// This method implements the GJK ray casting algorithm described by Gino Van Den Bergen in /// "Ray Casting against General Convex Objects with Application to Continuous Collision Detection". -bool GJKAlgorithm::raycast(const Ray& ray, ProxyShape* collisionShape, RaycastInfo& raycastInfo) { +bool GJKAlgorithm::raycast(const Ray& ray, ProxyShape* proxyShape, RaycastInfo& raycastInfo) { + + assert(proxyShape->getCollisionShape()->isConvex()); + + const ConvexShape* shape = static_cast(proxyShape->getCollisionShape()); + + void** shapeCachedCollisionData = proxyShape->getCachedCollisionData(); Vector3 suppA; // Current lower bound point on the ray (starting at ray's origin) Vector3 suppB; // Support point on the collision shape @@ -401,7 +431,7 @@ bool GJKAlgorithm::raycast(const Ray& ray, ProxyShape* collisionShape, RaycastIn const decimal epsilon = decimal(0.0001); // Convert the ray origin and direction into the local-space of the collision shape - const Transform localToWorldTransform = collisionShape->getLocalToWorldTransform(); + const Transform localToWorldTransform = proxyShape->getLocalToWorldTransform(); const Transform worldToLocalTransform = localToWorldTransform.getInverse(); Vector3 point1 = worldToLocalTransform * ray.point1; Vector3 point2 = worldToLocalTransform * ray.point2; @@ -418,7 +448,7 @@ bool GJKAlgorithm::raycast(const Ray& ray, ProxyShape* collisionShape, RaycastIn Vector3 n(decimal(0.0), decimal(0.0), decimal(0.0)); decimal lambda = decimal(0.0); suppA = point1; // Current lower bound point on the ray (starting at ray's origin) - suppB = collisionShape->getLocalSupportPointWithoutMargin(rayDirection); + suppB = shape->getLocalSupportPointWithoutMargin(rayDirection, shapeCachedCollisionData); Vector3 v = suppA - suppB; decimal vDotW, vDotR; decimal distSquare = v.lengthSquare(); @@ -428,7 +458,7 @@ bool GJKAlgorithm::raycast(const Ray& ray, ProxyShape* collisionShape, RaycastIn while (distSquare > epsilon && nbIterations < MAX_ITERATIONS_GJK_RAYCAST) { // Compute the support points - suppB = collisionShape->getLocalSupportPointWithoutMargin(v); + suppB = shape->getLocalSupportPointWithoutMargin(v, shapeCachedCollisionData); w = suppA - suppB; vDotW = v.dot(w); @@ -481,8 +511,8 @@ bool GJKAlgorithm::raycast(const Ray& ray, ProxyShape* collisionShape, RaycastIn // A raycast hit has been found, we fill in the raycast info raycastInfo.hitFraction = lambda; raycastInfo.worldPoint = localToWorldTransform * pointB; - raycastInfo.body = collisionShape->getBody(); - raycastInfo.proxyShape = collisionShape; + raycastInfo.body = proxyShape->getBody(); + raycastInfo.proxyShape = proxyShape; if (n.lengthSquare() >= machineEpsilonSquare) { // The normal vector is valid raycastInfo.worldNormal = localToWorldTransform.getOrientation() * n.getUnit(); diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.h b/src/collision/narrowphase/GJK/GJKAlgorithm.h index ba50f3ff..348f3c63 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.h +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.h @@ -29,7 +29,7 @@ // Libraries #include "collision/narrowphase/NarrowPhaseAlgorithm.h" #include "constraint/ContactPoint.h" -#include "collision/shapes/CollisionShape.h" +#include "collision/shapes/ConvexShape.h" #include "collision/narrowphase/EPA/EPAAlgorithm.h" @@ -75,9 +75,9 @@ class GJKAlgorithm : public NarrowPhaseAlgorithm { GJKAlgorithm& operator=(const GJKAlgorithm& algorithm); /// Compute the penetration depth for enlarged objects. - bool computePenetrationDepthForEnlargedObjects(ProxyShape* collisionShape1, + bool computePenetrationDepthForEnlargedObjects(ProxyShape* proxyShape1, const Transform& transform1, - ProxyShape* collisionShape2, + ProxyShape* proxyShape2, const Transform& transform2, ContactPointInfo*& contactInfo, Vector3& v); @@ -95,14 +95,14 @@ class GJKAlgorithm : public NarrowPhaseAlgorithm { virtual void init(MemoryAllocator* memoryAllocator); /// Return true and compute a contact info if the two bounding volumes collide. - virtual bool testCollision(ProxyShape* collisionShape1, ProxyShape* collisionShape2, + virtual bool testCollision(ProxyShape* proxyShape1, ProxyShape* proxyShape2, ContactPointInfo*& contactInfo); /// Use the GJK Algorithm to find if a point is inside a convex collision shape - bool testPointInside(const Vector3& localPoint, ProxyShape* collisionShape); + bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape); /// Ray casting algorithm agains a convex collision shape using the GJK Algorithm - bool raycast(const Ray& ray, ProxyShape* collisionShape, RaycastInfo& raycastInfo); + bool raycast(const Ray& ray, ProxyShape* proxyShape, RaycastInfo& raycastInfo); }; // Initalize the algorithm diff --git a/src/collision/shapes/BoxShape.cpp b/src/collision/shapes/BoxShape.cpp index 76c11e31..33dbb490 100644 --- a/src/collision/shapes/BoxShape.cpp +++ b/src/collision/shapes/BoxShape.cpp @@ -38,18 +38,12 @@ using namespace reactphysics3d; * @param margin The collision margin (in meters) around the collision shape */ BoxShape::BoxShape(const Vector3& extent, decimal margin) - : CollisionShape(BOX, margin), mExtent(extent - Vector3(margin, margin, margin)) { + : ConvexShape(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); } -// Private copy-constructor -BoxShape::BoxShape(const BoxShape& shape) : CollisionShape(shape), mExtent(shape.mExtent) { - -} - - // Destructor BoxShape::~BoxShape() { diff --git a/src/collision/shapes/BoxShape.h b/src/collision/shapes/BoxShape.h index 5ef775af..ec9a1c1f 100644 --- a/src/collision/shapes/BoxShape.h +++ b/src/collision/shapes/BoxShape.h @@ -81,9 +81,6 @@ class BoxShape : public ConvexShape { /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; - /// Allocate and return a copy of the object - virtual BoxShape* clone(void* allocatedMemory) const; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const; @@ -105,16 +102,8 @@ class BoxShape : public ConvexShape { /// Return the local inertia tensor of the collision shape virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; - - /// Test equality between two box shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; }; -// Allocate and return a copy of the object -inline BoxShape* BoxShape::clone(void* allocatedMemory) const { - return new (allocatedMemory) BoxShape(*this); -} - // Return the extents of the box /** * @return The vector with the three extents of the box shape (in meters) @@ -163,15 +152,6 @@ inline Vector3 BoxShape::getLocalSupportPointWithoutMargin(const Vector3& direct direction.z < 0.0 ? -mExtent.z : mExtent.z); } -// Test equality between two box shapes -inline bool BoxShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - - if (!ConvexShape::isEqualTo(otherCollisionShape)) return false; - - const BoxShape& otherShape = dynamic_cast(otherCollisionShape); - return (mExtent == otherShape.mExtent); -} - // Return true if a point is inside the collision shape inline bool BoxShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const { return (localPoint.x < mExtent[0] && localPoint.x > -mExtent[0] && diff --git a/src/collision/shapes/CapsuleShape.cpp b/src/collision/shapes/CapsuleShape.cpp index ff2681ff..22d44c69 100644 --- a/src/collision/shapes/CapsuleShape.cpp +++ b/src/collision/shapes/CapsuleShape.cpp @@ -37,17 +37,11 @@ using namespace reactphysics3d; * @param height The height of the capsule (in meters) */ CapsuleShape::CapsuleShape(decimal radius, decimal height) - : CollisionShape(CAPSULE, radius), mRadius(radius), mHalfHeight(height * decimal(0.5)) { + : ConvexShape(CAPSULE, radius), mRadius(radius), mHalfHeight(height * decimal(0.5)) { assert(radius > decimal(0.0)); assert(height > decimal(0.0)); } -// Private copy-constructor -CapsuleShape::CapsuleShape(const CapsuleShape& shape) - : CollisionShape(shape), mRadius(shape.mRadius), mHalfHeight(shape.mHalfHeight) { - -} - // Destructor CapsuleShape::~CapsuleShape() { diff --git a/src/collision/shapes/CapsuleShape.h b/src/collision/shapes/CapsuleShape.h index caec2075..480b185d 100644 --- a/src/collision/shapes/CapsuleShape.h +++ b/src/collision/shapes/CapsuleShape.h @@ -83,9 +83,6 @@ class CapsuleShape : public ConvexShape { const Vector3& sphereCenter, decimal maxFraction, Vector3& hitLocalPoint, decimal& hitFraction) const; - /// Allocate and return a copy of the object - virtual CapsuleShape* clone(void* allocatedMemory) const; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const; @@ -110,16 +107,8 @@ class CapsuleShape : public ConvexShape { /// Return the local inertia tensor of the collision shape virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; - - /// Test equality between two capsule shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; }; -// Allocate and return a copy of the object -inline CapsuleShape* CapsuleShape::clone(void* allocatedMemory) const { - return new (allocatedMemory) CapsuleShape(*this); -} - // Get the radius of the capsule /** * @return The radius of the capsule shape (in meters) @@ -160,15 +149,6 @@ inline void CapsuleShape::getLocalBounds(Vector3& min, Vector3& max) const { min.z = min.x; } -// Test equality between two capsule shapes -inline bool CapsuleShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - - if (!ConvexShape::isEqualTo(otherCollisionShape)) return false; - - const CapsuleShape& otherShape = dynamic_cast(otherCollisionShape); - return (mRadius == otherShape.mRadius && mHalfHeight == otherShape.mHalfHeight); -} - } #endif diff --git a/src/collision/shapes/CollisionShape.cpp b/src/collision/shapes/CollisionShape.cpp index e6dc0a49..2f349bad 100644 --- a/src/collision/shapes/CollisionShape.cpp +++ b/src/collision/shapes/CollisionShape.cpp @@ -37,12 +37,6 @@ CollisionShape::CollisionShape(CollisionShapeType type) } -// Private copy-constructor -CollisionShape::CollisionShape(const CollisionShape& shape) - : mType(shape.mType), mNbSimilarCreatedShapes(shape.mNbSimilarCreatedShapes) { - -} - // Destructor CollisionShape::~CollisionShape() { assert(mNbSimilarCreatedShapes == 0); diff --git a/src/collision/shapes/CollisionShape.h b/src/collision/shapes/CollisionShape.h index 04fb4536..f61a00a8 100644 --- a/src/collision/shapes/CollisionShape.h +++ b/src/collision/shapes/CollisionShape.h @@ -78,21 +78,9 @@ class CollisionShape { /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const=0; - /// Return the number of similar created shapes - uint getNbSimilarCreatedShapes() const; - - /// Allocate and return a copy of the object - virtual CollisionShape* clone(void* allocatedMemory) const=0; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const = 0; - /// Increment the number of similar allocated collision shapes - void incrementNbSimilarCreatedShapes(); - - /// Decrement the number of similar allocated collision shapes - void decrementNbSimilarCreatedShapes(); - public : // -------------------- Methods -------------------- // @@ -118,12 +106,6 @@ class CollisionShape { /// Compute the world-space AABB of the collision shape given a transform virtual void computeAABB(AABB& aabb, const Transform& transform) const; - /// Equality operator between two collision shapes. - bool operator==(const CollisionShape& otherCollisionShape) const; - - /// Test equality between two collision shapes of the same type (same derived classes). - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const=0; - // -------------------- Friendship -------------------- // friend class ProxyShape; @@ -138,36 +120,6 @@ inline CollisionShapeType CollisionShape::getType() const { return mType; } -// Return the number of similar created shapes -inline uint CollisionShape::getNbSimilarCreatedShapes() const { - return mNbSimilarCreatedShapes; -} - -// Increment the number of similar allocated collision shapes -inline void CollisionShape::incrementNbSimilarCreatedShapes() { - mNbSimilarCreatedShapes++; -} - -// Decrement the number of similar allocated collision shapes -inline void CollisionShape::decrementNbSimilarCreatedShapes() { - mNbSimilarCreatedShapes--; -} - -// Equality operator between two collision shapes. -/// This methods returns true only if the two collision shapes are of the same type and -/// of the same dimensions. -inline bool CollisionShape::operator==(const CollisionShape& otherCollisionShape) const { - - // If the two collisions shapes are not of the same type (same derived classes) - // we return false - if (mType != otherCollisionShape.mType) return false; - - assert(typeid(*this) == typeid(otherCollisionShape)); - - // Check if the two shapes are equal - return otherCollisionShape.isEqualTo(*this); -} - } #endif diff --git a/src/collision/shapes/ConcaveMeshShape.cpp b/src/collision/shapes/ConcaveMeshShape.cpp index 336d0b05..9379e9b6 100644 --- a/src/collision/shapes/ConcaveMeshShape.cpp +++ b/src/collision/shapes/ConcaveMeshShape.cpp @@ -29,7 +29,7 @@ using namespace reactphysics3d; // Constructor -ConcaveMeshShape::ConcaveMeshShape(TriangleMesh* triangleMesh) { +ConcaveMeshShape::ConcaveMeshShape(TriangleMesh* triangleMesh) : ConcaveShape(CONCAVE_MESH) { } diff --git a/src/collision/shapes/ConcaveMeshShape.h b/src/collision/shapes/ConcaveMeshShape.h index 77d23513..d2129c77 100644 --- a/src/collision/shapes/ConcaveMeshShape.h +++ b/src/collision/shapes/ConcaveMeshShape.h @@ -28,6 +28,7 @@ // Libraries #include "ConcaveShape.h" +#include "collision/TriangleMesh.h" namespace reactphysics3d { @@ -65,9 +66,6 @@ class ConcaveMeshShape : public ConcaveShape { /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; - /// Allocate and return a copy of the object - virtual ConcaveMeshShape* clone(void* allocatedMemory) const; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const; @@ -79,9 +77,6 @@ class ConcaveMeshShape : public ConcaveShape { /// Destructor ~ConcaveMeshShape(); - /// Return true if the collision shape is convex, false if it is concave - virtual bool isConvex() const; - /// Return the local bounds of the shape in x, y and z directions. virtual void getLocalBounds(Vector3& min, Vector3& max) const; @@ -95,16 +90,6 @@ class ConcaveMeshShape : public ConcaveShape { virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; }; -// Return true if the collision shape is convex, false if it is concave -virtual bool isConvex() const { - return false; -} - -// Allocate and return a copy of the object -inline ConcaveMeshShape* ConcaveMeshShape::clone(void* allocatedMemory) const { - return new (allocatedMemory) ConcaveMeshShape(*this); -} - // Return the number of bytes used by the collision shape inline size_t ConcaveMeshShape::getSizeInBytes() const { return sizeof(ConcaveMeshShape); @@ -145,10 +130,7 @@ inline void ConcaveMeshShape::getLocalBounds(Vector3& min, Vector3& max) const { inline void ConcaveMeshShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const { // TODO : Implement this - decimal diag = decimal(0.4) * mass * mRadius * mRadius; - tensor.setAllValues(diag, 0.0, 0.0, - 0.0, diag, 0.0, - 0.0, 0.0, diag); + tensor.setToZero(); } // Update the AABB of a body using its collision shape @@ -162,15 +144,6 @@ inline void ConcaveMeshShape::computeAABB(AABB& aabb, const Transform& transform // TODO : Implement this } -// Test equality between two sphere shapes -inline bool ConcaveMeshShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - const ConcaveMeshShape& otherShape = dynamic_cast(otherCollisionShape); - - // TODO : Implement this - - return false; -} - // Return true if a point is inside the collision shape inline bool ConcaveMeshShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const { diff --git a/src/collision/shapes/ConcaveShape.cpp b/src/collision/shapes/ConcaveShape.cpp index 2a8811fe..99dd2215 100644 --- a/src/collision/shapes/ConcaveShape.cpp +++ b/src/collision/shapes/ConcaveShape.cpp @@ -35,11 +35,6 @@ ConcaveShape::ConcaveShape(CollisionShapeType type) : CollisionShape(type) { } -// Private copy-constructor -ConcaveShape::ConcaveShape(const CollisionShape& shape) : CollisionShape(shape) { - -} - // Destructor ConcaveShape::~ConcaveShape() { diff --git a/src/collision/shapes/ConcaveShape.h b/src/collision/shapes/ConcaveShape.h index ef8c155b..b571a0f4 100644 --- a/src/collision/shapes/ConcaveShape.h +++ b/src/collision/shapes/ConcaveShape.h @@ -65,9 +65,6 @@ class ConcaveShape : public CollisionShape { /// Return true if the collision shape is convex, false if it is concave virtual bool isConvex() const; - - /// Test equality between two shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; }; /// Return true if the collision shape is convex, false if it is concave @@ -75,59 +72,6 @@ inline bool ConcaveShape::isConvex() const { return false; } -// Return the type of the collision shape -/** - * @return The type of the collision shape (box, sphere, cylinder, ...) - */ -inline CollisionShapeType CollisionShape::getType() const { - return mType; -} - -// Return the number of similar created shapes -inline uint CollisionShape::getNbSimilarCreatedShapes() const { - return mNbSimilarCreatedShapes; -} - -// Return the current collision shape margin -/** - * @return The margin (in meters) around the collision shape - */ -inline decimal CollisionShape::getMargin() const { - return mMargin; -} - -// Increment the number of similar allocated collision shapes -inline void CollisionShape::incrementNbSimilarCreatedShapes() { - mNbSimilarCreatedShapes++; -} - -// Decrement the number of similar allocated collision shapes -inline void CollisionShape::decrementNbSimilarCreatedShapes() { - mNbSimilarCreatedShapes--; -} - -// Equality operator between two collision shapes. -/// This methods returns true only if the two collision shapes are of the same type and -/// of the same dimensions. -inline bool CollisionShape::operator==(const CollisionShape& otherCollisionShape) const { - - // If the two collisions shapes are not of the same type (same derived classes) - // we return false - if (mType != otherCollisionShape.mType) return false; - - assert(typeid(*this) == typeid(otherCollisionShape)); - - if (mMargin != otherCollisionShape.mMargin) return false; - - // Check if the two shapes are equal - return otherCollisionShape.isEqualTo(*this); -} - -// Test equality between two shapes -inline bool ConcaveShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - return true; -} - } #endif diff --git a/src/collision/shapes/ConeShape.cpp b/src/collision/shapes/ConeShape.cpp index 146e7b8a..1a4ccda7 100644 --- a/src/collision/shapes/ConeShape.cpp +++ b/src/collision/shapes/ConeShape.cpp @@ -38,7 +38,7 @@ using namespace reactphysics3d; * @param margin Collision margin (in meters) around the collision shape */ ConeShape::ConeShape(decimal radius, decimal height, decimal margin) - : CollisionShape(CONE, margin), mRadius(radius), mHalfHeight(height * decimal(0.5)) { + : ConvexShape(CONE, margin), mRadius(radius), mHalfHeight(height * decimal(0.5)) { assert(mRadius > decimal(0.0)); assert(mHalfHeight > decimal(0.0)); @@ -46,13 +46,6 @@ ConeShape::ConeShape(decimal radius, decimal height, decimal margin) mSinTheta = mRadius / (sqrt(mRadius * mRadius + height * height)); } -// Private copy-constructor -ConeShape::ConeShape(const ConeShape& shape) - : CollisionShape(shape), mRadius(shape.mRadius), mHalfHeight(shape.mHalfHeight), - mSinTheta(shape.mSinTheta){ - -} - // Destructor ConeShape::~ConeShape() { diff --git a/src/collision/shapes/ConeShape.h b/src/collision/shapes/ConeShape.h index 7c1e07cf..b17c4514 100644 --- a/src/collision/shapes/ConeShape.h +++ b/src/collision/shapes/ConeShape.h @@ -86,9 +86,6 @@ class ConeShape : public ConvexShape { /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; - /// Allocate and return a copy of the object - virtual ConeShape* clone(void* allocatedMemory) const; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const; @@ -113,16 +110,8 @@ class ConeShape : public ConvexShape { /// Return the local inertia tensor of the collision shape virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; - - /// Test equality between two cone shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; }; -// Allocate and return a copy of the object -inline ConeShape* ConeShape::clone(void* allocatedMemory) const { - return new (allocatedMemory) ConeShape(*this); -} - // Return the radius /** * @return Radius of the cone (in meters) @@ -176,15 +165,6 @@ inline void ConeShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass 0.0, 0.0, 0.0, diagXZ); } -// Test equality between two cone shapes -inline bool ConeShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - - if (!ConvexShape::isEqualTo(otherCollisionShape)) return false; - - const ConeShape& otherShape = dynamic_cast(otherCollisionShape); - return (mRadius == otherShape.mRadius && mHalfHeight == otherShape.mHalfHeight); -} - // Return true if a point is inside the collision shape inline bool ConeShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const { const decimal radiusHeight = mRadius * (-localPoint.y + mHalfHeight) / diff --git a/src/collision/shapes/ConvexMeshShape.cpp b/src/collision/shapes/ConvexMeshShape.cpp index 02237cc9..799f67fd 100644 --- a/src/collision/shapes/ConvexMeshShape.cpp +++ b/src/collision/shapes/ConvexMeshShape.cpp @@ -40,7 +40,7 @@ using namespace reactphysics3d; */ ConvexMeshShape::ConvexMeshShape(const decimal* arrayVertices, uint nbVertices, int stride, decimal margin) - : CollisionShape(CONVEX_MESH, margin), mNbVertices(nbVertices), mMinBounds(0, 0, 0), + : ConvexShape(CONVEX_MESH, margin), mNbVertices(nbVertices), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(false) { assert(nbVertices > 0); assert(stride > 0); @@ -62,21 +62,11 @@ ConvexMeshShape::ConvexMeshShape(const decimal* arrayVertices, uint nbVertices, /// If you use this constructor, you will need to set the vertices manually one by one using /// the addVertex() method. ConvexMeshShape::ConvexMeshShape(decimal margin) - : CollisionShape(CONVEX_MESH, margin), mNbVertices(0), mMinBounds(0, 0, 0), + : ConvexShape(CONVEX_MESH, margin), mNbVertices(0), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(false) { } -// Private copy-constructor -ConvexMeshShape::ConvexMeshShape(const ConvexMeshShape& shape) - : CollisionShape(shape), mVertices(shape.mVertices), mNbVertices(shape.mNbVertices), - mMinBounds(shape.mMinBounds), mMaxBounds(shape.mMaxBounds), - mIsEdgesInformationUsed(shape.mIsEdgesInformationUsed), - mEdgesAdjacencyList(shape.mEdgesAdjacencyList) { - - assert(mNbVertices == mVertices.size()); -} - // Destructor ConvexMeshShape::~ConvexMeshShape() { @@ -209,36 +199,6 @@ void ConvexMeshShape::recalculateBounds() { mMinBounds -= Vector3(mMargin, mMargin, mMargin); } -// Test equality between two cone shapes -bool ConvexMeshShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - - if (!ConvexShape::isEqualTo(otherCollisionShape)) return false; - - const ConvexMeshShape& otherShape = dynamic_cast(otherCollisionShape); - - assert(mNbVertices == mVertices.size()); - - if (mNbVertices != otherShape.mNbVertices) return false; - - if (mIsEdgesInformationUsed != otherShape.mIsEdgesInformationUsed) return false; - - if (mEdgesAdjacencyList.size() != otherShape.mEdgesAdjacencyList.size()) return false; - - // Check that the vertices are the same - for (uint i=0; imBody->mWorld.mCollisionDetection.mNarrowPhaseGJKAlgorithm.raycast( diff --git a/src/collision/shapes/ConvexMeshShape.h b/src/collision/shapes/ConvexMeshShape.h index 80d5cbcb..348991ae 100644 --- a/src/collision/shapes/ConvexMeshShape.h +++ b/src/collision/shapes/ConvexMeshShape.h @@ -110,9 +110,6 @@ class ConvexMeshShape : public ConvexShape { /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; - /// Allocate and return a copy of the object - virtual ConvexMeshShape* clone(void* allocatedMemory) const; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const; @@ -136,9 +133,6 @@ class ConvexMeshShape : public ConvexShape { /// Return the local inertia tensor of the collision shape. virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; - /// Test equality between two collision shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; - /// Add a vertex into the convex mesh void addVertex(const Vector3& vertex); @@ -153,11 +147,6 @@ class ConvexMeshShape : public ConvexShape { void setIsEdgesInformationUsed(bool isEdgesUsed); }; -// Allocate and return a copy of the object -inline ConvexMeshShape* ConvexMeshShape::clone(void* allocatedMemory) const { - return new (allocatedMemory) ConvexMeshShape(*this); -} - // Return the number of bytes used by the collision shape inline size_t ConvexMeshShape::getSizeInBytes() const { return sizeof(ConvexMeshShape); diff --git a/src/collision/shapes/ConvexShape.cpp b/src/collision/shapes/ConvexShape.cpp index 1d27ad27..3ec13b2f 100644 --- a/src/collision/shapes/ConvexShape.cpp +++ b/src/collision/shapes/ConvexShape.cpp @@ -32,13 +32,7 @@ using namespace reactphysics3d; // Constructor ConvexShape::ConvexShape(CollisionShapeType type, decimal margin) - : CollisionShape(type), mMargin(margin) { - -} - -// Private copy-constructor -ConvexShape::ConvexShape(const CollisionShape& shape) - : CollisionShape(shape), mMargin(shape.mMargin) { + : CollisionShape(type), mMargin(margin) { } diff --git a/src/collision/shapes/ConvexShape.h b/src/collision/shapes/ConvexShape.h index 16be7065..bc515e33 100644 --- a/src/collision/shapes/ConvexShape.h +++ b/src/collision/shapes/ConvexShape.h @@ -81,8 +81,10 @@ class ConvexShape : public CollisionShape { /// Return true if the collision shape is convex, false if it is concave virtual bool isConvex() const; - /// Test equality between two shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; + // -------------------- Friendship -------------------- // + + friend class GJKAlgorithm; + friend class EPAAlgorithm; }; /// Return true if the collision shape is convex, false if it is concave @@ -94,48 +96,10 @@ inline bool ConvexShape::isConvex() const { /** * @return The margin (in meters) around the collision shape */ -inline decimal CollisionShape::getMargin() const { +inline decimal ConvexShape::getMargin() const { return mMargin; } -// Return the type of the collision shape -/** - * @return The type of the collision shape (box, sphere, cylinder, ...) - */ -inline CollisionShapeType CollisionShape::getType() const { - return mType; -} - -// Return the number of similar created shapes -inline uint CollisionShape::getNbSimilarCreatedShapes() const { - return mNbSimilarCreatedShapes; -} - -// Return the current collision shape margin -/** - * @return The margin (in meters) around the collision shape - */ -inline decimal CollisionShape::getMargin() const { - return mMargin; -} - -// Increment the number of similar allocated collision shapes -inline void CollisionShape::incrementNbSimilarCreatedShapes() { - mNbSimilarCreatedShapes++; -} - -// Decrement the number of similar allocated collision shapes -inline void CollisionShape::decrementNbSimilarCreatedShapes() { - mNbSimilarCreatedShapes--; -} - -// Test equality between two shapes -inline bool ConvexShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - - const ConvexShape& otherShape = static_cast(otherCollisionShape); - return (mMargin == otherShape.mMargin); -} - } #endif diff --git a/src/collision/shapes/CylinderShape.cpp b/src/collision/shapes/CylinderShape.cpp index 90dc9e0c..1388ab51 100644 --- a/src/collision/shapes/CylinderShape.cpp +++ b/src/collision/shapes/CylinderShape.cpp @@ -37,18 +37,12 @@ using namespace reactphysics3d; * @param margin Collision margin (in meters) around the collision shape */ CylinderShape::CylinderShape(decimal radius, decimal height, decimal margin) - : CollisionShape(CYLINDER, margin), mRadius(radius), + : ConvexShape(CYLINDER, margin), mRadius(radius), mHalfHeight(height/decimal(2.0)) { assert(radius > decimal(0.0)); assert(height > decimal(0.0)); } -// Private copy-constructor -CylinderShape::CylinderShape(const CylinderShape& shape) - : CollisionShape(shape), mRadius(shape.mRadius), mHalfHeight(shape.mHalfHeight) { - -} - // Destructor CylinderShape::~CylinderShape() { diff --git a/src/collision/shapes/CylinderShape.h b/src/collision/shapes/CylinderShape.h index 73266ad4..546f87b2 100644 --- a/src/collision/shapes/CylinderShape.h +++ b/src/collision/shapes/CylinderShape.h @@ -83,9 +83,6 @@ class CylinderShape : public ConvexShape { /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; - /// Allocate and return a copy of the object - virtual CylinderShape* clone(void* allocatedMemory) const; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const; @@ -110,16 +107,8 @@ class CylinderShape : public ConvexShape { /// Return the local inertia tensor of the collision shape virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; - - /// Test equality between two cylinder shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; }; -// Allocate and return a copy of the object -inline CylinderShape* CylinderShape::clone(void* allocatedMemory) const { - return new (allocatedMemory) CylinderShape(*this); -} - // Return the radius /** * @return Radius of the cylinder (in meters) @@ -173,15 +162,6 @@ inline void CylinderShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal 0.0, 0.0, diag); } -// Test equality between two cylinder shapes -inline bool CylinderShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - - if (!ConvexShape::isEqualTo(otherCollisionShape)) return false; - - const CylinderShape& otherShape = dynamic_cast(otherCollisionShape); - return (mRadius == otherShape.mRadius && mHalfHeight == otherShape.mHalfHeight); -} - // Return true if a point is inside the collision shape inline bool CylinderShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const{ return ((localPoint.x * localPoint.x + localPoint.z * localPoint.z) < mRadius * mRadius && diff --git a/src/collision/shapes/SphereShape.cpp b/src/collision/shapes/SphereShape.cpp index 7cae0b1a..c1b119eb 100644 --- a/src/collision/shapes/SphereShape.cpp +++ b/src/collision/shapes/SphereShape.cpp @@ -35,16 +35,10 @@ using namespace reactphysics3d; /** * @param radius Radius of the sphere (in meters) */ -SphereShape::SphereShape(decimal radius) : CollisionShape(SPHERE, radius), mRadius(radius) { +SphereShape::SphereShape(decimal radius) : ConvexShape(SPHERE, radius), mRadius(radius) { assert(radius > decimal(0.0)); } -// Private copy-constructor -SphereShape::SphereShape(const SphereShape& shape) - : CollisionShape(shape), mRadius(shape.mRadius) { - -} - // Destructor SphereShape::~SphereShape() { diff --git a/src/collision/shapes/SphereShape.h b/src/collision/shapes/SphereShape.h index 911d487d..0928311c 100644 --- a/src/collision/shapes/SphereShape.h +++ b/src/collision/shapes/SphereShape.h @@ -73,9 +73,6 @@ class SphereShape : public ConvexShape { /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; - /// Allocate and return a copy of the object - virtual SphereShape* clone(void* allocatedMemory) const; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const; @@ -100,16 +97,8 @@ class SphereShape : public ConvexShape { /// Update the AABB of a body using its collision shape virtual void computeAABB(AABB& aabb, const Transform& transform); - - /// Test equality between two sphere shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; }; -// Allocate and return a copy of the object -inline SphereShape* SphereShape::clone(void* allocatedMemory) const { - return new (allocatedMemory) SphereShape(*this); -} - // Get the radius of the sphere /** * @return Radius of the sphere (in meters) @@ -195,15 +184,6 @@ inline void SphereShape::computeAABB(AABB& aabb, const Transform& transform) { aabb.setMax(transform.getPosition() + extents); } -// Test equality between two sphere shapes -inline bool SphereShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - - if (!ConvexShape::isEqualTo(otherCollisionShape)) return false; - - const SphereShape& otherShape = dynamic_cast(otherCollisionShape); - return (mRadius == otherShape.mRadius); -} - // Return true if a point is inside the collision shape inline bool SphereShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const { return (localPoint.lengthSquare() < mRadius * mRadius); diff --git a/src/collision/shapes/TriangleShape.cpp b/src/collision/shapes/TriangleShape.cpp index 9537c2ce..c6c4323d 100644 --- a/src/collision/shapes/TriangleShape.cpp +++ b/src/collision/shapes/TriangleShape.cpp @@ -40,20 +40,12 @@ using namespace reactphysics3d; */ TriangleShape::TriangleShape(const Vector3& point1, const Vector3& point2, const Vector3& point3, decimal margin) - : CollisionShape(TRIANGLE, margin) { + : ConvexShape(TRIANGLE, margin) { mPoints[0] = point1; mPoints[1] = point2; mPoints[2] = point3; } -// Private copy-constructor -TriangleShape::TriangleShape(const TriangleShape& shape) - : CollisionShape(shape) { - mPoints[0] = shape.mPoints[0]; - mPoints[1] = shape.mPoints[1]; - mPoints[2] = shape.mPoints[2]; -} - // Destructor TriangleShape::~TriangleShape() { diff --git a/src/collision/shapes/TriangleShape.h b/src/collision/shapes/TriangleShape.h index fee38302..8309fc1f 100644 --- a/src/collision/shapes/TriangleShape.h +++ b/src/collision/shapes/TriangleShape.h @@ -69,9 +69,6 @@ class TriangleShape : public ConvexShape { /// Raycast method with feedback information virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; - /// Allocate and return a copy of the object - virtual TriangleShape* clone(void* allocatedMemory) const; - /// Return the number of bytes used by the collision shape virtual size_t getSizeInBytes() const; @@ -94,16 +91,8 @@ class TriangleShape : public ConvexShape { /// Update the AABB of a body using its collision shape virtual void computeAABB(AABB& aabb, const Transform& transform); - - /// Test equality between two triangle shapes - virtual bool isEqualTo(const CollisionShape& otherCollisionShape) const; }; -// Allocate and return a copy of the object -inline TriangleShape* TriangleShape::clone(void* allocatedMemory) const { - return new (allocatedMemory) TriangleShape(*this); -} - // Return the number of bytes used by the collision shape inline size_t TriangleShape::getSizeInBytes() const { return sizeof(TriangleShape); @@ -133,9 +122,9 @@ inline Vector3 TriangleShape::getLocalSupportPointWithoutMargin(const Vector3& d */ inline void TriangleShape::getLocalBounds(Vector3& min, Vector3& max) const { - const Vector3 xAxis(worldPoint1.X, worldPoint2.X, worldPoint3.X); - const Vector3 yAxis(worldPoint1.Y, worldPoint2.Y, worldPoint3.Y); - const Vector3 zAxis(worldPoint1.Z, worldPoint2.Z, worldPoint3.Z); + const Vector3 xAxis(mPoints[0].x, mPoints[1].x, mPoints[2].x); + const Vector3 yAxis(mPoints[0].y, mPoints[1].y, mPoints[2].y); + const Vector3 zAxis(mPoints[0].z, mPoints[1].z, mPoints[2].z); min.setAllValues(xAxis.getMinValue(), yAxis.getMinValue(), zAxis.getMinValue()); max.setAllValues(xAxis.getMaxValue(), yAxis.getMaxValue(), zAxis.getMaxValue()); } @@ -162,24 +151,13 @@ inline void TriangleShape::computeAABB(AABB& aabb, const Transform& transform) { const Vector3 worldPoint2 = transform * mPoints[1]; const Vector3 worldPoint3 = transform * mPoints[2]; - const Vector3 xAxis(worldPoint1.X, worldPoint2.X, worldPoint3.X); - const Vector3 yAxis(worldPoint1.Y, worldPoint2.Y, worldPoint3.Y); - const Vector3 zAxis(worldPoint1.Z, worldPoint2.Z, worldPoint3.Z); + const Vector3 xAxis(worldPoint1.x, worldPoint2.x, worldPoint3.x); + const Vector3 yAxis(worldPoint1.y, worldPoint2.y, worldPoint3.y); + const Vector3 zAxis(worldPoint1.z, worldPoint2.z, worldPoint3.z); aabb.setMin(Vector3(xAxis.getMinValue(), yAxis.getMinValue(), zAxis.getMinValue())); aabb.setMax(Vector3(xAxis.getMaxValue(), yAxis.getMaxValue(), zAxis.getMaxValue())); } -// Test equality between two triangle shapes -inline bool TriangleShape::isEqualTo(const CollisionShape& otherCollisionShape) const { - - if (!ConvexShape::isEqualTo(otherCollisionShape)) return false; - - const TriangleShape& otherShape = dynamic_cast(otherCollisionShape); - return (mPoints[0] == otherShape.mPoints[0] && - mPoints[1] == otherShape.mPoints[1] && - mPoints[2] == otherShape.mPoints[2]); -} - // Return true if a point is inside the collision shape inline bool TriangleShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const { return false; diff --git a/src/engine/CollisionWorld.cpp b/src/engine/CollisionWorld.cpp index 41b8bf8b..e1df2a31 100644 --- a/src/engine/CollisionWorld.cpp +++ b/src/engine/CollisionWorld.cpp @@ -49,7 +49,6 @@ CollisionWorld::~CollisionWorld() { destroyCollisionBody(*itToRemove); } - assert(mCollisionShapes.empty()); assert(mBodies.empty()); } @@ -118,70 +117,6 @@ bodyindex CollisionWorld::computeNextAvailableBodyID() { return bodyID; } -// Create a new collision shape in the world. -/// First, this methods checks that the new collision shape does not exist yet in the -/// world. If it already exists, we do not allocate memory for a new one but instead -/// we reuse the existing one. The goal is to only allocate memory for a single -/// collision shape if this one is used for several bodies in the world. To allocate -/// memory for a new collision shape, we use the memory allocator. -CollisionShape* CollisionWorld::createCollisionShape(const CollisionShape& collisionShape) { - - // Check if there is already a similar collision shape in the world - std::list::iterator it; - for (it = mCollisionShapes.begin(); it != mCollisionShapes.end(); ++it) { - - if (collisionShape == (*(*it))) { - - // Increment the number of similar created shapes - (*it)->incrementNbSimilarCreatedShapes(); - - // A similar collision shape already exists in the world, so we do not - // create a new one but we simply return a pointer to the existing one - return (*it); - } - } - - // A similar collision shape does not already exist in the world, so we create a - // new one and add it to the world - void* allocatedMemory = mMemoryAllocator.allocate(collisionShape.getSizeInBytes()); - CollisionShape* newCollisionShape = collisionShape.clone(allocatedMemory); - mCollisionShapes.push_back(newCollisionShape); - - newCollisionShape->incrementNbSimilarCreatedShapes(); - - // Return a pointer to the new collision shape - return newCollisionShape; -} - - -// Remove a collision shape. -/// First, we check if another body is still using the same collision shape. If so, -/// we keep the allocated collision shape. If it is not the case, we can deallocate -/// the memory associated with the collision shape. -void CollisionWorld::removeCollisionShape(CollisionShape* collisionShape) { - - assert(collisionShape->getNbSimilarCreatedShapes() != 0); - - // Decrement the number of bodies using the same collision shape - collisionShape->decrementNbSimilarCreatedShapes(); - - // If no other body is using the collision shape in the world - if (collisionShape->getNbSimilarCreatedShapes() == 0) { - - // Remove the shape from the set of shapes in the world - mCollisionShapes.remove(collisionShape); - - // Compute the size (in bytes) of the collision shape - size_t nbBytesShape = collisionShape->getSizeInBytes(); - - // Call the destructor of the collision shape - collisionShape->~CollisionShape(); - - // Deallocate the memory used by the collision shape - mMemoryAllocator.release(collisionShape, nbBytesShape); - } -} - // Reset all the contact manifolds linked list of each body void CollisionWorld::resetContactManifoldListsOfBodies() { diff --git a/src/engine/CollisionWorld.h b/src/engine/CollisionWorld.h index 1c32e78f..009be590 100644 --- a/src/engine/CollisionWorld.h +++ b/src/engine/CollisionWorld.h @@ -66,9 +66,6 @@ class CollisionWorld { /// All the bodies (rigid and soft) of the world std::set mBodies; - /// All the collision shapes of the world - std::list mCollisionShapes; - /// Current body ID bodyindex mCurrentBodyID; @@ -92,12 +89,6 @@ class CollisionWorld { /// Return the next available body ID bodyindex computeNextAvailableBodyID(); - /// Remove a collision shape. - void removeCollisionShape(CollisionShape* collisionShape); - - /// Create a new collision shape in the world. - CollisionShape* createCollisionShape(const CollisionShape& collisionShape); - /// Reset all the contact manifolds linked list of each body void resetContactManifoldListsOfBodies(); diff --git a/src/mathematics/mathematics_functions.h b/src/mathematics/mathematics_functions.h index d88ed46a..b6106648 100644 --- a/src/mathematics/mathematics_functions.h +++ b/src/mathematics/mathematics_functions.h @@ -28,7 +28,6 @@ // Libraries #include "configuration.h" -#include "mathematics/Vector3.h" #include "decimal.h" #include diff --git a/test/tests/collision/TestCollisionWorld.h b/test/tests/collision/TestCollisionWorld.h index 3bffee87..fe89984b 100644 --- a/test/tests/collision/TestCollisionWorld.h +++ b/test/tests/collision/TestCollisionWorld.h @@ -112,11 +112,16 @@ class TestCollisionWorld : public Test { CollisionBody* mSphere2Body; CollisionBody* mCylinderBody; - // Shapes - ProxyShape* mBoxShape; - ProxyShape* mSphere1Shape; - ProxyShape* mSphere2Shape; - ProxyShape* mCylinderShape; + // Collision shapes + BoxShape* mBoxShape; + SphereShape* mSphereShape; + CylinderShape* mCylinderShape; + + // Proxy shapes + ProxyShape* mBoxProxyShape; + ProxyShape* mSphere1ProxyShape; + ProxyShape* mSphere2ProxyShape; + ProxyShape* mCylinderProxyShape; // Collision callback class WorldCollisionCallback mCollisionCallback; @@ -134,28 +139,28 @@ class TestCollisionWorld : public Test { // Create the bodies Transform boxTransform(Vector3(10, 0, 0), Quaternion::identity()); mBoxBody = mWorld->createCollisionBody(boxTransform); - BoxShape boxShape(Vector3(3, 3, 3)); - mBoxShape = mBoxBody->addCollisionShape(boxShape, Transform::identity()); + mBoxShape = new BoxShape(Vector3(3, 3, 3)); + mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, Transform::identity()); - SphereShape sphereShape(3.0); + mSphereShape = new SphereShape(3.0); Transform sphere1Transform(Vector3(10,5, 0), Quaternion::identity()); mSphere1Body = mWorld->createCollisionBody(sphere1Transform); - mSphere1Shape = mSphere1Body->addCollisionShape(sphereShape, Transform::identity()); + mSphere1ProxyShape = mSphere1Body->addCollisionShape(mSphereShape, Transform::identity()); Transform sphere2Transform(Vector3(30, 10, 10), Quaternion::identity()); mSphere2Body = mWorld->createCollisionBody(sphere2Transform); - mSphere2Shape = mSphere2Body->addCollisionShape(sphereShape, Transform::identity()); + mSphere2ProxyShape = mSphere2Body->addCollisionShape(mSphereShape, Transform::identity()); Transform cylinderTransform(Vector3(10, -5, 0), Quaternion::identity()); mCylinderBody = mWorld->createCollisionBody(cylinderTransform); - CylinderShape cylinderShape(2, 5); - mCylinderShape = mCylinderBody->addCollisionShape(cylinderShape, Transform::identity()); + mCylinderShape = new CylinderShape(2, 5); + mCylinderProxyShape = mCylinderBody->addCollisionShape(mCylinderShape, Transform::identity()); // Assign collision categories to proxy shapes - mBoxShape->setCollisionCategoryBits(CATEGORY_1); - mSphere1Shape->setCollisionCategoryBits(CATEGORY_1); - mSphere2Shape->setCollisionCategoryBits(CATEGORY_2); - mCylinderShape->setCollisionCategoryBits(CATEGORY_3); + mBoxProxyShape->setCollisionCategoryBits(CATEGORY_1); + mSphere1ProxyShape->setCollisionCategoryBits(CATEGORY_1); + mSphere2ProxyShape->setCollisionCategoryBits(CATEGORY_2); + mCylinderProxyShape->setCollisionCategoryBits(CATEGORY_3); mCollisionCallback.boxBody = mBoxBody; mCollisionCallback.sphere1Body = mSphere1Body; @@ -163,6 +168,13 @@ class TestCollisionWorld : public Test { mCollisionCallback.cylinderBody = mCylinderBody; } + /// Destructor + ~TestCollisionWorld() { + delete mBoxShape; + delete mSphereShape; + delete mCylinderShape; + } + /// Run the tests void run() { @@ -183,10 +195,10 @@ class TestCollisionWorld : public Test { test(!mWorld->testAABBOverlap(mSphere1Body, mCylinderBody)); test(!mWorld->testAABBOverlap(mSphere1Body, mSphere2Body)); - test(mWorld->testAABBOverlap(mBoxShape, mSphere1Shape)); - test(mWorld->testAABBOverlap(mBoxShape, mCylinderShape)); - test(!mWorld->testAABBOverlap(mSphere1Shape, mCylinderShape)); - test(!mWorld->testAABBOverlap(mSphere1Shape, mSphere2Shape)); + test(mWorld->testAABBOverlap(mBoxProxyShape, mSphere1ProxyShape)); + test(mWorld->testAABBOverlap(mBoxProxyShape, mCylinderProxyShape)); + test(!mWorld->testAABBOverlap(mSphere1ProxyShape, mCylinderProxyShape)); + test(!mWorld->testAABBOverlap(mSphere1ProxyShape, mSphere2ProxyShape)); mCollisionCallback.reset(); mWorld->testCollision(mCylinderBody, &mCollisionCallback); @@ -210,14 +222,14 @@ class TestCollisionWorld : public Test { test(!mCollisionCallback.sphere1CollideWithSphere2); mCollisionCallback.reset(); - mWorld->testCollision(mCylinderShape, &mCollisionCallback); + mWorld->testCollision(mCylinderProxyShape, &mCollisionCallback); test(!mCollisionCallback.boxCollideWithSphere1); test(mCollisionCallback.boxCollideWithCylinder); test(!mCollisionCallback.sphere1CollideWithCylinder); test(!mCollisionCallback.sphere1CollideWithSphere2); mCollisionCallback.reset(); - mWorld->testCollision(mBoxShape, mCylinderShape, &mCollisionCallback); + mWorld->testCollision(mBoxProxyShape, mCylinderProxyShape, &mCollisionCallback); test(!mCollisionCallback.boxCollideWithSphere1); test(mCollisionCallback.boxCollideWithCylinder); test(!mCollisionCallback.sphere1CollideWithCylinder); @@ -268,10 +280,10 @@ class TestCollisionWorld : public Test { test(!mWorld->testAABBOverlap(mSphere1Body, mCylinderBody)); test(!mWorld->testAABBOverlap(mSphere1Body, mSphere2Body)); - test(!mWorld->testAABBOverlap(mBoxShape, mSphere1Shape)); - test(!mWorld->testAABBOverlap(mBoxShape, mCylinderShape)); - test(!mWorld->testAABBOverlap(mSphere1Shape, mCylinderShape)); - test(!mWorld->testAABBOverlap(mSphere1Shape, mSphere2Shape)); + test(!mWorld->testAABBOverlap(mBoxProxyShape, mSphere1ProxyShape)); + test(!mWorld->testAABBOverlap(mBoxProxyShape, mCylinderProxyShape)); + test(!mWorld->testAABBOverlap(mSphere1ProxyShape, mCylinderProxyShape)); + test(!mWorld->testAABBOverlap(mSphere1ProxyShape, mSphere2ProxyShape)); mBoxBody->setIsActive(true); mCylinderBody->setIsActive(true); @@ -280,10 +292,10 @@ class TestCollisionWorld : public Test { // --------- Test collision with collision filtering -------- // - mBoxShape->setCollideWithMaskBits(CATEGORY_1 | CATEGORY_3); - mSphere1Shape->setCollideWithMaskBits(CATEGORY_1 | CATEGORY_2); - mSphere2Shape->setCollideWithMaskBits(CATEGORY_1); - mCylinderShape->setCollideWithMaskBits(CATEGORY_1); + mBoxProxyShape->setCollideWithMaskBits(CATEGORY_1 | CATEGORY_3); + mSphere1ProxyShape->setCollideWithMaskBits(CATEGORY_1 | CATEGORY_2); + mSphere2ProxyShape->setCollideWithMaskBits(CATEGORY_1); + mCylinderProxyShape->setCollideWithMaskBits(CATEGORY_1); mCollisionCallback.reset(); mWorld->testCollision(&mCollisionCallback); @@ -302,10 +314,10 @@ class TestCollisionWorld : public Test { test(!mCollisionCallback.sphere1CollideWithCylinder); test(mCollisionCallback.sphere1CollideWithSphere2); - mBoxShape->setCollideWithMaskBits(CATEGORY_2); - mSphere1Shape->setCollideWithMaskBits(CATEGORY_2); - mSphere2Shape->setCollideWithMaskBits(CATEGORY_3); - mCylinderShape->setCollideWithMaskBits(CATEGORY_1); + mBoxProxyShape->setCollideWithMaskBits(CATEGORY_2); + mSphere1ProxyShape->setCollideWithMaskBits(CATEGORY_2); + mSphere2ProxyShape->setCollideWithMaskBits(CATEGORY_3); + mCylinderProxyShape->setCollideWithMaskBits(CATEGORY_1); mCollisionCallback.reset(); mWorld->testCollision(&mCollisionCallback); @@ -317,10 +329,10 @@ class TestCollisionWorld : public Test { // Move sphere 1 to collide with box mSphere1Body->setTransform(Transform(Vector3(10, 5, 0), Quaternion::identity())); - mBoxShape->setCollideWithMaskBits(0xFFFF); - mSphere1Shape->setCollideWithMaskBits(0xFFFF); - mSphere2Shape->setCollideWithMaskBits(0xFFFF); - mCylinderShape->setCollideWithMaskBits(0xFFFF); + mBoxProxyShape->setCollideWithMaskBits(0xFFFF); + mSphere1ProxyShape->setCollideWithMaskBits(0xFFFF); + mSphere2ProxyShape->setCollideWithMaskBits(0xFFFF); + mCylinderProxyShape->setCollideWithMaskBits(0xFFFF); } }; diff --git a/test/tests/collision/TestPointInside.h b/test/tests/collision/TestPointInside.h index bea06999..41774082 100644 --- a/test/tests/collision/TestPointInside.h +++ b/test/tests/collision/TestPointInside.h @@ -61,20 +61,29 @@ class TestPointInside : public Test { CollisionBody* mCylinderBody; CollisionBody* mCompoundBody; + // Collision shapes + BoxShape* mBoxShape; + SphereShape* mSphereShape; + CapsuleShape* mCapsuleShape; + ConeShape* mConeShape; + ConvexMeshShape* mConvexMeshShape; + ConvexMeshShape* mConvexMeshShapeBodyEdgesInfo; + CylinderShape* mCylinderShape; + // Transform Transform mBodyTransform; Transform mShapeTransform; Transform mLocalShapeToWorld; Transform mLocalShape2ToWorld; - // Collision Shapes - ProxyShape* mBoxShape; - ProxyShape* mSphereShape; - ProxyShape* mCapsuleShape; - ProxyShape* mConeShape; - ProxyShape* mConvexMeshShape; - ProxyShape* mConvexMeshShapeEdgesInfo; - ProxyShape* mCylinderShape; + // Proxy Shapes + ProxyShape* mBoxProxyShape; + ProxyShape* mSphereProxyShape; + ProxyShape* mCapsuleProxyShape; + ProxyShape* mConeProxyShape; + ProxyShape* mConvexMeshProxyShape; + ProxyShape* mConvexMeshProxyShapeEdgesInfo; + ProxyShape* mCylinderProxyShape; public : @@ -110,65 +119,76 @@ class TestPointInside : public Test { mLocalShapeToWorld = mBodyTransform * mShapeTransform; // Create collision shapes - BoxShape boxShape(Vector3(2, 3, 4), 0); - mBoxShape = mBoxBody->addCollisionShape(boxShape, mShapeTransform); + mBoxShape = new BoxShape(Vector3(2, 3, 4), 0); + mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform); - SphereShape sphereShape(3); - mSphereShape = mSphereBody->addCollisionShape(sphereShape, mShapeTransform); + mSphereShape = new SphereShape(3); + mSphereProxyShape = mSphereBody->addCollisionShape(mSphereShape, mShapeTransform); - CapsuleShape capsuleShape(2, 10); - mCapsuleShape = mCapsuleBody->addCollisionShape(capsuleShape, mShapeTransform); + mCapsuleShape = new CapsuleShape(2, 10); + mCapsuleProxyShape = mCapsuleBody->addCollisionShape(mCapsuleShape, mShapeTransform); - ConeShape coneShape(2, 6, 0); - mConeShape = mConeBody->addCollisionShape(coneShape, mShapeTransform); + mConeShape = new ConeShape(2, 6, 0); + mConeProxyShape = mConeBody->addCollisionShape(mConeShape, mShapeTransform); - ConvexMeshShape convexMeshShape(0); // Box of dimension (2, 3, 4) - convexMeshShape.addVertex(Vector3(-2, -3, -4)); - convexMeshShape.addVertex(Vector3(2, -3, -4)); - convexMeshShape.addVertex(Vector3(2, -3, 4)); - convexMeshShape.addVertex(Vector3(-2, -3, 4)); - convexMeshShape.addVertex(Vector3(-2, 3, -4)); - convexMeshShape.addVertex(Vector3(2, 3, -4)); - convexMeshShape.addVertex(Vector3(2, 3, 4)); - convexMeshShape.addVertex(Vector3(-2, 3, 4)); - mConvexMeshShape = mConvexMeshBody->addCollisionShape(convexMeshShape, mShapeTransform); + mConvexMeshShape = new ConvexMeshShape(0); // Box of dimension (2, 3, 4) + mConvexMeshShape->addVertex(Vector3(-2, -3, -4)); + mConvexMeshShape->addVertex(Vector3(2, -3, -4)); + mConvexMeshShape->addVertex(Vector3(2, -3, 4)); + mConvexMeshShape->addVertex(Vector3(-2, -3, 4)); + mConvexMeshShape->addVertex(Vector3(-2, 3, -4)); + mConvexMeshShape->addVertex(Vector3(2, 3, -4)); + mConvexMeshShape->addVertex(Vector3(2, 3, 4)); + mConvexMeshShape->addVertex(Vector3(-2, 3, 4)); + mConvexMeshProxyShape = mConvexMeshBody->addCollisionShape(mConvexMeshShape, mShapeTransform); - ConvexMeshShape convexMeshShapeEdgesInfo(0); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, -3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, -3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, -3, 4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, -3, 4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, 3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, 3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, 3, 4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, 3, 4)); - convexMeshShapeEdgesInfo.addEdge(0, 1); - convexMeshShapeEdgesInfo.addEdge(1, 2); - convexMeshShapeEdgesInfo.addEdge(2, 3); - convexMeshShapeEdgesInfo.addEdge(0, 3); - convexMeshShapeEdgesInfo.addEdge(4, 5); - convexMeshShapeEdgesInfo.addEdge(5, 6); - convexMeshShapeEdgesInfo.addEdge(6, 7); - convexMeshShapeEdgesInfo.addEdge(4, 7); - convexMeshShapeEdgesInfo.addEdge(0, 4); - convexMeshShapeEdgesInfo.addEdge(1, 5); - convexMeshShapeEdgesInfo.addEdge(2, 6); - convexMeshShapeEdgesInfo.addEdge(3, 7); - convexMeshShapeEdgesInfo.setIsEdgesInformationUsed(true); - mConvexMeshShapeEdgesInfo = mConvexMeshBodyEdgesInfo->addCollisionShape( - convexMeshShapeEdgesInfo, + mConvexMeshShapeBodyEdgesInfo = new ConvexMeshShape(0); + mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(-2, -3, -4)); + mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(2, -3, -4)); + mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(2, -3, 4)); + mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(-2, -3, 4)); + mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(-2, 3, -4)); + mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(2, 3, -4)); + mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(2, 3, 4)); + mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(-2, 3, 4)); + mConvexMeshShapeBodyEdgesInfo->addEdge(0, 1); + mConvexMeshShapeBodyEdgesInfo->addEdge(1, 2); + mConvexMeshShapeBodyEdgesInfo->addEdge(2, 3); + mConvexMeshShapeBodyEdgesInfo->addEdge(0, 3); + mConvexMeshShapeBodyEdgesInfo->addEdge(4, 5); + mConvexMeshShapeBodyEdgesInfo->addEdge(5, 6); + mConvexMeshShapeBodyEdgesInfo->addEdge(6, 7); + mConvexMeshShapeBodyEdgesInfo->addEdge(4, 7); + mConvexMeshShapeBodyEdgesInfo->addEdge(0, 4); + mConvexMeshShapeBodyEdgesInfo->addEdge(1, 5); + mConvexMeshShapeBodyEdgesInfo->addEdge(2, 6); + mConvexMeshShapeBodyEdgesInfo->addEdge(3, 7); + mConvexMeshShapeBodyEdgesInfo->setIsEdgesInformationUsed(true); + mConvexMeshProxyShapeEdgesInfo = mConvexMeshBodyEdgesInfo->addCollisionShape( + mConvexMeshShapeBodyEdgesInfo, mShapeTransform); - CylinderShape cylinderShape(3, 8, 0); - mCylinderShape = mCylinderBody->addCollisionShape(cylinderShape, mShapeTransform); + mCylinderShape = new CylinderShape(3, 8, 0); + mCylinderProxyShape = mCylinderBody->addCollisionShape(mCylinderShape, mShapeTransform); // Compound shape is a cylinder and a sphere Vector3 positionShape2(Vector3(4, 2, -3)); Quaternion orientationShape2(-3 *PI / 8, 1.5 * PI/ 3, PI / 13); Transform shapeTransform2(positionShape2, orientationShape2); mLocalShape2ToWorld = mBodyTransform * shapeTransform2; - mCompoundBody->addCollisionShape(cylinderShape, mShapeTransform); - mCompoundBody->addCollisionShape(sphereShape, shapeTransform2); + mCompoundBody->addCollisionShape(mCylinderShape, mShapeTransform); + mCompoundBody->addCollisionShape(mSphereShape, shapeTransform2); + } + + /// Destructor + ~TestPointInside() { + delete mBoxShape; + delete mSphereShape; + delete mCapsuleShape; + delete mConeShape; + delete mConvexMeshShape; + delete mConvexMeshShapeBodyEdgesInfo; + delete mCylinderShape; } /// Run the tests @@ -213,30 +233,30 @@ class TestPointInside : public Test { test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); // Tests with ProxyBoxShape - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); - test(mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); + test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); - test(!mBoxShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); + test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); } /// Test the ProxySphereShape::testPointInside() and @@ -266,26 +286,26 @@ class TestPointInside : public Test { test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5))); // Tests with ProxySphereShape - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -1.5))); - test(mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 1.5))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -1.5))); + test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 1.5))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(-2, -2, -2))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5))); - test(!mSphereShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2, -2, -2))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5))); + test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5))); } /// Test the ProxyCapsuleShape::testPointInside() and @@ -340,51 +360,51 @@ class TestPointInside : public Test { test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.5, -5, -1.7))); // Tests with ProxyCapsuleShape - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, -6.9, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 6.9, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, -0.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 1.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -1.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 5, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 5, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, 0.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, -0.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 1.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -1.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, -5, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -6.9, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 6.9, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, -0.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 1.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -1.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 5, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 5, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, 0.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, -0.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 1.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -1.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, -5, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4))); + test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, -7.1, 0))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 7.1, 0))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.1))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -2.1))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 2.1))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -2.1))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 5, 0))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 5, 0))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, 5, 1.6))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, 5, -1.7))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 2.1))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -2.1))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, -5, 0))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -5, 0))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -5, 1.6))); - test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -5, -1.7))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -7.1, 0))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 7.1, 0))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.1))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -2.1))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 2.1))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -2.1))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 5, 0))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 5, 0))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, 5, 1.6))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, 5, -1.7))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 2.1))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -2.1))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, -5, 0))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -5, 0))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -5, 1.6))); + test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -5, -1.7))); } /// Test the ProxyConeShape::testPointInside() and @@ -428,40 +448,40 @@ class TestPointInside : public Test { test(!mConeBody->testPointInside(mLocalShapeToWorld * Vector3(-1.5, -2.9, 1.5))); // Tests with ProxyConeShape - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-0.9, 0, 0))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0.9))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -0.9))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0.6, 0, -0.7))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0.6, 0, 0.7))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-0.6, 0, -0.7))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-0.6, 0, 0.7))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(1.96, -2.9, 0))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-1.96, -2.9, 0))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 1.96))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, -1.96))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, -2.9, -1.4))); - test(mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-1.3, -2.9, 1.4))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-0.9, 0, 0))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0.9))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -0.9))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.6, 0, -0.7))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.6, 0, 0.7))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-0.6, 0, -0.7))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-0.6, 0, 0.7))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.96, -2.9, 0))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.96, -2.9, 0))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 1.96))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, -1.96))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, -2.9, -1.4))); + test(mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.3, -2.9, 1.4))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(1.1, 0, 0))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-1.1, 0, 0))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.1))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.1))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0.8, 0, -0.8))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0.8, 0, 0.8))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-0.8, 0, -0.8))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-0.8, 0, 0.8))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(1.97, -2.9, 0))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-1.97, -2.9, 0))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 1.97))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, -1.97))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2.9, -1.5))); - test(!mConeShape->testPointInside(mLocalShapeToWorld * Vector3(-1.5, -2.9, 1.5))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.1, 0, 0))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.1, 0, 0))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.1))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.1))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.8, 0, -0.8))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.8, 0, 0.8))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-0.8, 0, -0.8))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-0.8, 0, 0.8))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.97, -2.9, 0))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.97, -2.9, 0))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 1.97))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, -1.97))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2.9, -1.5))); + test(!mConeProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.5, -2.9, 1.5))); } /// Test the ProxyConvexMeshShape::testPointInside() and @@ -497,30 +517,30 @@ class TestPointInside : public Test { test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); // Tests with ProxyConvexMeshShape - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); - test(mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); + test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); - test(!mConvexMeshShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); + test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); // ----- Tests using edges information ----- // @@ -551,30 +571,30 @@ class TestPointInside : public Test { test(!mConvexMeshBodyEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); // Tests with ProxyConvexMeshShape - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); - test(mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); + test(mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); - test(!mConvexMeshShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); + test(!mConvexMeshProxyShapeEdgesInfo->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); } /// Test the ProxyCylinderShape::testPointInside() and @@ -638,60 +658,60 @@ class TestPointInside : public Test { test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(-2.2, -3.9, 2.2))); // Tests with ProxyCylinderShape - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -2.9))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, 0, 1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, 0, -1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 0, -1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 0, 1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 3.9, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 3.9, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 2.9))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, -2.9))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, 3.9, 1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, 3.9, -1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 3.9, -1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 3.9, 1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, -3.9, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, -3.9, 0))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 2.9))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, -2.9))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, -3.9, 1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, -3.9, -1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, -1.7))); - test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, 1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -2.9))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, 0, 1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, 0, -1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 0, -1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 0, 1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 3.9, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 3.9, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 2.9))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, -2.9))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, 3.9, 1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, 3.9, -1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 3.9, -1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 3.9, 1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, -3.9, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, -3.9, 0))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 2.9))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, -2.9))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, -3.9, 1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.7, -3.9, -1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, -1.7))); + test(mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, 1.7))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 4.1, 0))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, -4.1, 0))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 0, 2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 0, -2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 0, -2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.3, 0, 2.8))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 3.9, 0))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 3.9, 0))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 3.1))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, -3.1))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 3.9, 2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 3.9, -2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 3.9, -2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 3.9, 2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, -3.9, 0))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, -3.9, 0))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 3.1))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, -3.1))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, -3.9, 2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, -3.9, -2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, -3.9, -2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, -3.9, 2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 4.1, 0))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -4.1, 0))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 0, 2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 0, -2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 0, -2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.3, 0, 2.8))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 3.9, 0))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 3.9, 0))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 3.1))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, -3.1))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 3.9, 2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 3.9, -2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 3.9, -2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 3.9, 2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, -3.9, 0))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, -3.9, 0))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 3.1))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, -3.1))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, -3.9, 2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, -3.9, -2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, -3.9, -2.2))); + test(!mCylinderProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, -3.9, 2.2))); } /// Test the CollisionBody::testPointInside() method diff --git a/test/tests/collision/TestRaycast.h b/test/tests/collision/TestRaycast.h index b3c4cb03..bfba8c4f 100644 --- a/test/tests/collision/TestRaycast.h +++ b/test/tests/collision/TestRaycast.h @@ -120,16 +120,26 @@ class TestRaycast : public Test { Transform mLocalShapeToWorld; Transform mLocalShape2ToWorld; - // Collision Shapes - ProxyShape* mBoxShape; - ProxyShape* mSphereShape; - ProxyShape* mCapsuleShape; - ProxyShape* mConeShape; - ProxyShape* mConvexMeshShape; - ProxyShape* mConvexMeshShapeEdgesInfo; - ProxyShape* mCylinderShape; - ProxyShape* mCompoundSphereShape; - ProxyShape* mCompoundCylinderShape; + // Collision shapes + BoxShape* mBoxShape; + SphereShape* mSphereShape; + CapsuleShape* mCapsuleShape; + ConeShape* mConeShape; + ConvexMeshShape* mConvexMeshShape; + ConvexMeshShape* mConvexMeshShapeEdgesInfo; + CylinderShape* mCylinderShape; + + + // Proxy Shapes + ProxyShape* mBoxProxyShape; + ProxyShape* mSphereProxyShape; + ProxyShape* mCapsuleProxyShape; + ProxyShape* mConeProxyShape; + ProxyShape* mConvexMeshProxyShape; + ProxyShape* mConvexMeshProxyShapeEdgesInfo; + ProxyShape* mCylinderProxyShape; + ProxyShape* mCompoundSphereProxyShape; + ProxyShape* mCompoundCylinderProxyShape; public : @@ -167,76 +177,87 @@ class TestRaycast : public Test { mLocalShapeToWorld = mBodyTransform * mShapeTransform; // Create collision shapes - BoxShape boxShape(Vector3(2, 3, 4), 0); - mBoxShape = mBoxBody->addCollisionShape(boxShape, mShapeTransform); + mBoxShape = new BoxShape(Vector3(2, 3, 4), 0); + mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform); - SphereShape sphereShape(3); - mSphereShape = mSphereBody->addCollisionShape(sphereShape, mShapeTransform); + mSphereShape = new SphereShape(3); + mSphereProxyShape = mSphereBody->addCollisionShape(mSphereShape, mShapeTransform); - CapsuleShape capsuleShape(2, 5); - mCapsuleShape = mCapsuleBody->addCollisionShape(capsuleShape, mShapeTransform); + mCapsuleShape = new CapsuleShape(2, 5); + mCapsuleProxyShape = mCapsuleBody->addCollisionShape(mCapsuleShape, mShapeTransform); - ConeShape coneShape(2, 6, 0); - mConeShape = mConeBody->addCollisionShape(coneShape, mShapeTransform); + mConeShape = new ConeShape(2, 6, 0); + mConeProxyShape = mConeBody->addCollisionShape(mConeShape, mShapeTransform); - ConvexMeshShape convexMeshShape(0); // Box of dimension (2, 3, 4) - convexMeshShape.addVertex(Vector3(-2, -3, -4)); - convexMeshShape.addVertex(Vector3(2, -3, -4)); - convexMeshShape.addVertex(Vector3(2, -3, 4)); - convexMeshShape.addVertex(Vector3(-2, -3, 4)); - convexMeshShape.addVertex(Vector3(-2, 3, -4)); - convexMeshShape.addVertex(Vector3(2, 3, -4)); - convexMeshShape.addVertex(Vector3(2, 3, 4)); - convexMeshShape.addVertex(Vector3(-2, 3, 4)); - mConvexMeshShape = mConvexMeshBody->addCollisionShape(convexMeshShape, mShapeTransform); + mConvexMeshShape = new ConvexMeshShape(0); // Box of dimension (2, 3, 4) + mConvexMeshShape->addVertex(Vector3(-2, -3, -4)); + mConvexMeshShape->addVertex(Vector3(2, -3, -4)); + mConvexMeshShape->addVertex(Vector3(2, -3, 4)); + mConvexMeshShape->addVertex(Vector3(-2, -3, 4)); + mConvexMeshShape->addVertex(Vector3(-2, 3, -4)); + mConvexMeshShape->addVertex(Vector3(2, 3, -4)); + mConvexMeshShape->addVertex(Vector3(2, 3, 4)); + mConvexMeshShape->addVertex(Vector3(-2, 3, 4)); + mConvexMeshProxyShape = mConvexMeshBody->addCollisionShape(mConvexMeshShape, mShapeTransform); - ConvexMeshShape convexMeshShapeEdgesInfo(0); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, -3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, -3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, -3, 4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, -3, 4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, 3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, 3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, 3, 4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, 3, 4)); - convexMeshShapeEdgesInfo.addEdge(0, 1); - convexMeshShapeEdgesInfo.addEdge(1, 2); - convexMeshShapeEdgesInfo.addEdge(2, 3); - convexMeshShapeEdgesInfo.addEdge(0, 3); - convexMeshShapeEdgesInfo.addEdge(4, 5); - convexMeshShapeEdgesInfo.addEdge(5, 6); - convexMeshShapeEdgesInfo.addEdge(6, 7); - convexMeshShapeEdgesInfo.addEdge(4, 7); - convexMeshShapeEdgesInfo.addEdge(0, 4); - convexMeshShapeEdgesInfo.addEdge(1, 5); - convexMeshShapeEdgesInfo.addEdge(2, 6); - convexMeshShapeEdgesInfo.addEdge(3, 7); - convexMeshShapeEdgesInfo.setIsEdgesInformationUsed(true); - mConvexMeshShapeEdgesInfo = mConvexMeshBodyEdgesInfo->addCollisionShape( - convexMeshShapeEdgesInfo, + mConvexMeshShapeEdgesInfo = new ConvexMeshShape(0); + mConvexMeshShapeEdgesInfo->addVertex(Vector3(-2, -3, -4)); + mConvexMeshShapeEdgesInfo->addVertex(Vector3(2, -3, -4)); + mConvexMeshShapeEdgesInfo->addVertex(Vector3(2, -3, 4)); + mConvexMeshShapeEdgesInfo->addVertex(Vector3(-2, -3, 4)); + mConvexMeshShapeEdgesInfo->addVertex(Vector3(-2, 3, -4)); + mConvexMeshShapeEdgesInfo->addVertex(Vector3(2, 3, -4)); + mConvexMeshShapeEdgesInfo->addVertex(Vector3(2, 3, 4)); + mConvexMeshShapeEdgesInfo->addVertex(Vector3(-2, 3, 4)); + mConvexMeshShapeEdgesInfo->addEdge(0, 1); + mConvexMeshShapeEdgesInfo->addEdge(1, 2); + mConvexMeshShapeEdgesInfo->addEdge(2, 3); + mConvexMeshShapeEdgesInfo->addEdge(0, 3); + mConvexMeshShapeEdgesInfo->addEdge(4, 5); + mConvexMeshShapeEdgesInfo->addEdge(5, 6); + mConvexMeshShapeEdgesInfo->addEdge(6, 7); + mConvexMeshShapeEdgesInfo->addEdge(4, 7); + mConvexMeshShapeEdgesInfo->addEdge(0, 4); + mConvexMeshShapeEdgesInfo->addEdge(1, 5); + mConvexMeshShapeEdgesInfo->addEdge(2, 6); + mConvexMeshShapeEdgesInfo->addEdge(3, 7); + mConvexMeshShapeEdgesInfo->setIsEdgesInformationUsed(true); + mConvexMeshProxyShapeEdgesInfo = mConvexMeshBodyEdgesInfo->addCollisionShape( + mConvexMeshShapeEdgesInfo, mShapeTransform); - CylinderShape cylinderShape(2, 5, 0); - mCylinderShape = mCylinderBody->addCollisionShape(cylinderShape, mShapeTransform); + mCylinderShape = new CylinderShape(2, 5, 0); + mCylinderProxyShape = mCylinderBody->addCollisionShape(mCylinderShape, mShapeTransform); // Compound shape is a cylinder and a sphere Vector3 positionShape2(Vector3(4, 2, -3)); Quaternion orientationShape2(-3 *PI / 8, 1.5 * PI/ 3, PI / 13); Transform shapeTransform2(positionShape2, orientationShape2); mLocalShape2ToWorld = mBodyTransform * shapeTransform2; - mCompoundCylinderShape = mCompoundBody->addCollisionShape(cylinderShape, mShapeTransform); - mCompoundSphereShape = mCompoundBody->addCollisionShape(sphereShape, shapeTransform2); + mCompoundCylinderProxyShape = mCompoundBody->addCollisionShape(mCylinderShape, mShapeTransform); + mCompoundSphereProxyShape = mCompoundBody->addCollisionShape(mSphereShape, shapeTransform2); // Assign proxy shapes to the different categories - mBoxShape->setCollisionCategoryBits(CATEGORY1); - mSphereShape->setCollisionCategoryBits(CATEGORY1); - mCapsuleShape->setCollisionCategoryBits(CATEGORY1); - mConeShape->setCollisionCategoryBits(CATEGORY2); - mConvexMeshShape->setCollisionCategoryBits(CATEGORY2); - mConvexMeshShapeEdgesInfo->setCollisionCategoryBits(CATEGORY2); - mCylinderShape->setCollisionCategoryBits(CATEGORY2); - mCompoundSphereShape->setCollisionCategoryBits(CATEGORY2); - mCompoundCylinderShape->setCollisionCategoryBits(CATEGORY2); + mBoxProxyShape->setCollisionCategoryBits(CATEGORY1); + mSphereProxyShape->setCollisionCategoryBits(CATEGORY1); + mCapsuleProxyShape->setCollisionCategoryBits(CATEGORY1); + mConeProxyShape->setCollisionCategoryBits(CATEGORY2); + mConvexMeshProxyShape->setCollisionCategoryBits(CATEGORY2); + mConvexMeshProxyShapeEdgesInfo->setCollisionCategoryBits(CATEGORY2); + mCylinderProxyShape->setCollisionCategoryBits(CATEGORY2); + mCompoundSphereProxyShape->setCollisionCategoryBits(CATEGORY2); + mCompoundCylinderProxyShape->setCollisionCategoryBits(CATEGORY2); + } + + /// Destructor + ~TestRaycast() { + delete mBoxShape; + delete mSphereShape; + delete mCapsuleShape; + delete mConeShape; + delete mConvexMeshShape; + delete mConvexMeshShapeEdgesInfo; + delete mCylinderShape; } /// Run the tests @@ -260,14 +281,14 @@ class TestRaycast : public Test { Ray ray(point1, point2); Vector3 hitPoint = mLocalShapeToWorld * Vector3(1, 2, 4); - mCallback.shapeToTest = mBoxShape; + mCallback.shapeToTest = mBoxProxyShape; // CollisionWorld::raycast() mCallback.reset(); mWorld->raycast(ray, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mBoxBody); - test(mCallback.raycastInfo.proxyShape == mBoxShape); + test(mCallback.raycastInfo.proxyShape == mBoxProxyShape); test(approxEqual(mCallback.raycastInfo.hitFraction, decimal(0.2), epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.y, hitPoint.y, epsilon)); @@ -287,7 +308,7 @@ class TestRaycast : public Test { RaycastInfo raycastInfo2; test(mBoxBody->raycast(ray, raycastInfo2)); test(raycastInfo2.body == mBoxBody); - test(raycastInfo2.proxyShape == mBoxShape); + test(raycastInfo2.proxyShape == mBoxProxyShape); test(approxEqual(raycastInfo2.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo2.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo2.worldPoint.y, hitPoint.y, epsilon)); @@ -295,9 +316,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo3; - test(mBoxShape->raycast(ray, raycastInfo3)); + test(mBoxProxyShape->raycast(ray, raycastInfo3)); test(raycastInfo3.body == mBoxBody); - test(raycastInfo3.proxyShape == mBoxShape); + test(raycastInfo3.proxyShape == mBoxProxyShape); test(approxEqual(raycastInfo3.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo3.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo3.worldPoint.y, hitPoint.y, epsilon)); @@ -322,7 +343,7 @@ class TestRaycast : public Test { // ----- Test raycast miss ----- // test(!mBoxBody->raycast(ray1, raycastInfo3)); - test(!mBoxShape->raycast(ray1, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray1, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray1, &mCallback); test(!mCallback.isHit); @@ -334,55 +355,55 @@ class TestRaycast : public Test { test(!mCallback.isHit); test(!mBoxBody->raycast(ray2, raycastInfo3)); - test(!mBoxShape->raycast(ray2, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray2, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray2, &mCallback); test(!mCallback.isHit); test(!mBoxBody->raycast(ray3, raycastInfo3)); - test(!mBoxShape->raycast(ray3, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray3, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray3, &mCallback); test(!mCallback.isHit); test(!mBoxBody->raycast(ray4, raycastInfo3)); - test(!mBoxShape->raycast(ray4, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray4, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray4, &mCallback); test(!mCallback.isHit); test(!mBoxBody->raycast(ray5, raycastInfo3)); - test(!mBoxShape->raycast(ray5, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray5, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray5, &mCallback); test(!mCallback.isHit); test(!mBoxBody->raycast(ray6, raycastInfo3)); - test(!mBoxShape->raycast(ray6, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray6, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray6, &mCallback); test(!mCallback.isHit); test(!mBoxBody->raycast(ray7, raycastInfo3)); - test(!mBoxShape->raycast(ray7, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray7, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray7, &mCallback); test(!mCallback.isHit); test(!mBoxBody->raycast(ray8, raycastInfo3)); - test(!mBoxShape->raycast(ray8, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray8, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray8, &mCallback); test(!mCallback.isHit); test(!mBoxBody->raycast(ray9, raycastInfo3)); - test(!mBoxShape->raycast(ray9, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray9, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray9, &mCallback); test(!mCallback.isHit); test(!mBoxBody->raycast(ray10, raycastInfo3)); - test(!mBoxShape->raycast(ray10, raycastInfo3)); + test(!mBoxProxyShape->raycast(ray10, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray10, &mCallback); test(!mCallback.isHit); @@ -408,7 +429,7 @@ class TestRaycast : public Test { // ----- Test raycast hits ----- // test(mBoxBody->raycast(ray11, raycastInfo3)); - test(mBoxShape->raycast(ray11, raycastInfo3)); + test(mBoxProxyShape->raycast(ray11, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray11, &mCallback); test(mCallback.isHit); @@ -417,7 +438,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mBoxBody->raycast(ray12, raycastInfo3)); - test(mBoxShape->raycast(ray12, raycastInfo3)); + test(mBoxProxyShape->raycast(ray12, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray12, &mCallback); test(mCallback.isHit); @@ -426,7 +447,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mBoxBody->raycast(ray13, raycastInfo3)); - test(mBoxShape->raycast(ray13, raycastInfo3)); + test(mBoxProxyShape->raycast(ray13, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray13, &mCallback); test(mCallback.isHit); @@ -435,7 +456,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mBoxBody->raycast(ray14, raycastInfo3)); - test(mBoxShape->raycast(ray14, raycastInfo3)); + test(mBoxProxyShape->raycast(ray14, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray14, &mCallback); test(mCallback.isHit); @@ -444,7 +465,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mBoxBody->raycast(ray15, raycastInfo3)); - test(mBoxShape->raycast(ray15, raycastInfo3)); + test(mBoxProxyShape->raycast(ray15, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray15, &mCallback); test(mCallback.isHit); @@ -453,7 +474,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mBoxBody->raycast(ray16, raycastInfo3)); - test(mBoxShape->raycast(ray16, raycastInfo3)); + test(mBoxProxyShape->raycast(ray16, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray16, &mCallback); test(mCallback.isHit); @@ -472,14 +493,14 @@ class TestRaycast : public Test { Ray ray(point1, point2); Vector3 hitPoint = mLocalShapeToWorld * Vector3(-3, 0, 0); - mCallback.shapeToTest = mSphereShape; + mCallback.shapeToTest = mSphereProxyShape; // CollisionWorld::raycast() mCallback.reset(); mWorld->raycast(ray, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mSphereBody); - test(mCallback.raycastInfo.proxyShape == mSphereShape); + test(mCallback.raycastInfo.proxyShape == mSphereProxyShape); test(approxEqual(mCallback.raycastInfo.hitFraction, 0.2, epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.y, hitPoint.y, epsilon)); @@ -499,7 +520,7 @@ class TestRaycast : public Test { RaycastInfo raycastInfo2; test(mSphereBody->raycast(ray, raycastInfo2)); test(raycastInfo2.body == mSphereBody); - test(raycastInfo2.proxyShape == mSphereShape); + test(raycastInfo2.proxyShape == mSphereProxyShape); test(approxEqual(raycastInfo2.hitFraction, 0.2, epsilon)); test(approxEqual(raycastInfo2.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo2.worldPoint.y, hitPoint.y, epsilon)); @@ -507,9 +528,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo3; - test(mSphereShape->raycast(ray, raycastInfo3)); + test(mSphereProxyShape->raycast(ray, raycastInfo3)); test(raycastInfo3.body == mSphereBody); - test(raycastInfo3.proxyShape == mSphereShape); + test(raycastInfo3.proxyShape == mSphereProxyShape); test(approxEqual(raycastInfo3.hitFraction, 0.2, epsilon)); test(approxEqual(raycastInfo3.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo3.worldPoint.y, hitPoint.y, epsilon)); @@ -534,7 +555,7 @@ class TestRaycast : public Test { // ----- Test raycast miss ----- // test(!mSphereBody->raycast(ray1, raycastInfo3)); - test(!mSphereShape->raycast(ray1, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray1, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray1, &mCallback); test(!mCallback.isHit); @@ -546,55 +567,55 @@ class TestRaycast : public Test { test(!mCallback.isHit); test(!mSphereBody->raycast(ray2, raycastInfo3)); - test(!mSphereShape->raycast(ray2, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray2, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray2, &mCallback); test(!mCallback.isHit); test(!mSphereBody->raycast(ray3, raycastInfo3)); - test(!mSphereShape->raycast(ray3, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray3, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray3, &mCallback); test(!mCallback.isHit); test(!mSphereBody->raycast(ray4, raycastInfo3)); - test(!mSphereShape->raycast(ray4, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray4, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray4, &mCallback); test(!mCallback.isHit); test(!mSphereBody->raycast(ray5, raycastInfo3)); - test(!mSphereShape->raycast(ray5, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray5, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray5, &mCallback); test(!mCallback.isHit); test(!mSphereBody->raycast(ray6, raycastInfo3)); - test(!mSphereShape->raycast(ray6, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray6, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray6, &mCallback); test(!mCallback.isHit); test(!mSphereBody->raycast(ray7, raycastInfo3)); - test(!mSphereShape->raycast(ray7, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray7, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray7, &mCallback); test(!mCallback.isHit); test(!mSphereBody->raycast(ray8, raycastInfo3)); - test(!mSphereShape->raycast(ray8, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray8, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray8, &mCallback); test(!mCallback.isHit); test(!mSphereBody->raycast(ray9, raycastInfo3)); - test(!mSphereShape->raycast(ray9, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray9, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray9, &mCallback); test(!mCallback.isHit); test(!mSphereBody->raycast(ray10, raycastInfo3)); - test(!mSphereShape->raycast(ray10, raycastInfo3)); + test(!mSphereProxyShape->raycast(ray10, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray10, &mCallback); test(!mCallback.isHit); @@ -620,7 +641,7 @@ class TestRaycast : public Test { // ----- Test raycast hits ----- // test(mSphereBody->raycast(ray11, raycastInfo3)); - test(mSphereShape->raycast(ray11, raycastInfo3)); + test(mSphereProxyShape->raycast(ray11, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray11, &mCallback); test(mCallback.isHit); @@ -629,7 +650,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mSphereBody->raycast(ray12, raycastInfo3)); - test(mSphereShape->raycast(ray12, raycastInfo3)); + test(mSphereProxyShape->raycast(ray12, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray12, &mCallback); test(mCallback.isHit); @@ -638,14 +659,14 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mSphereBody->raycast(ray13, raycastInfo3)); - test(mSphereShape->raycast(ray13, raycastInfo3)); + test(mSphereProxyShape->raycast(ray13, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray13, &mCallback); mCallback.reset(); mWorld->raycast(Ray(ray13.point1, ray13.point2, decimal(0.8)), &mCallback); test(mSphereBody->raycast(ray14, raycastInfo3)); - test(mSphereShape->raycast(ray14, raycastInfo3)); + test(mSphereProxyShape->raycast(ray14, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray14, &mCallback); test(mCallback.isHit); @@ -654,7 +675,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mSphereBody->raycast(ray15, raycastInfo3)); - test(mSphereShape->raycast(ray15, raycastInfo3)); + test(mSphereProxyShape->raycast(ray15, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray15, &mCallback); test(mCallback.isHit); @@ -663,7 +684,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mSphereBody->raycast(ray16, raycastInfo3)); - test(mSphereShape->raycast(ray16, raycastInfo3)); + test(mSphereProxyShape->raycast(ray16, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray16, &mCallback); test(mCallback.isHit); @@ -692,14 +713,14 @@ class TestRaycast : public Test { Ray rayBottom(point3A, point3B); Vector3 hitPointBottom = mLocalShapeToWorld * Vector3(0, decimal(-4.5), 0); - mCallback.shapeToTest = mCapsuleShape; + mCallback.shapeToTest = mCapsuleProxyShape; // CollisionWorld::raycast() mCallback.reset(); mWorld->raycast(ray, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mCapsuleBody); - test(mCallback.raycastInfo.proxyShape == mCapsuleShape); + test(mCallback.raycastInfo.proxyShape == mCapsuleProxyShape); test(approxEqual(mCallback.raycastInfo.hitFraction, decimal(0.2), epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.y, hitPoint.y, epsilon)); @@ -719,7 +740,7 @@ class TestRaycast : public Test { RaycastInfo raycastInfo2; test(mCapsuleBody->raycast(ray, raycastInfo2)); test(raycastInfo2.body == mCapsuleBody); - test(raycastInfo2.proxyShape == mCapsuleShape); + test(raycastInfo2.proxyShape == mCapsuleProxyShape); test(approxEqual(raycastInfo2.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo2.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo2.worldPoint.y, hitPoint.y, epsilon)); @@ -727,18 +748,18 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo3; - test(mCapsuleShape->raycast(ray, raycastInfo3)); + test(mCapsuleProxyShape->raycast(ray, raycastInfo3)); test(raycastInfo3.body == mCapsuleBody); - test(raycastInfo3.proxyShape == mCapsuleShape); + test(raycastInfo3.proxyShape == mCapsuleProxyShape); test(approxEqual(raycastInfo3.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo3.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo3.worldPoint.y, hitPoint.y, epsilon)); test(approxEqual(raycastInfo3.worldPoint.z, hitPoint.z, epsilon)); RaycastInfo raycastInfo4; - test(mCapsuleShape->raycast(rayTop, raycastInfo4)); + test(mCapsuleProxyShape->raycast(rayTop, raycastInfo4)); test(raycastInfo4.body == mCapsuleBody); - test(raycastInfo4.proxyShape == mCapsuleShape); + test(raycastInfo4.proxyShape == mCapsuleProxyShape); test(approxEqual(raycastInfo4.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo4.worldPoint.x, hitPointTop.x, epsilon)); test(approxEqual(raycastInfo4.worldPoint.y, hitPointTop.y, epsilon)); @@ -746,9 +767,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo5; - test(mCapsuleShape->raycast(rayBottom, raycastInfo5)); + test(mCapsuleProxyShape->raycast(rayBottom, raycastInfo5)); test(raycastInfo5.body == mCapsuleBody); - test(raycastInfo5.proxyShape == mCapsuleShape); + test(raycastInfo5.proxyShape == mCapsuleProxyShape); test(approxEqual(raycastInfo5.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo5.worldPoint.x, hitPointBottom.x, epsilon)); test(approxEqual(raycastInfo5.worldPoint.y, hitPointBottom.y, epsilon)); @@ -773,7 +794,7 @@ class TestRaycast : public Test { // ----- Test raycast miss ----- // test(!mCapsuleBody->raycast(ray1, raycastInfo3)); - test(!mCapsuleShape->raycast(ray1, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray1, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray1, &mCallback); test(!mCallback.isHit); @@ -785,54 +806,54 @@ class TestRaycast : public Test { test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray2, raycastInfo3)); - test(!mCapsuleShape->raycast(ray2, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray2, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray2, &mCallback); test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray3, raycastInfo3)); - test(!mCapsuleShape->raycast(ray3, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray3, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray3, &mCallback); test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray4, raycastInfo3)); - test(!mCapsuleShape->raycast(ray4, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray4, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray4, &mCallback); test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray5, raycastInfo3)); - test(!mCapsuleShape->raycast(ray5, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray5, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray5, &mCallback); test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray6, raycastInfo3)); - test(!mCapsuleShape->raycast(ray6, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray6, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray6, &mCallback); test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray7, raycastInfo3)); - test(!mCapsuleShape->raycast(ray7, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray7, raycastInfo3)); mWorld->raycast(ray7, &mCallback); test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray8, raycastInfo3)); - test(!mCapsuleShape->raycast(ray8, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray8, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray8, &mCallback); test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray9, raycastInfo3)); - test(!mCapsuleShape->raycast(ray9, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray9, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray9, &mCallback); test(!mCallback.isHit); test(!mCapsuleBody->raycast(ray10, raycastInfo3)); - test(!mCapsuleShape->raycast(ray10, raycastInfo3)); + test(!mCapsuleProxyShape->raycast(ray10, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray10, &mCallback); test(!mCallback.isHit); @@ -858,7 +879,7 @@ class TestRaycast : public Test { // ----- Test raycast hits ----- // test(mCapsuleBody->raycast(ray11, raycastInfo3)); - test(mCapsuleShape->raycast(ray11, raycastInfo3)); + test(mCapsuleProxyShape->raycast(ray11, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray11, &mCallback); test(mCallback.isHit); @@ -867,7 +888,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCapsuleBody->raycast(ray12, raycastInfo3)); - test(mCapsuleShape->raycast(ray12, raycastInfo3)); + test(mCapsuleProxyShape->raycast(ray12, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray12, &mCallback); test(mCallback.isHit); @@ -876,7 +897,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCapsuleBody->raycast(ray13, raycastInfo3)); - test(mCapsuleShape->raycast(ray13, raycastInfo3)); + test(mCapsuleProxyShape->raycast(ray13, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray13, &mCallback); test(mCallback.isHit); @@ -885,7 +906,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCapsuleBody->raycast(ray14, raycastInfo3)); - test(mCapsuleShape->raycast(ray14, raycastInfo3)); + test(mCapsuleProxyShape->raycast(ray14, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray14, &mCallback); test(mCallback.isHit); @@ -894,7 +915,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCapsuleBody->raycast(ray15, raycastInfo3)); - test(mCapsuleShape->raycast(ray15, raycastInfo3)); + test(mCapsuleProxyShape->raycast(ray15, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray15, &mCallback); test(mCallback.isHit); @@ -903,7 +924,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCapsuleBody->raycast(ray16, raycastInfo3)); - test(mCapsuleShape->raycast(ray16, raycastInfo3)); + test(mCapsuleProxyShape->raycast(ray16, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray16, &mCallback); test(mCallback.isHit); @@ -927,14 +948,14 @@ class TestRaycast : public Test { Ray rayBottom(point2A, point2B); Vector3 hitPoint2 = mLocalShapeToWorld * Vector3(1, -3, 0); - mCallback.shapeToTest = mConeShape; + mCallback.shapeToTest = mConeProxyShape; // CollisionWorld::raycast() mCallback.reset(); mWorld->raycast(ray, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mConeBody); - test(mCallback.raycastInfo.proxyShape == mConeShape); + test(mCallback.raycastInfo.proxyShape == mConeProxyShape); test(approxEqual(mCallback.raycastInfo.hitFraction, decimal(0.2), epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.y, hitPoint.y, epsilon)); @@ -954,7 +975,7 @@ class TestRaycast : public Test { RaycastInfo raycastInfo2; test(mConeBody->raycast(ray, raycastInfo2)); test(raycastInfo2.body == mConeBody); - test(raycastInfo2.proxyShape == mConeShape); + test(raycastInfo2.proxyShape == mConeProxyShape); test(approxEqual(raycastInfo2.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo2.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo2.worldPoint.y, hitPoint.y, epsilon)); @@ -962,9 +983,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo3; - test(mConeShape->raycast(ray, raycastInfo3)); + test(mConeProxyShape->raycast(ray, raycastInfo3)); test(raycastInfo3.body == mConeBody); - test(raycastInfo3.proxyShape == mConeShape); + test(raycastInfo3.proxyShape == mConeProxyShape); test(approxEqual(raycastInfo3.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo3.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo3.worldPoint.y, hitPoint.y, epsilon)); @@ -974,7 +995,7 @@ class TestRaycast : public Test { mWorld->raycast(rayBottom, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mConeBody); - test(mCallback.raycastInfo.proxyShape == mConeShape); + test(mCallback.raycastInfo.proxyShape == mConeProxyShape); test(approxEqual(mCallback.raycastInfo.hitFraction, decimal(0.2), epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.x, hitPoint2.x, epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.y, hitPoint2.y, epsilon)); @@ -984,7 +1005,7 @@ class TestRaycast : public Test { RaycastInfo raycastInfo5; test(mConeBody->raycast(rayBottom, raycastInfo5)); test(raycastInfo5.body == mConeBody); - test(raycastInfo5.proxyShape == mConeShape); + test(raycastInfo5.proxyShape == mConeProxyShape); test(approxEqual(raycastInfo5.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo5.worldPoint.x, hitPoint2.x, epsilon)); test(approxEqual(raycastInfo5.worldPoint.y, hitPoint2.y, epsilon)); @@ -992,9 +1013,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo6; - test(mConeShape->raycast(rayBottom, raycastInfo6)); + test(mConeProxyShape->raycast(rayBottom, raycastInfo6)); test(raycastInfo6.body == mConeBody); - test(raycastInfo6.proxyShape == mConeShape); + test(raycastInfo6.proxyShape == mConeProxyShape); test(approxEqual(raycastInfo6.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo6.worldPoint.x, hitPoint2.x, epsilon)); test(approxEqual(raycastInfo6.worldPoint.y, hitPoint2.y, epsilon)); @@ -1019,7 +1040,7 @@ class TestRaycast : public Test { // ----- Test raycast miss ----- // test(!mConeBody->raycast(ray1, raycastInfo3)); - test(!mConeShape->raycast(ray1, raycastInfo3)); + test(!mConeProxyShape->raycast(ray1, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray1, &mCallback); test(!mCallback.isHit); @@ -1031,55 +1052,55 @@ class TestRaycast : public Test { test(!mCallback.isHit); test(!mConeBody->raycast(ray2, raycastInfo3)); - test(!mConeShape->raycast(ray2, raycastInfo3)); + test(!mConeProxyShape->raycast(ray2, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray2, &mCallback); test(!mCallback.isHit); test(!mConeBody->raycast(ray3, raycastInfo3)); - test(!mConeShape->raycast(ray3, raycastInfo3)); + test(!mConeProxyShape->raycast(ray3, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray3, &mCallback); test(!mCallback.isHit); test(!mConeBody->raycast(ray4, raycastInfo3)); - test(!mConeShape->raycast(ray4, raycastInfo3)); + test(!mConeProxyShape->raycast(ray4, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray4, &mCallback); test(!mCallback.isHit); test(!mConeBody->raycast(ray5, raycastInfo3)); - test(!mConeShape->raycast(ray5, raycastInfo3)); + test(!mConeProxyShape->raycast(ray5, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray5, &mCallback); test(!mCallback.isHit); test(!mConeBody->raycast(ray6, raycastInfo3)); - test(!mConeShape->raycast(ray6, raycastInfo3)); + test(!mConeProxyShape->raycast(ray6, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray6, &mCallback); test(!mCallback.isHit); test(!mConeBody->raycast(ray7, raycastInfo3)); - test(!mConeShape->raycast(ray7, raycastInfo3)); + test(!mConeProxyShape->raycast(ray7, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray7, &mCallback); test(!mCallback.isHit); test(!mConeBody->raycast(ray8, raycastInfo3)); - test(!mConeShape->raycast(ray8, raycastInfo3)); + test(!mConeProxyShape->raycast(ray8, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray8, &mCallback); test(!mCallback.isHit); test(!mConeBody->raycast(ray9, raycastInfo3)); - test(!mConeShape->raycast(ray9, raycastInfo3)); + test(!mConeProxyShape->raycast(ray9, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray9, &mCallback); test(!mCallback.isHit); test(!mConeBody->raycast(ray10, raycastInfo3)); - test(!mConeShape->raycast(ray10, raycastInfo3)); + test(!mConeProxyShape->raycast(ray10, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray10, &mCallback); test(!mCallback.isHit); @@ -1105,7 +1126,7 @@ class TestRaycast : public Test { // ----- Test raycast hits ----- // test(mConeBody->raycast(ray11, raycastInfo3)); - test(mConeShape->raycast(ray11, raycastInfo3)); + test(mConeProxyShape->raycast(ray11, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray11, &mCallback); test(mCallback.isHit); @@ -1114,7 +1135,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mConeBody->raycast(ray12, raycastInfo3)); - test(mConeShape->raycast(ray12, raycastInfo3)); + test(mConeProxyShape->raycast(ray12, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray12, &mCallback); test(mCallback.isHit); @@ -1123,7 +1144,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mConeBody->raycast(ray13, raycastInfo3)); - test(mConeShape->raycast(ray13, raycastInfo3)); + test(mConeProxyShape->raycast(ray13, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray13, &mCallback); test(mCallback.isHit); @@ -1132,7 +1153,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mConeBody->raycast(ray14, raycastInfo3)); - test(mConeShape->raycast(ray14, raycastInfo3)); + test(mConeProxyShape->raycast(ray14, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray14, &mCallback); test(mCallback.isHit); @@ -1141,7 +1162,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mConeBody->raycast(ray15, raycastInfo3)); - test(mConeShape->raycast(ray15, raycastInfo3)); + test(mConeProxyShape->raycast(ray15, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray15, &mCallback); test(mCallback.isHit); @@ -1150,7 +1171,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mConeBody->raycast(ray16, raycastInfo3)); - test(mConeShape->raycast(ray16, raycastInfo3)); + test(mConeProxyShape->raycast(ray16, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray16, &mCallback); test(mCallback.isHit); @@ -1169,14 +1190,14 @@ class TestRaycast : public Test { Ray ray(point1, point2); Vector3 hitPoint = mLocalShapeToWorld * Vector3(1, 2, 4); - mCallback.shapeToTest = mConvexMeshShape; + mCallback.shapeToTest = mConvexMeshProxyShape; // CollisionWorld::raycast() mCallback.reset(); mWorld->raycast(ray, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mConvexMeshBody); - test(mCallback.raycastInfo.proxyShape == mConvexMeshShape); + test(mCallback.raycastInfo.proxyShape == mConvexMeshProxyShape); test(approxEqual(mCallback.raycastInfo.hitFraction, decimal(0.2), epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.y, hitPoint.y, epsilon)); @@ -1196,7 +1217,7 @@ class TestRaycast : public Test { RaycastInfo raycastInfo2; test(mConvexMeshBody->raycast(ray, raycastInfo2)); test(raycastInfo2.body == mConvexMeshBody); - test(raycastInfo2.proxyShape == mConvexMeshShape); + test(raycastInfo2.proxyShape == mConvexMeshProxyShape); test(approxEqual(raycastInfo2.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo2.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo2.worldPoint.y, hitPoint.y, epsilon)); @@ -1206,7 +1227,7 @@ class TestRaycast : public Test { RaycastInfo raycastInfo3; test(mConvexMeshBodyEdgesInfo->raycast(ray, raycastInfo3)); test(raycastInfo3.body == mConvexMeshBodyEdgesInfo); - test(raycastInfo3.proxyShape == mConvexMeshShapeEdgesInfo); + test(raycastInfo3.proxyShape == mConvexMeshProxyShapeEdgesInfo); test(approxEqual(raycastInfo3.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo3.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo3.worldPoint.y, hitPoint.y, epsilon)); @@ -1214,9 +1235,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo4; - test(mConvexMeshShape->raycast(ray, raycastInfo4)); + test(mConvexMeshProxyShape->raycast(ray, raycastInfo4)); test(raycastInfo4.body == mConvexMeshBody); - test(raycastInfo4.proxyShape == mConvexMeshShape); + test(raycastInfo4.proxyShape == mConvexMeshProxyShape); test(approxEqual(raycastInfo4.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo4.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo4.worldPoint.y, hitPoint.y, epsilon)); @@ -1224,9 +1245,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo5; - test(mConvexMeshShapeEdgesInfo->raycast(ray, raycastInfo5)); + test(mConvexMeshProxyShapeEdgesInfo->raycast(ray, raycastInfo5)); test(raycastInfo5.body == mConvexMeshBodyEdgesInfo); - test(raycastInfo5.proxyShape == mConvexMeshShapeEdgesInfo); + test(raycastInfo5.proxyShape == mConvexMeshProxyShapeEdgesInfo); test(approxEqual(raycastInfo5.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo5.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo5.worldPoint.y, hitPoint.y, epsilon)); @@ -1252,8 +1273,8 @@ class TestRaycast : public Test { // ----- Test raycast miss ----- // test(!mConvexMeshBody->raycast(ray1, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray1, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray1, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray1, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray1, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray1, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray1, &mCallback); test(!mCallback.isHit); @@ -1266,72 +1287,72 @@ class TestRaycast : public Test { test(!mConvexMeshBody->raycast(ray2, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray2, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray2, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray2, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray2, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray2, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray2, &mCallback); test(!mCallback.isHit); test(!mConvexMeshBody->raycast(ray3, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray3, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray3, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray3, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray3, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray3, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray3, &mCallback); test(!mCallback.isHit); test(!mConvexMeshBody->raycast(ray4, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray4, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray4, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray4, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray4, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray4, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray4, &mCallback); test(!mCallback.isHit); test(!mConvexMeshBody->raycast(ray5, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray5, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray5, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray5, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray5, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray5, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray5, &mCallback); test(!mCallback.isHit); test(!mConvexMeshBody->raycast(ray6, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray6, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray6, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray6, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray6, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray6, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray6, &mCallback); test(!mCallback.isHit); test(!mConvexMeshBody->raycast(ray7, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray7, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray7, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray7, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray7, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray7, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray7, &mCallback); test(!mCallback.isHit); test(!mConvexMeshBody->raycast(ray8, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray8, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray8, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray8, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray8, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray8, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray8, &mCallback); test(!mCallback.isHit); test(!mConvexMeshBody->raycast(ray9, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray9, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray9, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray9, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray9, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray9, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray9, &mCallback); test(!mCallback.isHit); test(!mConvexMeshBody->raycast(ray10, raycastInfo3)); test(!mConvexMeshBodyEdgesInfo->raycast(ray10, raycastInfo3)); - test(!mConvexMeshShape->raycast(ray10, raycastInfo3)); - test(!mConvexMeshShapeEdgesInfo->raycast(ray10, raycastInfo3)); + test(!mConvexMeshProxyShape->raycast(ray10, raycastInfo3)); + test(!mConvexMeshProxyShapeEdgesInfo->raycast(ray10, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray10, &mCallback); test(!mCallback.isHit); @@ -1358,8 +1379,8 @@ class TestRaycast : public Test { // ----- Test raycast hits ----- // test(mConvexMeshBody->raycast(ray11, raycastInfo3)); test(mConvexMeshBodyEdgesInfo->raycast(ray11, raycastInfo3)); - test(mConvexMeshShape->raycast(ray11, raycastInfo3)); - test(mConvexMeshShapeEdgesInfo->raycast(ray11, raycastInfo3)); + test(mConvexMeshProxyShape->raycast(ray11, raycastInfo3)); + test(mConvexMeshProxyShapeEdgesInfo->raycast(ray11, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray11, &mCallback); test(mCallback.isHit); @@ -1369,8 +1390,8 @@ class TestRaycast : public Test { test(mConvexMeshBody->raycast(ray12, raycastInfo3)); test(mConvexMeshBodyEdgesInfo->raycast(ray12, raycastInfo3)); - test(mConvexMeshShape->raycast(ray12, raycastInfo3)); - test(mConvexMeshShapeEdgesInfo->raycast(ray12, raycastInfo3)); + test(mConvexMeshProxyShape->raycast(ray12, raycastInfo3)); + test(mConvexMeshProxyShapeEdgesInfo->raycast(ray12, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray12, &mCallback); test(mCallback.isHit); @@ -1380,8 +1401,8 @@ class TestRaycast : public Test { test(mConvexMeshBody->raycast(ray13, raycastInfo3)); test(mConvexMeshBodyEdgesInfo->raycast(ray13, raycastInfo3)); - test(mConvexMeshShape->raycast(ray13, raycastInfo3)); - test(mConvexMeshShapeEdgesInfo->raycast(ray13, raycastInfo3)); + test(mConvexMeshProxyShape->raycast(ray13, raycastInfo3)); + test(mConvexMeshProxyShapeEdgesInfo->raycast(ray13, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray13, &mCallback); test(mCallback.isHit); @@ -1391,8 +1412,8 @@ class TestRaycast : public Test { test(mConvexMeshBody->raycast(ray14, raycastInfo3)); test(mConvexMeshBodyEdgesInfo->raycast(ray14, raycastInfo3)); - test(mConvexMeshShape->raycast(ray14, raycastInfo3)); - test(mConvexMeshShapeEdgesInfo->raycast(ray14, raycastInfo3)); + test(mConvexMeshProxyShape->raycast(ray14, raycastInfo3)); + test(mConvexMeshProxyShapeEdgesInfo->raycast(ray14, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray14, &mCallback); test(mCallback.isHit); @@ -1402,8 +1423,8 @@ class TestRaycast : public Test { test(mConvexMeshBody->raycast(ray15, raycastInfo3)); test(mConvexMeshBodyEdgesInfo->raycast(ray15, raycastInfo3)); - test(mConvexMeshShape->raycast(ray15, raycastInfo3)); - test(mConvexMeshShapeEdgesInfo->raycast(ray15, raycastInfo3)); + test(mConvexMeshProxyShape->raycast(ray15, raycastInfo3)); + test(mConvexMeshProxyShapeEdgesInfo->raycast(ray15, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray15, &mCallback); test(mCallback.isHit); @@ -1413,8 +1434,8 @@ class TestRaycast : public Test { test(mConvexMeshBody->raycast(ray16, raycastInfo3)); test(mConvexMeshBodyEdgesInfo->raycast(ray16, raycastInfo3)); - test(mConvexMeshShape->raycast(ray16, raycastInfo3)); - test(mConvexMeshShapeEdgesInfo->raycast(ray16, raycastInfo3)); + test(mConvexMeshProxyShape->raycast(ray16, raycastInfo3)); + test(mConvexMeshProxyShapeEdgesInfo->raycast(ray16, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray16, &mCallback); test(mCallback.isHit); @@ -1443,14 +1464,14 @@ class TestRaycast : public Test { Ray rayBottom(point3A, point3B); Vector3 hitPointBottom = mLocalShapeToWorld * Vector3(0, decimal(-2.5), 0); - mCallback.shapeToTest = mCylinderShape; + mCallback.shapeToTest = mCylinderProxyShape; // CollisionWorld::raycast() mCallback.reset(); mWorld->raycast(ray, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mCylinderBody); - test(mCallback.raycastInfo.proxyShape == mCylinderShape); + test(mCallback.raycastInfo.proxyShape == mCylinderProxyShape); test(approxEqual(mCallback.raycastInfo.hitFraction, decimal(0.2), epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(mCallback.raycastInfo.worldPoint.y, hitPoint.y, epsilon)); @@ -1470,7 +1491,7 @@ class TestRaycast : public Test { RaycastInfo raycastInfo2; test(mCylinderBody->raycast(ray, raycastInfo2)); test(raycastInfo2.body == mCylinderBody); - test(raycastInfo2.proxyShape == mCylinderShape); + test(raycastInfo2.proxyShape == mCylinderProxyShape); test(approxEqual(raycastInfo2.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo2.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo2.worldPoint.y, hitPoint.y, epsilon)); @@ -1478,9 +1499,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo3; - test(mCylinderShape->raycast(ray, raycastInfo3)); + test(mCylinderProxyShape->raycast(ray, raycastInfo3)); test(raycastInfo3.body == mCylinderBody); - test(raycastInfo3.proxyShape == mCylinderShape); + test(raycastInfo3.proxyShape == mCylinderProxyShape); test(approxEqual(raycastInfo3.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo3.worldPoint.x, hitPoint.x, epsilon)); test(approxEqual(raycastInfo3.worldPoint.y, hitPoint.y, epsilon)); @@ -1488,9 +1509,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo5; - test(mCylinderShape->raycast(rayTop, raycastInfo5)); + test(mCylinderProxyShape->raycast(rayTop, raycastInfo5)); test(raycastInfo5.body == mCylinderBody); - test(raycastInfo5.proxyShape == mCylinderShape); + test(raycastInfo5.proxyShape == mCylinderProxyShape); test(approxEqual(raycastInfo5.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo5.worldPoint.x, hitPointTop.x, epsilon)); test(approxEqual(raycastInfo5.worldPoint.y, hitPointTop.y, epsilon)); @@ -1498,9 +1519,9 @@ class TestRaycast : public Test { // ProxyCollisionShape::raycast() RaycastInfo raycastInfo6; - test(mCylinderShape->raycast(rayBottom, raycastInfo6)); + test(mCylinderProxyShape->raycast(rayBottom, raycastInfo6)); test(raycastInfo6.body == mCylinderBody); - test(raycastInfo6.proxyShape == mCylinderShape); + test(raycastInfo6.proxyShape == mCylinderProxyShape); test(approxEqual(raycastInfo6.hitFraction, decimal(0.2), epsilon)); test(approxEqual(raycastInfo6.worldPoint.x, hitPointBottom.x, epsilon)); test(approxEqual(raycastInfo6.worldPoint.y, hitPointBottom.y, epsilon)); @@ -1525,7 +1546,7 @@ class TestRaycast : public Test { // ----- Test raycast miss ----- // test(!mCylinderBody->raycast(ray1, raycastInfo3)); - test(!mCylinderShape->raycast(ray1, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray1, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray1, &mCallback); test(!mCallback.isHit); @@ -1537,55 +1558,55 @@ class TestRaycast : public Test { test(!mCallback.isHit); test(!mCylinderBody->raycast(ray2, raycastInfo3)); - test(!mCylinderShape->raycast(ray2, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray2, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray2, &mCallback); test(!mCallback.isHit); test(!mCylinderBody->raycast(ray3, raycastInfo3)); - test(!mCylinderShape->raycast(ray3, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray3, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray3, &mCallback); test(!mCallback.isHit); test(!mCylinderBody->raycast(ray4, raycastInfo3)); - test(!mCylinderShape->raycast(ray4, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray4, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray4, &mCallback); test(!mCallback.isHit); test(!mCylinderBody->raycast(ray5, raycastInfo3)); - test(!mCylinderShape->raycast(ray5, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray5, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray5, &mCallback); test(!mCallback.isHit); test(!mCylinderBody->raycast(ray6, raycastInfo3)); - test(!mCylinderShape->raycast(ray6, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray6, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray6, &mCallback); test(!mCallback.isHit); test(!mCylinderBody->raycast(ray7, raycastInfo3)); - test(!mCylinderShape->raycast(ray7, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray7, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray7, &mCallback); test(!mCallback.isHit); test(!mCylinderBody->raycast(ray8, raycastInfo3)); - test(!mCylinderShape->raycast(ray8, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray8, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray8, &mCallback); test(!mCallback.isHit); test(!mCylinderBody->raycast(ray9, raycastInfo3)); - test(!mCylinderShape->raycast(ray9, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray9, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray9, &mCallback); test(!mCallback.isHit); test(!mCylinderBody->raycast(ray10, raycastInfo3)); - test(!mCylinderShape->raycast(ray10, raycastInfo3)); + test(!mCylinderProxyShape->raycast(ray10, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray10, &mCallback); test(!mCallback.isHit); @@ -1611,7 +1632,7 @@ class TestRaycast : public Test { // ----- Test raycast hits ----- // test(mCylinderBody->raycast(ray11, raycastInfo3)); - test(mCylinderShape->raycast(ray11, raycastInfo3)); + test(mCylinderProxyShape->raycast(ray11, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray11, &mCallback); test(mCallback.isHit); @@ -1620,7 +1641,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCylinderBody->raycast(ray12, raycastInfo3)); - test(mCylinderShape->raycast(ray12, raycastInfo3)); + test(mCylinderProxyShape->raycast(ray12, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray12, &mCallback); test(mCallback.isHit); @@ -1629,7 +1650,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCylinderBody->raycast(ray13, raycastInfo3)); - test(mCylinderShape->raycast(ray13, raycastInfo3)); + test(mCylinderProxyShape->raycast(ray13, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray13, &mCallback); test(mCallback.isHit); @@ -1638,7 +1659,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCylinderBody->raycast(ray14, raycastInfo3)); - test(mCylinderShape->raycast(ray14, raycastInfo3)); + test(mCylinderProxyShape->raycast(ray14, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray14, &mCallback); test(mCallback.isHit); @@ -1647,7 +1668,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCylinderBody->raycast(ray15, raycastInfo3)); - test(mCylinderShape->raycast(ray15, raycastInfo3)); + test(mCylinderProxyShape->raycast(ray15, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray15, &mCallback); test(mCallback.isHit); @@ -1656,7 +1677,7 @@ class TestRaycast : public Test { test(mCallback.isHit); test(mCylinderBody->raycast(ray16, raycastInfo3)); - test(mCylinderShape->raycast(ray16, raycastInfo3)); + test(mCylinderProxyShape->raycast(ray16, raycastInfo3)); mCallback.reset(); mWorld->raycast(ray16, &mCallback); test(mCallback.isHit); @@ -1679,7 +1700,7 @@ class TestRaycast : public Test { Ray ray5(mLocalShape2ToWorld * Vector3(0, -4, 1), mLocalShape2ToWorld * Vector3(0, 30, 1)); Ray ray6(mLocalShape2ToWorld * Vector3(-1, 2, -11), mLocalShape2ToWorld * Vector3(-1, 2, 30)); - mCallback.shapeToTest = mCompoundSphereShape; + mCallback.shapeToTest = mCompoundSphereProxyShape; // Correct category filter mask mCallback.reset(); @@ -1748,7 +1769,7 @@ class TestRaycast : public Test { Ray ray15(mLocalShapeToWorld * Vector3(0, -9, 1), mLocalShapeToWorld * Vector3(0, 30, 1)); Ray ray16(mLocalShapeToWorld * Vector3(-1, 2, -7), mLocalShapeToWorld * Vector3(-1, 2, 30)); - mCallback.shapeToTest = mCompoundCylinderShape; + mCallback.shapeToTest = mCompoundCylinderProxyShape; test(mCompoundBody->raycast(ray11, raycastInfo)); mCallback.reset(); diff --git a/testbed/common/Box.cpp b/testbed/common/Box.cpp index dc5e9d94..34dc26c0 100644 --- a/testbed/common/Box.cpp +++ b/testbed/common/Box.cpp @@ -132,7 +132,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &p // Create the collision shape for the rigid body (box shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::BoxShape collisionShape(rp3d::Vector3(mSize[0], mSize[1], mSize[2])); + mboxCollisionShape = new rp3d::BoxShape(rp3d::Vector3(mSize[0], mSize[1], mSize[2])); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -145,7 +145,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &p mBody = world->createCollisionBody(transform); // Add the collision shape to the body - mBody->addCollisionShape(collisionShape, rp3d::Transform::identity()); + mBody->addCollisionShape(mboxCollisionShape, rp3d::Transform::identity()); // If the Vertex Buffer object has not been created yet if (totalNbBoxes == 0) { @@ -181,7 +181,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3& p // Create the collision shape for the rigid body (box shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::BoxShape collisionShape(rp3d::Vector3(mSize[0], mSize[1], mSize[2])); + mboxCollisionShape = new rp3d::BoxShape(rp3d::Vector3(mSize[0], mSize[1], mSize[2])); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -194,7 +194,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3& p rp3d::RigidBody* body = world->createRigidBody(transform); // Add the collision shape to the body - body->addCollisionShape(collisionShape, rp3d::Transform::identity(), mass); + body->addCollisionShape(mboxCollisionShape, rp3d::Transform::identity(), mass); mBody = body; @@ -220,7 +220,7 @@ Box::~Box() { mVBONormals.destroy(); mVAO.destroy(); } - + delete mboxCollisionShape; totalNbBoxes--; } diff --git a/testbed/common/Box.h b/testbed/common/Box.h index a879c92a..2969fdd0 100644 --- a/testbed/common/Box.h +++ b/testbed/common/Box.h @@ -41,6 +41,8 @@ class Box : public openglframework::Object3D, public PhysicsObject { /// Size of each side of the box float mSize[3]; + rp3d::BoxShape* mboxCollisionShape; + /// Scaling matrix (applied to a cube to obtain the correct box dimensions) openglframework::Matrix4 mScalingMatrix; diff --git a/testbed/common/Capsule.cpp b/testbed/common/Capsule.cpp index 77bfe437..c2c2bc05 100644 --- a/testbed/common/Capsule.cpp +++ b/testbed/common/Capsule.cpp @@ -57,7 +57,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos // Create the collision shape for the rigid body (sphere shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::CapsuleShape collisionShape(mRadius, mHeight); + mCollisionShape = new rp3d::CapsuleShape(mRadius, mHeight); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -70,7 +70,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos mBody = world->createCollisionBody(transform); // Add a collision shape to the body and specify the mass of the shape - mBody->addCollisionShape(collisionShape, rp3d::Transform::identity()); + mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity()); mTransformMatrix = mTransformMatrix * mScalingMatrix; @@ -106,7 +106,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos // Create the collision shape for the rigid body (sphere shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::CapsuleShape collisionShape(mRadius, mHeight); + mCollisionShape = new rp3d::CapsuleShape(mRadius, mHeight); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -117,7 +117,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform); // Add a collision shape to the body and specify the mass of the shape - body->addCollisionShape(collisionShape, rp3d::Transform::identity(), mass); + body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass); mBody = body; @@ -146,7 +146,7 @@ Capsule::~Capsule() { mVBOTextureCoords.destroy(); mVAO.destroy(); } - + delete mCollisionShape; totalNbCapsules--; } diff --git a/testbed/common/Capsule.h b/testbed/common/Capsule.h index c1a37779..e18c3ff5 100644 --- a/testbed/common/Capsule.h +++ b/testbed/common/Capsule.h @@ -44,6 +44,9 @@ class Capsule : public openglframework::Mesh, public PhysicsObject { /// Height of the capsule float mHeight; + /// Collision shape + rp3d::CapsuleShape* mCollisionShape; + /// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions) openglframework::Matrix4 mScalingMatrix; diff --git a/testbed/common/Cone.cpp b/testbed/common/Cone.cpp index 079a6189..22953283 100644 --- a/testbed/common/Cone.cpp +++ b/testbed/common/Cone.cpp @@ -54,10 +54,9 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position, // Initialize the position where the cone will be rendered translateWorld(position); - // Create the collision shape for the rigid body (cone shape) - // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::ConeShape collisionShape(mRadius, mHeight); + // Create the collision shape for the rigid body (cone shape) and do + // not forget to delete it at the end + mCollisionShape = new rp3d::ConeShape(mRadius, mHeight); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -70,7 +69,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position, mBody = world->createCollisionBody(transform); // Add a collision shape to the body and specify the mass of the shape - mBody->addCollisionShape(collisionShape, rp3d::Transform::identity()); + mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity()); mTransformMatrix = mTransformMatrix * mScalingMatrix; @@ -103,10 +102,9 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position, // Initialize the position where the cone will be rendered translateWorld(position); - // Create the collision shape for the rigid body (cone shape) - // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::ConeShape collisionShape(mRadius, mHeight); + // Create the collision shape for the rigid body (cone shape) and do not + // forget to delete it at the end + mCollisionShape = new rp3d::ConeShape(mRadius, mHeight); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -117,7 +115,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position, rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform); // Add a collision shape to the body and specify the mass of the shape - body->addCollisionShape(collisionShape, rp3d::Transform::identity(), mass); + body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass); mBody = body; @@ -145,7 +143,7 @@ Cone::~Cone() { mVBOTextureCoords.destroy(); mVAO.destroy(); } - + delete mCollisionShape; totalNbCones--; } diff --git a/testbed/common/Cone.h b/testbed/common/Cone.h index 1d256752..eeb4f0a4 100644 --- a/testbed/common/Cone.h +++ b/testbed/common/Cone.h @@ -44,6 +44,9 @@ class Cone : public openglframework::Mesh, public PhysicsObject { /// Height of the cone float mHeight; + /// Collision shape + rp3d::ConeShape* mCollisionShape; + /// Scaling matrix (applied to a sphere to obtain the correct cone dimensions) openglframework::Matrix4 mScalingMatrix; diff --git a/testbed/common/ConvexMesh.cpp b/testbed/common/ConvexMesh.cpp index 182c5940..4527e8fb 100644 --- a/testbed/common/ConvexMesh.cpp +++ b/testbed/common/ConvexMesh.cpp @@ -51,11 +51,9 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, vertices[3 * i + 2] = static_cast(mVertices[i].z); } - // Create the collision shape for the rigid body (convex mesh shape) - // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - - rp3d::ConvexMeshShape collisionShape(vertices, mVertices.size(), 3 * sizeof(rp3d::decimal)); + // Create the collision shape for the rigid body (convex mesh shape) and + // do not forget to delete it at the end + mCollisionShape = new rp3d::ConvexMeshShape(vertices, mVertices.size(), 3 * sizeof(rp3d::decimal)); delete[] vertices; @@ -70,11 +68,11 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, unsigned int v3 = getVertexIndexInFace(i, 2); // Add the three edges into the collision shape - collisionShape.addEdge(v1, v2); - collisionShape.addEdge(v1, v3); - collisionShape.addEdge(v2, v3); + mCollisionShape->addEdge(v1, v2); + mCollisionShape->addEdge(v1, v3); + mCollisionShape->addEdge(v2, v3); } - collisionShape.setIsEdgesInformationUsed(true);// Enable the fast collision detection with edges + mCollisionShape->setIsEdgesInformationUsed(true);// Enable the fast collision detection with edges // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -87,7 +85,7 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, mBody = world->createCollisionBody(transform); // Add a collision shape to the body and specify the mass of the collision shape - mBody->addCollisionShape(collisionShape, rp3d::Transform::identity()); + mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity()); // Create the VBOs and VAO createVBOAndVAO(); @@ -118,10 +116,9 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass, vertices[3 * i + 2] = static_cast(mVertices[i].z); } - // Create the collision shape for the rigid body (convex mesh shape) - // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - rp3d::ConvexMeshShape collisionShape(vertices, mVertices.size(), 3 * sizeof(rp3d::decimal)); + // Create the collision shape for the rigid body (convex mesh shape) and do + // not forget to delete it at the end + mCollisionShape = new rp3d::ConvexMeshShape(vertices, mVertices.size(), 3 * sizeof(rp3d::decimal)); delete[] vertices; @@ -136,11 +133,11 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass, unsigned int v3 = getVertexIndexInFace(i, 2); // Add the three edges into the collision shape - collisionShape.addEdge(v1, v2); - collisionShape.addEdge(v1, v3); - collisionShape.addEdge(v2, v3); + mCollisionShape->addEdge(v1, v2); + mCollisionShape->addEdge(v1, v3); + mCollisionShape->addEdge(v2, v3); } - collisionShape.setIsEdgesInformationUsed(true);// Enable the fast collision detection with edges + mCollisionShape->setIsEdgesInformationUsed(true);// Enable the fast collision detection with edges // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -151,7 +148,7 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass, rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform); // Add a collision shape to the body and specify the mass of the collision shape - body->addCollisionShape(collisionShape, rp3d::Transform::identity(), mass); + body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass); mBody = body; @@ -171,6 +168,8 @@ ConvexMesh::~ConvexMesh() { mVBONormals.destroy(); mVBOTextureCoords.destroy(); mVAO.destroy(); + + delete mCollisionShape; } // Render the sphere at the correct position and with the correct orientation diff --git a/testbed/common/ConvexMesh.h b/testbed/common/ConvexMesh.h index 4a4cdcdb..b1089826 100644 --- a/testbed/common/ConvexMesh.h +++ b/testbed/common/ConvexMesh.h @@ -41,6 +41,9 @@ class ConvexMesh : public openglframework::Mesh, public PhysicsObject { /// Previous transform (for interpolation) rp3d::Transform mPreviousTransform; + /// Collision shape + rp3d::ConvexMeshShape* mCollisionShape; + /// Vertex Buffer Object for the vertices data openglframework::VertexBufferObject mVBOVertices; diff --git a/testbed/common/Cylinder.cpp b/testbed/common/Cylinder.cpp index bfc39092..f269637c 100644 --- a/testbed/common/Cylinder.cpp +++ b/testbed/common/Cylinder.cpp @@ -54,10 +54,9 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p // Initialize the position where the cylinder will be rendered translateWorld(position); - // Create the collision shape for the rigid body (cylinder shape) - // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::CylinderShape collisionShape(mRadius, mHeight); + // Create the collision shape for the rigid body (cylinder shape) and do not + // forget to delete it at the end + mCollisionShape = new rp3d::CylinderShape(mRadius, mHeight); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -70,7 +69,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p mBody = world->createCollisionBody(transform); // Add a collision shape to the body and specify the mass of the shape - mBody->addCollisionShape(collisionShape, rp3d::Transform::identity()); + mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity()); mTransformMatrix = mTransformMatrix * mScalingMatrix; @@ -103,10 +102,9 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p // Initialize the position where the cylinder will be rendered translateWorld(position); - // Create the collision shape for the rigid body (cylinder shape) - // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::CylinderShape collisionShape(mRadius, mHeight); + // Create the collision shape for the rigid body (cylinder shape) and do + // not forget to delete it at the end + mCollisionShape = new rp3d::CylinderShape(mRadius, mHeight); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -117,7 +115,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform); // Add a collision shape to the body and specify the mass of the shape - body->addCollisionShape(collisionShape, rp3d::Transform::identity(), mass); + body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass); mTransformMatrix = mTransformMatrix * mScalingMatrix; @@ -146,7 +144,7 @@ Cylinder::~Cylinder() { mVBOTextureCoords.destroy(); mVAO.destroy(); } - + delete mCollisionShape; totalNbCylinders--; } diff --git a/testbed/common/Cylinder.h b/testbed/common/Cylinder.h index 17379e7c..4bb5232e 100644 --- a/testbed/common/Cylinder.h +++ b/testbed/common/Cylinder.h @@ -50,6 +50,9 @@ class Cylinder : public openglframework::Mesh, public PhysicsObject { /// Previous transform (for interpolation) rp3d::Transform mPreviousTransform; + /// Collision shape + rp3d::CylinderShape* mCollisionShape; + /// Vertex Buffer Object for the vertices data static openglframework::VertexBufferObject mVBOVertices; diff --git a/testbed/common/Dumbbell.cpp b/testbed/common/Dumbbell.cpp index c97daf03..f4085c56 100644 --- a/testbed/common/Dumbbell.cpp +++ b/testbed/common/Dumbbell.cpp @@ -55,7 +55,7 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() const rp3d::decimal radiusSphere = rp3d::decimal(1.5); const rp3d::decimal massSphere = rp3d::decimal(2.0); - const rp3d::SphereShape sphereCollisionShape(radiusSphere); + mSphereShape = new rp3d::SphereShape(radiusSphere); // Create a cylinder collision shape for the middle of the dumbbell // ReactPhysics3D will clone this object to create an internal one. Therefore, @@ -63,7 +63,7 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position, const rp3d::decimal radiusCylinder = rp3d::decimal(0.5); const rp3d::decimal heightCylinder = rp3d::decimal(8.0); const rp3d::decimal massCylinder = rp3d::decimal(1.0); - const rp3d::CylinderShape cylinderCollisionShape(radiusCylinder, heightCylinder); + mCylinderShape = new rp3d::CylinderShape(radiusCylinder, heightCylinder); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -86,9 +86,9 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position, rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transformBody); // Add the three collision shapes to the body and specify the mass and transform of the shapes - body->addCollisionShape(sphereCollisionShape, transformSphereShape1, massSphere); - body->addCollisionShape(sphereCollisionShape, transformSphereShape2, massSphere); - body->addCollisionShape(cylinderCollisionShape, transformCylinderShape, massCylinder); + body->addCollisionShape(mSphereShape, transformSphereShape1, massSphere); + body->addCollisionShape(mSphereShape, transformSphereShape2, massSphere); + body->addCollisionShape(mCylinderShape, transformCylinderShape, massCylinder); mBody = body; @@ -123,14 +123,14 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position, // ReactPhysics3D will clone this object to create an internal one. Therefore, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() const rp3d::decimal radiusSphere = rp3d::decimal(1.5); - const rp3d::SphereShape sphereCollisionShape(radiusSphere); + mSphereShape = new rp3d::SphereShape(radiusSphere); // Create a cylinder collision shape for the middle of the dumbbell // ReactPhysics3D will clone this object to create an internal one. Therefore, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() const rp3d::decimal radiusCylinder = rp3d::decimal(0.5); const rp3d::decimal heightCylinder = rp3d::decimal(8.0); - const rp3d::CylinderShape cylinderCollisionShape(radiusCylinder, heightCylinder); + mCylinderShape = new rp3d::CylinderShape(radiusCylinder, heightCylinder); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -151,9 +151,9 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position, mBody = world->createCollisionBody(transformBody); // Add the three collision shapes to the body and specify the mass and transform of the shapes - mBody->addCollisionShape(sphereCollisionShape, transformSphereShape1); - mBody->addCollisionShape(sphereCollisionShape, transformSphereShape2); - mBody->addCollisionShape(cylinderCollisionShape, transformCylinderShape); + mBody->addCollisionShape(mSphereShape, transformSphereShape1); + mBody->addCollisionShape(mSphereShape, transformSphereShape2); + mBody->addCollisionShape(mCylinderShape, transformCylinderShape); mTransformMatrix = mTransformMatrix * mScalingMatrix; @@ -180,7 +180,8 @@ Dumbbell::~Dumbbell() { mVBOTextureCoords.destroy(); mVAO.destroy(); } - + delete mSphereShape; + delete mCylinderShape; totalNbDumbbells--; } diff --git a/testbed/common/Dumbbell.h b/testbed/common/Dumbbell.h index cde7cea9..9f933948 100644 --- a/testbed/common/Dumbbell.h +++ b/testbed/common/Dumbbell.h @@ -41,6 +41,10 @@ class Dumbbell : public openglframework::Mesh, public PhysicsObject { /// Radius of the spheres float mRadius; + /// Collision shapes + rp3d::CylinderShape* mCylinderShape; + rp3d::SphereShape* mSphereShape; + /// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions) openglframework::Matrix4 mScalingMatrix; diff --git a/testbed/common/Sphere.cpp b/testbed/common/Sphere.cpp index 783478ce..39eb10cd 100644 --- a/testbed/common/Sphere.cpp +++ b/testbed/common/Sphere.cpp @@ -57,7 +57,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position, // Create the collision shape for the rigid body (sphere shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::SphereShape collisionShape(mRadius); + mCollisionShape = new rp3d::SphereShape(mRadius); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -70,7 +70,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position, mBody = world->createCollisionBody(transform); // Add a collision shape to the body and specify the mass of the shape - mBody->addCollisionShape(collisionShape, rp3d::Transform::identity()); + mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity()); mTransformMatrix = mTransformMatrix * mScalingMatrix; @@ -106,7 +106,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position, // Create the collision shape for the rigid body (sphere shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() - const rp3d::SphereShape collisionShape(mRadius); + mCollisionShape = new rp3d::SphereShape(mRadius); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -117,7 +117,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position, rp3d::RigidBody* body = world->createRigidBody(transform); // Add a collision shape to the body and specify the mass of the shape - body->addCollisionShape(collisionShape, rp3d::Transform::identity(), mass); + body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass); mBody = body; @@ -145,7 +145,7 @@ Sphere::~Sphere() { mVBOTextureCoords.destroy(); mVAO.destroy(); } - + delete mCollisionShape; totalNbSpheres--; } diff --git a/testbed/common/Sphere.h b/testbed/common/Sphere.h index 99a27ecc..0761b456 100644 --- a/testbed/common/Sphere.h +++ b/testbed/common/Sphere.h @@ -41,6 +41,9 @@ class Sphere : public openglframework::Mesh, public PhysicsObject { /// Radius of the sphere float mRadius; + /// Collision shape + rp3d::SphereShape* mCollisionShape; + /// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions) openglframework::Matrix4 mScalingMatrix;