diff --git a/src/body/Body.cpp b/src/body/Body.cpp index 7974a6b9..0f02a55b 100644 --- a/src/body/Body.cpp +++ b/src/body/Body.cpp @@ -36,11 +36,6 @@ using namespace reactphysics3d; */ Body::Body(bodyindex id) : mID(id), mIsAlreadyInIsland(false), mIsAllowedToSleep(true), mIsActive(true), - mIsSleeping(false), mSleepTime(0), mUserData(NULL) { - -} - -// Destructor -Body::~Body() { + mIsSleeping(false), mSleepTime(0), mUserData(nullptr) { } diff --git a/src/body/Body.h b/src/body/Body.h index 4d1f9bf4..b1b18325 100644 --- a/src/body/Body.h +++ b/src/body/Body.h @@ -75,14 +75,6 @@ class Body { /// Pointer that can be used to attach user data to the body void* mUserData; - // -------------------- Methods -------------------- // - - /// Private copy-constructor - Body(const Body& body); - - /// Private assignment operator - Body& operator=(const Body& body); - public : // -------------------- Methods -------------------- // @@ -90,8 +82,14 @@ class Body { /// Constructor Body(bodyindex id); + /// Deleted copy-constructor + Body(const Body& body) = delete; + + /// Deleted assignment operator + Body& operator=(const Body& body) = delete; + /// Destructor - virtual ~Body(); + virtual ~Body() = default; /// Return the ID of the body bodyindex getID() const; diff --git a/src/body/CollisionBody.cpp b/src/body/CollisionBody.cpp index e5a51b91..daa4a71e 100644 --- a/src/body/CollisionBody.cpp +++ b/src/body/CollisionBody.cpp @@ -38,14 +38,14 @@ using namespace reactphysics3d; * @param id ID of the body */ CollisionBody::CollisionBody(const Transform& transform, CollisionWorld& world, bodyindex id) - : Body(id), mType(DYNAMIC), mTransform(transform), mProxyCollisionShapes(NULL), - mNbCollisionShapes(0), mContactManifoldsList(NULL), mWorld(world) { + : Body(id), mType(BodyType::DYNAMIC), mTransform(transform), mProxyCollisionShapes(nullptr), + mNbCollisionShapes(0), mContactManifoldsList(nullptr), mWorld(world) { } // Destructor CollisionBody::~CollisionBody() { - assert(mContactManifoldsList == NULL); + assert(mContactManifoldsList == nullptr); // Remove all the proxy collision shapes of the body removeAllCollisionShapes(); @@ -75,7 +75,7 @@ ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape, transform, decimal(1)); // Add it to the list of proxy collision shapes of the body - if (mProxyCollisionShapes == NULL) { + if (mProxyCollisionShapes == nullptr) { mProxyCollisionShapes = proxyShape; } else { @@ -122,7 +122,7 @@ void CollisionBody::removeCollisionShape(const ProxyShape* proxyShape) { } // Look for the proxy shape that contains the collision shape in parameter - while(current->mNext != NULL) { + while(current->mNext != nullptr) { // If we have found the collision shape to remove if (current->mNext == proxyShape) { @@ -152,7 +152,7 @@ void CollisionBody::removeAllCollisionShapes() { ProxyShape* current = mProxyCollisionShapes; // Look for the proxy shape that contains the collision shape in parameter - while(current != NULL) { + while(current != nullptr) { // Remove the proxy collision shape ProxyShape* nextElement = current->mNext; @@ -168,7 +168,7 @@ void CollisionBody::removeAllCollisionShapes() { current = nextElement; } - mProxyCollisionShapes = NULL; + mProxyCollisionShapes = nullptr; } // Reset the contact manifold lists @@ -176,7 +176,7 @@ void CollisionBody::resetContactManifoldsList() { // Delete the linked list of contact manifolds of that body ContactManifoldListElement* currentElement = mContactManifoldsList; - while (currentElement != NULL) { + while (currentElement != nullptr) { ContactManifoldListElement* nextElement = currentElement->next; // Delete the current element @@ -185,14 +185,14 @@ void CollisionBody::resetContactManifoldsList() { currentElement = nextElement; } - mContactManifoldsList = NULL; + mContactManifoldsList = nullptr; } // Update the broad-phase state for this body (because it has moved for instance) void CollisionBody::updateBroadPhaseState() const { // For all the proxy collision shapes of the body - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { // Update the proxy updateProxyShapeInBroadPhase(shape); @@ -225,7 +225,7 @@ void CollisionBody::setIsActive(bool isActive) { if (isActive) { // For each proxy shape of the body - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { // Compute the world-space AABB of the new collision shape AABB aabb; @@ -238,7 +238,7 @@ void CollisionBody::setIsActive(bool isActive) { else { // If we have to deactivate the body // For each proxy shape of the body - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { // Remove the proxy shape from the collision detection mWorld.mCollisionDetection.removeProxyCollisionShape(shape); @@ -254,7 +254,7 @@ void CollisionBody::setIsActive(bool isActive) { void CollisionBody::askForBroadPhaseCollisionCheck() const { // For all the proxy collision shapes of the body - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { mWorld.mCollisionDetection.askForBroadPhaseCollisionCheck(shape); } @@ -271,7 +271,7 @@ int CollisionBody::resetIsAlreadyInIslandAndCountManifolds() { // Reset the mIsAlreadyInIsland variable of the contact manifolds for // this body ContactManifoldListElement* currentElement = mContactManifoldsList; - while (currentElement != NULL) { + while (currentElement != nullptr) { currentElement->contactManifold->mIsAlreadyInIsland = false; currentElement = currentElement->next; nbManifolds++; @@ -289,7 +289,7 @@ int CollisionBody::resetIsAlreadyInIslandAndCountManifolds() { bool CollisionBody::testPointInside(const Vector3& worldPoint) const { // For each collision shape of the body - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { // Test if the point is inside the collision shape if (shape->testPointInside(worldPoint)) return true; @@ -315,7 +315,7 @@ bool CollisionBody::raycast(const Ray& ray, RaycastInfo& raycastInfo) { Ray rayTemp(ray); // For each collision shape of the body - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { // Test if the ray hits the collision shape if (shape->raycast(rayTemp, raycastInfo)) { @@ -335,12 +335,12 @@ AABB CollisionBody::getAABB() const { AABB bodyAABB; - if (mProxyCollisionShapes == NULL) return bodyAABB; + if (mProxyCollisionShapes == nullptr) return bodyAABB; mProxyCollisionShapes->getCollisionShape()->computeAABB(bodyAABB, mTransform * mProxyCollisionShapes->getLocalToBodyTransform()); // For each proxy shape of the body - for (ProxyShape* shape = mProxyCollisionShapes->mNext; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes->mNext; shape != nullptr; shape = shape->mNext) { // Compute the world-space AABB of the collision shape AABB aabb; diff --git a/src/body/CollisionBody.h b/src/body/CollisionBody.h index f69be6c5..5fda6958 100644 --- a/src/body/CollisionBody.h +++ b/src/body/CollisionBody.h @@ -54,7 +54,7 @@ class CollisionWorld; /// DYNAMIC : A dynamic body has non-zero mass, non-zero velocity determined by forces and its /// position is determined by the physics engine. A dynamic body can collide with other /// dynamic, static or kinematic bodies. -enum BodyType {STATIC, KINEMATIC, DYNAMIC}; +enum class BodyType {STATIC, KINEMATIC, DYNAMIC}; // Class CollisionBody /** @@ -87,12 +87,6 @@ class CollisionBody : public Body { // -------------------- Methods -------------------- // - /// Private copy-constructor - CollisionBody(const CollisionBody& body); - - /// Private assignment operator - CollisionBody& operator=(const CollisionBody& body); - /// Reset the contact manifold lists void resetContactManifoldsList(); @@ -120,7 +114,13 @@ class CollisionBody : public Body { CollisionBody(const Transform& transform, CollisionWorld& world, bodyindex id); /// Destructor - virtual ~CollisionBody(); + virtual ~CollisionBody() override; + + /// Deleted copy-constructor + CollisionBody(const CollisionBody& body) = delete; + + /// Deleted assignment operator + CollisionBody& operator=(const CollisionBody& body) = delete; /// Return the type of the body BodyType getType() const; @@ -129,7 +129,7 @@ class CollisionBody : public Body { void setType(BodyType type); /// Set whether or not the body is active - virtual void setIsActive(bool isActive); + virtual void setIsActive(bool isActive) override; /// Return the current position and orientation const Transform& getTransform() const; @@ -208,7 +208,7 @@ inline BodyType CollisionBody::getType() const { inline void CollisionBody::setType(BodyType type) { mType = type; - if (mType == STATIC) { + if (mType == BodyType::STATIC) { // Update the broad-phase state of the body updateBroadPhaseState(); diff --git a/src/body/RigidBody.cpp b/src/body/RigidBody.cpp index b1818b26..ff77b228 100644 --- a/src/body/RigidBody.cpp +++ b/src/body/RigidBody.cpp @@ -42,7 +42,7 @@ RigidBody::RigidBody(const Transform& transform, CollisionWorld& world, bodyinde : CollisionBody(transform, world, id), mInitMass(decimal(1.0)), mCenterOfMassLocal(0, 0, 0), mCenterOfMassWorld(transform.getPosition()), mIsGravityEnabled(true), mLinearDamping(decimal(0.0)), mAngularDamping(decimal(0.0)), - mJointsList(NULL) { + mJointsList(nullptr) { // Compute the inverse mass mMassInverse = decimal(1.0) / mInitMass; @@ -50,7 +50,7 @@ RigidBody::RigidBody(const Transform& transform, CollisionWorld& world, bodyinde // Destructor RigidBody::~RigidBody() { - assert(mJointsList == NULL); + assert(mJointsList == nullptr); } // Set the type of the body @@ -76,7 +76,7 @@ void RigidBody::setType(BodyType type) { recomputeMassInformation(); // If it is a static body - if (mType == STATIC) { + if (mType == BodyType::STATIC) { // Reset the velocity to zero mLinearVelocity.setToZero(); @@ -84,7 +84,7 @@ void RigidBody::setType(BodyType type) { } // If it is a static or a kinematic body - if (mType == STATIC || mType == KINEMATIC) { + if (mType == BodyType::STATIC || mType == BodyType::KINEMATIC) { // Reset the inverse mass and inverse inertia tensor to zero mMassInverse = decimal(0.0); @@ -119,7 +119,7 @@ void RigidBody::setType(BodyType type) { */ void RigidBody::setInertiaTensorLocal(const Matrix3x3& inertiaTensorLocal) { - if (mType != DYNAMIC) return; + if (mType != BodyType::DYNAMIC) return; mInertiaTensorLocal = inertiaTensorLocal; @@ -134,7 +134,7 @@ void RigidBody::setInertiaTensorLocal(const Matrix3x3& inertiaTensorLocal) { */ void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) { - if (mType != DYNAMIC) return; + if (mType != BodyType::DYNAMIC) return; const Vector3 oldCenterOfMass = mCenterOfMassWorld; mCenterOfMassLocal = centerOfMassLocal; @@ -152,7 +152,7 @@ void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) { */ void RigidBody::setMass(decimal mass) { - if (mType != DYNAMIC) return; + if (mType != BodyType::DYNAMIC) return; mInitMass = mass; @@ -168,8 +168,8 @@ void RigidBody::setMass(decimal mass) { // Remove a joint from the joints list void RigidBody::removeJointFromJointsList(MemoryAllocator& memoryAllocator, const Joint* joint) { - assert(joint != NULL); - assert(mJointsList != NULL); + assert(joint != nullptr); + assert(mJointsList != nullptr); // Remove the joint from the linked list of the joints of the first body if (mJointsList->joint == joint) { // If the first element is the one to remove @@ -180,7 +180,7 @@ void RigidBody::removeJointFromJointsList(MemoryAllocator& memoryAllocator, cons } else { // If the element to remove is not the first one in the list JointListElement* currentElement = mJointsList; - while (currentElement->next != NULL) { + while (currentElement->next != nullptr) { if (currentElement->next->joint == joint) { JointListElement* elementToRemove = currentElement->next; currentElement->next = elementToRemove->next; @@ -219,7 +219,7 @@ ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape, transform, mass); // Add it to the list of proxy collision shapes of the body - if (mProxyCollisionShapes == NULL) { + if (mProxyCollisionShapes == nullptr) { mProxyCollisionShapes = proxyShape; } else { @@ -267,7 +267,7 @@ void RigidBody::removeCollisionShape(const ProxyShape* proxyShape) { void RigidBody::setLinearVelocity(const Vector3& linearVelocity) { // If it is a static body, we do nothing - if (mType == STATIC) return; + if (mType == BodyType::STATIC) return; // Update the linear velocity of the current body state mLinearVelocity = linearVelocity; @@ -285,7 +285,7 @@ void RigidBody::setLinearVelocity(const Vector3& linearVelocity) { void RigidBody::setAngularVelocity(const Vector3& angularVelocity) { // If it is a static body, we do nothing - if (mType == STATIC) return; + if (mType == BodyType::STATIC) return; // Set the angular velocity mAngularVelocity = angularVelocity; @@ -329,15 +329,15 @@ void RigidBody::recomputeMassInformation() { mCenterOfMassLocal.setToZero(); // If it is STATIC or KINEMATIC body - if (mType == STATIC || mType == KINEMATIC) { + if (mType == BodyType::STATIC || mType == BodyType::KINEMATIC) { mCenterOfMassWorld = mTransform.getPosition(); return; } - assert(mType == DYNAMIC); + assert(mType == BodyType::DYNAMIC); // Compute the total mass of the body - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { mInitMass += shape->getMass(); mCenterOfMassLocal += shape->getLocalToBodyTransform().getPosition() * shape->getMass(); } @@ -356,7 +356,7 @@ void RigidBody::recomputeMassInformation() { mCenterOfMassWorld = mTransform * mCenterOfMassLocal; // Compute the total mass and inertia tensor using all the collision shapes - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { // Get the inertia tensor of the collision shape in its local-space Matrix3x3 inertiaTensor; @@ -399,7 +399,7 @@ void RigidBody::updateBroadPhaseState() const { const Vector3 displacement = world.mTimeStep * mLinearVelocity; // For all the proxy collision shapes of the body - for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { + for (ProxyShape* shape = mProxyCollisionShapes; shape != nullptr; shape = shape->mNext) { // Recompute the world-space AABB of the collision shape AABB aabb; diff --git a/src/body/RigidBody.h b/src/body/RigidBody.h index fd1c18b7..8fb36d0e 100644 --- a/src/body/RigidBody.h +++ b/src/body/RigidBody.h @@ -103,12 +103,6 @@ class RigidBody : public CollisionBody { // -------------------- Methods -------------------- // - /// Private copy-constructor - RigidBody(const RigidBody& body); - - /// Private assignment operator - RigidBody& operator=(const RigidBody& body); - /// Remove a joint from the joints list void removeJointFromJointsList(MemoryAllocator& memoryAllocator, const Joint* joint); @@ -116,7 +110,7 @@ class RigidBody : public CollisionBody { void updateTransformWithCenterOfMass(); /// Update the broad-phase state for this body (because it has moved for instance) - virtual void updateBroadPhaseState() const; + virtual void updateBroadPhaseState() const override; public : @@ -126,13 +120,19 @@ class RigidBody : public CollisionBody { RigidBody(const Transform& transform, CollisionWorld& world, bodyindex id); /// Destructor - virtual ~RigidBody(); + virtual ~RigidBody() override; + + /// Deleted copy-constructor + RigidBody(const RigidBody& body) = delete; + + /// Deleted assignment operator + RigidBody& operator=(const RigidBody& body) = delete; /// Set the type of the body (static, kinematic or dynamic) void setType(BodyType type); /// Set the current position and orientation - virtual void setTransform(const Transform& transform); + virtual void setTransform(const Transform& transform) override; /// Return the mass of the body decimal getMass() const; @@ -150,7 +150,7 @@ class RigidBody : public CollisionBody { void setAngularVelocity(const Vector3& angularVelocity); /// Set the variable to know whether or not the body is sleeping - virtual void setIsSleeping(bool isSleeping); + virtual void setIsSleeping(bool isSleeping) override; /// Return the local inertia tensor of the body (in body coordinates) const Matrix3x3& getInertiaTensorLocal() const; @@ -215,7 +215,7 @@ class RigidBody : public CollisionBody { decimal mass); /// Remove a collision shape from the body - virtual void removeCollisionShape(const ProxyShape* proxyShape); + virtual void removeCollisionShape(const ProxyShape* proxyShape) override; /// Recompute the center of mass, total mass and inertia tensor of the body using all /// the collision shapes attached to the body. @@ -407,7 +407,7 @@ inline void RigidBody::setIsSleeping(bool isSleeping) { inline void RigidBody::applyForceToCenterOfMass(const Vector3& force) { // If it is not a dynamic body, we do nothing - if (mType != DYNAMIC) return; + if (mType != BodyType::DYNAMIC) return; // Awake the body if it was sleeping if (mIsSleeping) { @@ -432,7 +432,7 @@ inline void RigidBody::applyForceToCenterOfMass(const Vector3& force) { inline void RigidBody::applyForce(const Vector3& force, const Vector3& point) { // If it is not a dynamic body, we do nothing - if (mType != DYNAMIC) return; + if (mType != BodyType::DYNAMIC) return; // Awake the body if it was sleeping if (mIsSleeping) { @@ -455,7 +455,7 @@ inline void RigidBody::applyForce(const Vector3& force, const Vector3& point) { inline void RigidBody::applyTorque(const Vector3& torque) { // If it is not a dynamic body, we do nothing - if (mType != DYNAMIC) return; + if (mType != BodyType::DYNAMIC) return; // Awake the body if it was sleeping if (mIsSleeping) { diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index ea469ccb..7d9f6fb2 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -53,11 +53,6 @@ CollisionDetection::CollisionDetection(CollisionWorld* world, MemoryAllocator& m fillInCollisionMatrix(); } -// Destructor -CollisionDetection::~CollisionDetection() { - -} - // Compute the collision detection void CollisionDetection::computeCollisionDetection() { @@ -140,7 +135,7 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac contactPoint->getLocalPointOnBody2()); // Notify the collision callback about this new contact - if (callback != NULL) callback->notifyContact(contactInfo); + if (callback != nullptr) callback->notifyContact(contactInfo); } } } @@ -209,8 +204,8 @@ void CollisionDetection::computeNarrowPhase() { pair->update(); // Check that at least one body is awake and not static - bool isBody1Active = !body1->isSleeping() && body1->getType() != STATIC; - bool isBody2Active = !body2->isSleeping() && body2->getType() != STATIC; + bool isBody1Active = !body1->isSleeping() && body1->getType() != BodyType::STATIC; + bool isBody2Active = !body2->isSleeping() && body2->getType() != BodyType::STATIC; if (!isBody1Active && !isBody2Active) continue; // Check if the bodies are in the set of bodies that cannot collide between each other @@ -220,10 +215,12 @@ void CollisionDetection::computeNarrowPhase() { // Select the narrow phase algorithm to use according to the two collision shapes const CollisionShapeType shape1Type = shape1->getCollisionShape()->getType(); const CollisionShapeType shape2Type = shape2->getCollisionShape()->getType(); - NarrowPhaseAlgorithm* narrowPhaseAlgorithm = mCollisionMatrix[shape1Type][shape2Type]; + const int shape1Index = static_cast(shape1Type); + const int shape2Index = static_cast(shape2Type); + NarrowPhaseAlgorithm* narrowPhaseAlgorithm = mCollisionMatrix[shape1Index][shape2Index]; // If there is no collision algorithm between those two kinds of shapes - if (narrowPhaseAlgorithm == NULL) continue; + if (narrowPhaseAlgorithm == nullptr) continue; // Notify the narrow-phase algorithm about the overlapping pair we are going to test narrowPhaseAlgorithm->setCurrentOverlappingPair(pair); @@ -312,7 +309,7 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call pair->update(); // Check if the two bodies are allowed to collide, otherwise, we do not test for collision - if (body1->getType() != DYNAMIC && body2->getType() != DYNAMIC) continue; + if (body1->getType() != BodyType::DYNAMIC && body2->getType() != BodyType::DYNAMIC) continue; bodyindexpair bodiesIndex = OverlappingPair::computeBodiesIndexPair(body1, body2); if (mNoCollisionPairs.count(bodiesIndex) > 0) continue; @@ -322,10 +319,12 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call // Select the narrow phase algorithm to use according to the two collision shapes const CollisionShapeType shape1Type = shape1->getCollisionShape()->getType(); const CollisionShapeType shape2Type = shape2->getCollisionShape()->getType(); - NarrowPhaseAlgorithm* narrowPhaseAlgorithm = mCollisionMatrix[shape1Type][shape2Type]; + const int shape1Index = static_cast(shape1Type); + const int shape2Index = static_cast(shape2Type); + NarrowPhaseAlgorithm* narrowPhaseAlgorithm = mCollisionMatrix[shape1Index][shape2Index]; // If there is no collision algorithm between those two kinds of shapes - if (narrowPhaseAlgorithm == NULL) continue; + if (narrowPhaseAlgorithm == nullptr) continue; // Notify the narrow-phase algorithm about the overlapping pair we are going to test narrowPhaseAlgorithm->setCurrentOverlappingPair(pair); @@ -373,7 +372,7 @@ void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* shape1, Pro // Create the overlapping pair and add it into the set of overlapping pairs OverlappingPair* newPair = new (mWorld->mMemoryAllocator.allocate(sizeof(OverlappingPair))) OverlappingPair(shape1, shape2, nbMaxManifolds, mWorld->mMemoryAllocator); - assert(newPair != NULL); + assert(newPair != nullptr); #ifndef NDEBUG std::pair::iterator, bool> check = @@ -420,14 +419,14 @@ void CollisionDetection::notifyContact(OverlappingPair* overlappingPair, const C if (overlappingPair->getNbContactPoints() == 0) { // Trigger a callback event - if (mWorld->mEventListener != NULL) mWorld->mEventListener->beginContact(contactInfo); + if (mWorld->mEventListener != nullptr) mWorld->mEventListener->beginContact(contactInfo); } // Create a new contact createContact(overlappingPair, contactInfo); // Trigger a callback event for the new contact - if (mWorld->mEventListener != NULL) mWorld->mEventListener->newContact(contactInfo); + if (mWorld->mEventListener != nullptr) mWorld->mEventListener->newContact(contactInfo); } // Create a new contact @@ -463,7 +462,7 @@ void CollisionDetection::addAllContactManifoldsToBodies() { // in the corresponding contact void CollisionDetection::addContactManifoldToBody(OverlappingPair* pair) { - assert(pair != NULL); + assert(pair != nullptr); CollisionBody* body1 = pair->getShape1()->getBody(); CollisionBody* body2 = pair->getShape2()->getBody(); diff --git a/src/collision/CollisionDetection.h b/src/collision/CollisionDetection.h index d5c585e6..75f278ba 100644 --- a/src/collision/CollisionDetection.h +++ b/src/collision/CollisionDetection.h @@ -67,7 +67,7 @@ class TestCollisionBetweenShapesCallback : public NarrowPhaseCallback { // Called by a narrow-phase collision algorithm when a new contact has been found virtual void notifyContact(OverlappingPair* overlappingPair, - const ContactPointInfo& contactInfo); + const ContactPointInfo& contactInfo) override; }; // Class CollisionDetection @@ -119,12 +119,6 @@ class CollisionDetection : public NarrowPhaseCallback { // -------------------- Methods -------------------- // - /// Private copy-constructor - CollisionDetection(const CollisionDetection& collisionDetection); - - /// Private assignment operator - CollisionDetection& operator=(const CollisionDetection& collisionDetection); - /// Compute the broad-phase collision detection void computeBroadPhase(); @@ -152,7 +146,13 @@ class CollisionDetection : public NarrowPhaseCallback { CollisionDetection(CollisionWorld* world, MemoryAllocator& memoryAllocator); /// Destructor - ~CollisionDetection(); + ~CollisionDetection() = default; + + /// Deleted copy-constructor + CollisionDetection(const CollisionDetection& collisionDetection) = delete; + + /// Deleted assignment operator + CollisionDetection& operator=(const CollisionDetection& collisionDetection) = delete; /// Set the collision dispatch configuration void setCollisionDispatch(CollisionDispatch* collisionDispatch); @@ -223,7 +223,7 @@ class CollisionDetection : public NarrowPhaseCallback { MemoryAllocator& getWorldMemoryAllocator(); /// Called by a narrow-phase collision algorithm when a new contact has been found - virtual void notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo); + virtual void notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo) override; /// Create a new contact void createContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo); @@ -237,7 +237,7 @@ class CollisionDetection : public NarrowPhaseCallback { // Return the Narrow-phase collision detection algorithm to use between two types of shapes inline NarrowPhaseAlgorithm* CollisionDetection::getCollisionAlgorithm(CollisionShapeType shape1Type, CollisionShapeType shape2Type) const { - return mCollisionMatrix[shape1Type][shape2Type]; + return mCollisionMatrix[static_cast(shape1Type)][static_cast(shape2Type)]; } // Set the collision dispatch configuration diff --git a/src/collision/ContactManifold.h b/src/collision/ContactManifold.h index e34bb449..eb7716df 100644 --- a/src/collision/ContactManifold.h +++ b/src/collision/ContactManifold.h @@ -130,12 +130,6 @@ class ContactManifold { // -------------------- Methods -------------------- // - /// Private copy-constructor - ContactManifold(const ContactManifold& contactManifold); - - /// Private assignment operator - ContactManifold& operator=(const ContactManifold& contactManifold); - /// Return the index of maximum area int getMaxArea(decimal area0, decimal area1, decimal area2, decimal area3) const; @@ -162,6 +156,12 @@ class ContactManifold { /// Destructor ~ContactManifold(); + /// Deleted copy-constructor + ContactManifold(const ContactManifold& contactManifold) = delete; + + /// Deleted assignment operator + ContactManifold& operator=(const ContactManifold& contactManifold) = delete; + /// Return a pointer to the first proxy shape of the contact ProxyShape* getShape1() const; diff --git a/src/collision/ProxyShape.cpp b/src/collision/ProxyShape.cpp index 0e416370..50418011 100644 --- a/src/collision/ProxyShape.cpp +++ b/src/collision/ProxyShape.cpp @@ -37,7 +37,7 @@ using namespace reactphysics3d; */ 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), + mNext(nullptr), mBroadPhaseID(-1), mCachedCollisionData(nullptr), mUserData(nullptr), mCollisionCategoryBits(0x0001), mCollideWithMaskBits(0xFFFF) { } @@ -46,7 +46,7 @@ ProxyShape::ProxyShape(CollisionBody* body, CollisionShape* shape, const Transfo ProxyShape::~ProxyShape() { // Release the cached collision data memory - if (mCachedCollisionData != NULL) { + if (mCachedCollisionData != nullptr) { free(mCachedCollisionData); } } diff --git a/src/collision/ProxyShape.h b/src/collision/ProxyShape.h index 810c15e8..d7c81621 100644 --- a/src/collision/ProxyShape.h +++ b/src/collision/ProxyShape.h @@ -85,14 +85,6 @@ class ProxyShape { /// proxy shape will collide with every collision categories by default. unsigned short mCollideWithMaskBits; - // -------------------- Methods -------------------- // - - /// Private copy-constructor - ProxyShape(const ProxyShape& proxyShape); - - /// Private assignment operator - ProxyShape& operator=(const ProxyShape& proxyShape); - public: // -------------------- Methods -------------------- // @@ -104,6 +96,12 @@ class ProxyShape { /// Destructor virtual ~ProxyShape(); + /// Deleted copy-constructor + ProxyShape(const ProxyShape& proxyShape) = delete; + + /// Deleted assignment operator + ProxyShape& operator=(const ProxyShape& proxyShape) = delete; + /// Return the collision shape const CollisionShape* getCollisionShape() const; diff --git a/src/collision/RaycastInfo.h b/src/collision/RaycastInfo.h index 1b86de54..06510e04 100644 --- a/src/collision/RaycastInfo.h +++ b/src/collision/RaycastInfo.h @@ -46,14 +46,6 @@ struct RaycastInfo { private: - // -------------------- Methods -------------------- // - - /// Private copy constructor - RaycastInfo(const RaycastInfo& raycastInfo); - - /// Private assignment operator - RaycastInfo& operator=(const RaycastInfo& raycastInfo); - public: // -------------------- Attributes -------------------- // @@ -83,14 +75,18 @@ struct RaycastInfo { // -------------------- Methods -------------------- // /// Constructor - RaycastInfo() : meshSubpart(-1), triangleIndex(-1), body(NULL), proxyShape(NULL) { + RaycastInfo() : meshSubpart(-1), triangleIndex(-1), body(nullptr), proxyShape(nullptr) { } /// Destructor - ~RaycastInfo() { + ~RaycastInfo() = default; - } + /// Deleted copy constructor + RaycastInfo(const RaycastInfo& raycastInfo) = delete; + + /// Deleted assignment operator + RaycastInfo& operator=(const RaycastInfo& raycastInfo) = delete; }; // Class RaycastCallback diff --git a/src/collision/TriangleMesh.cpp b/src/collision/TriangleMesh.cpp index 5439b3f3..3fdc48c5 100644 --- a/src/collision/TriangleMesh.cpp +++ b/src/collision/TriangleMesh.cpp @@ -27,13 +27,3 @@ #include "TriangleMesh.h" using namespace reactphysics3d; - -// Constructor -TriangleMesh::TriangleMesh() { - -} - -// Destructor -TriangleMesh::~TriangleMesh() { - -} diff --git a/src/collision/TriangleMesh.h b/src/collision/TriangleMesh.h index 52dabbe7..936824e9 100644 --- a/src/collision/TriangleMesh.h +++ b/src/collision/TriangleMesh.h @@ -51,10 +51,10 @@ class TriangleMesh { public: /// Constructor - TriangleMesh(); + TriangleMesh() = default; /// Destructor - ~TriangleMesh(); + ~TriangleMesh() = default; /// Add a subpart of the mesh void addSubpart(TriangleVertexArray* triangleVertexArray); diff --git a/src/collision/TriangleVertexArray.cpp b/src/collision/TriangleVertexArray.cpp index f1808a3c..883b0ab7 100644 --- a/src/collision/TriangleVertexArray.cpp +++ b/src/collision/TriangleVertexArray.cpp @@ -54,8 +54,3 @@ TriangleVertexArray::TriangleVertexArray(uint nbVertices, void* verticesStart, i mVertexDataType = vertexDataType; mIndexDataType = indexDataType; } - -// Destructor -TriangleVertexArray::~TriangleVertexArray() { - -} diff --git a/src/collision/TriangleVertexArray.h b/src/collision/TriangleVertexArray.h index 3cf45723..8e434919 100644 --- a/src/collision/TriangleVertexArray.h +++ b/src/collision/TriangleVertexArray.h @@ -46,10 +46,10 @@ class TriangleVertexArray { public: /// Data type for the vertices in the array - enum VertexDataType {VERTEX_FLOAT_TYPE, VERTEX_DOUBLE_TYPE}; + enum class VertexDataType {VERTEX_FLOAT_TYPE, VERTEX_DOUBLE_TYPE}; /// Data type for the indices in the array - enum IndexDataType {INDEX_INTEGER_TYPE, INDEX_SHORT_TYPE}; + enum class IndexDataType {INDEX_INTEGER_TYPE, INDEX_SHORT_TYPE}; protected: @@ -87,7 +87,7 @@ class TriangleVertexArray { VertexDataType vertexDataType, IndexDataType indexDataType); /// Destructor - ~TriangleVertexArray(); + ~TriangleVertexArray() = default; /// Return the vertex data type VertexDataType getVertexDataType() const; diff --git a/src/collision/broadphase/BroadPhaseAlgorithm.cpp b/src/collision/broadphase/BroadPhaseAlgorithm.cpp index cfb6acd8..781273e5 100644 --- a/src/collision/broadphase/BroadPhaseAlgorithm.cpp +++ b/src/collision/broadphase/BroadPhaseAlgorithm.cpp @@ -39,11 +39,11 @@ BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection) // Allocate memory for the array of non-static proxy shapes IDs mMovedShapes = (int*) malloc(mNbAllocatedMovedShapes * sizeof(int)); - assert(mMovedShapes != NULL); + assert(mMovedShapes != nullptr); // Allocate memory for the array of potential overlapping pairs mPotentialPairs = (BroadPhasePair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair)); - assert(mPotentialPairs != NULL); + assert(mPotentialPairs != nullptr); } // Destructor @@ -65,14 +65,14 @@ void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) { mNbAllocatedMovedShapes *= 2; int* oldArray = mMovedShapes; mMovedShapes = (int*) malloc(mNbAllocatedMovedShapes * sizeof(int)); - assert(mMovedShapes != NULL); + assert(mMovedShapes != nullptr); memcpy(mMovedShapes, oldArray, mNbMovedShapes * sizeof(int)); free(oldArray); } // Store the broad-phase ID into the array of shapes that have moved assert(mNbMovedShapes < mNbAllocatedMovedShapes); - assert(mMovedShapes != NULL); + assert(mMovedShapes != nullptr); mMovedShapes[mNbMovedShapes] = broadPhaseID; mNbMovedShapes++; } @@ -91,7 +91,7 @@ void BroadPhaseAlgorithm::removeMovedCollisionShape(int broadPhaseID) { mNbAllocatedMovedShapes /= 2; int* oldArray = mMovedShapes; mMovedShapes = (int*) malloc(mNbAllocatedMovedShapes * sizeof(int)); - assert(mMovedShapes != NULL); + assert(mMovedShapes != nullptr); uint nbElements = 0; for (uint i=0; igetType()); // If there is no collision algorithm between those two kinds of shapes - if (algo == NULL) return; + if (algo == nullptr) return; // Notify the narrow-phase algorithm about the overlapping pair we are going to test algo->setCurrentOverlappingPair(mOverlappingPair); @@ -263,8 +253,8 @@ void SmoothCollisionNarrowPhaseCallback::notifyContact(OverlappingPair* overlapp bool isFirstShapeTriangle; // If the collision shape 1 is the triangle - if (contactInfo.collisionShape1->getType() == TRIANGLE) { - assert(contactInfo.collisionShape2->getType() != TRIANGLE); + if (contactInfo.collisionShape1->getType() == CollisionShapeType::TRIANGLE) { + assert(contactInfo.collisionShape2->getType() != CollisionShapeType::TRIANGLE); const TriangleShape* triangleShape = static_cast(contactInfo.collisionShape1); triangleVertices[0] = triangleShape->getVertex(0); @@ -274,7 +264,7 @@ void SmoothCollisionNarrowPhaseCallback::notifyContact(OverlappingPair* overlapp isFirstShapeTriangle = true; } else { // If the collision shape 2 is the triangle - assert(contactInfo.collisionShape2->getType() == TRIANGLE); + assert(contactInfo.collisionShape2->getType() == CollisionShapeType::TRIANGLE); const TriangleShape* triangleShape = static_cast(contactInfo.collisionShape2); triangleVertices[0] = triangleShape->getVertex(0); diff --git a/src/collision/narrowphase/ConcaveVsConvexAlgorithm.h b/src/collision/narrowphase/ConcaveVsConvexAlgorithm.h index e44b71c2..bcd4ef8f 100644 --- a/src/collision/narrowphase/ConcaveVsConvexAlgorithm.h +++ b/src/collision/narrowphase/ConcaveVsConvexAlgorithm.h @@ -72,6 +72,9 @@ class ConvexVsTriangleCallback : public TriangleCallback { public: + /// Destructor + virtual ~ConvexVsTriangleCallback() override = default; + /// Set the collision detection pointer void setCollisionDetection(CollisionDetection* collisionDetection) { mCollisionDetection = collisionDetection; @@ -104,7 +107,7 @@ class ConvexVsTriangleCallback : public TriangleCallback { } /// Test collision between a triangle and the convex mesh shape - virtual void testTriangle(const Vector3* trianglePoints); + virtual void testTriangle(const Vector3* trianglePoints) override; }; // Class SmoothMeshContactInfo @@ -169,7 +172,7 @@ class SmoothCollisionNarrowPhaseCallback : public NarrowPhaseCallback { /// Called by a narrow-phase collision algorithm when a new contact has been found virtual void notifyContact(OverlappingPair* overlappingPair, - const ContactPointInfo& contactInfo); + const ContactPointInfo& contactInfo) override; }; @@ -188,12 +191,6 @@ class ConcaveVsConvexAlgorithm : public NarrowPhaseAlgorithm { // -------------------- Methods -------------------- // - /// Private copy-constructor - ConcaveVsConvexAlgorithm(const ConcaveVsConvexAlgorithm& algorithm); - - /// Private assignment operator - ConcaveVsConvexAlgorithm& operator=(const ConcaveVsConvexAlgorithm& algorithm); - /// Process the concave triangle mesh collision using the smooth mesh collision algorithm void processSmoothMeshCollision(OverlappingPair* overlappingPair, std::vector contactPoints, @@ -212,15 +209,21 @@ class ConcaveVsConvexAlgorithm : public NarrowPhaseAlgorithm { // -------------------- Methods -------------------- // /// Constructor - ConcaveVsConvexAlgorithm(); + ConcaveVsConvexAlgorithm() = default; /// Destructor - virtual ~ConcaveVsConvexAlgorithm(); + virtual ~ConcaveVsConvexAlgorithm() override = default; + + /// Private copy-constructor + ConcaveVsConvexAlgorithm(const ConcaveVsConvexAlgorithm& algorithm) = delete; + + /// Private assignment operator + ConcaveVsConvexAlgorithm& operator=(const ConcaveVsConvexAlgorithm& algorithm) = delete; /// Compute a contact info if the two bounding volume collide virtual void testCollision(const CollisionShapeInfo& shape1Info, const CollisionShapeInfo& shape2Info, - NarrowPhaseCallback* narrowPhaseCallback); + NarrowPhaseCallback* narrowPhaseCallback) override; }; // Add a triangle vertex into the set of processed triangles diff --git a/src/collision/narrowphase/DefaultCollisionDispatch.cpp b/src/collision/narrowphase/DefaultCollisionDispatch.cpp index 8e3f6930..109b5de3 100644 --- a/src/collision/narrowphase/DefaultCollisionDispatch.cpp +++ b/src/collision/narrowphase/DefaultCollisionDispatch.cpp @@ -29,16 +29,6 @@ using namespace reactphysics3d; -// Constructor -DefaultCollisionDispatch::DefaultCollisionDispatch() { - -} - -// Destructor -DefaultCollisionDispatch::~DefaultCollisionDispatch() { - -} - /// Initialize the collision dispatch configuration void DefaultCollisionDispatch::init(CollisionDetection* collisionDetection, MemoryAllocator* memoryAllocator) { @@ -57,7 +47,7 @@ NarrowPhaseAlgorithm* DefaultCollisionDispatch::selectAlgorithm(int type1, int t CollisionShapeType shape2Type = static_cast(type2); // Sphere vs Sphere algorithm - if (shape1Type == SPHERE && shape2Type == SPHERE) { + if (shape1Type == CollisionShapeType::SPHERE && shape2Type == CollisionShapeType::SPHERE) { return &mSphereVsSphereAlgorithm; } // Concave vs Convex algorithm @@ -70,6 +60,6 @@ NarrowPhaseAlgorithm* DefaultCollisionDispatch::selectAlgorithm(int type1, int t return &mGJKAlgorithm; } else { - return NULL; + return nullptr; } } diff --git a/src/collision/narrowphase/DefaultCollisionDispatch.h b/src/collision/narrowphase/DefaultCollisionDispatch.h index 6a3fb167..9bf15b11 100644 --- a/src/collision/narrowphase/DefaultCollisionDispatch.h +++ b/src/collision/narrowphase/DefaultCollisionDispatch.h @@ -56,18 +56,18 @@ class DefaultCollisionDispatch : public CollisionDispatch { public: /// Constructor - DefaultCollisionDispatch(); + DefaultCollisionDispatch() = default; /// Destructor - virtual ~DefaultCollisionDispatch(); + virtual ~DefaultCollisionDispatch() override = default; /// Initialize the collision dispatch configuration virtual void init(CollisionDetection* collisionDetection, - MemoryAllocator* memoryAllocator); + MemoryAllocator* memoryAllocator) override; /// Select and return the narrow-phase collision detection algorithm to /// use between two types of collision shapes. - virtual NarrowPhaseAlgorithm* selectAlgorithm(int type1, int type2); + virtual NarrowPhaseAlgorithm* selectAlgorithm(int type1, int type2) override; }; } diff --git a/src/collision/narrowphase/EPA/EPAAlgorithm.cpp b/src/collision/narrowphase/EPA/EPAAlgorithm.cpp index 6c94ed5a..6fc19680 100644 --- a/src/collision/narrowphase/EPA/EPAAlgorithm.cpp +++ b/src/collision/narrowphase/EPA/EPAAlgorithm.cpp @@ -32,16 +32,6 @@ // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; -// Constructor -EPAAlgorithm::EPAAlgorithm() { - -} - -// Destructor -EPAAlgorithm::~EPAAlgorithm() { - -} - // Decide if the origin is in the tetrahedron. /// Return 0 if the origin is in the tetrahedron and return the number (1,2,3 or 4) of /// the vertex that is wrong if the origin is not in the tetrahedron @@ -234,7 +224,7 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const VoronoiSimplex& TriangleEPA* face3 = triangleStore.newTriangle(points, 1, 3, 2); // If the constructed tetrahedron is not correct - if (!((face0 != NULL) && (face1 != NULL) && (face2 != NULL) && (face3 != NULL) + if (!((face0 != nullptr) && (face1 != nullptr) && (face2 != nullptr) && (face3 != nullptr) && face0->getDistSquare() > 0.0 && face1->getDistSquare() > 0.0 && face2->getDistSquare() > 0.0 && face3->getDistSquare() > 0.0)) { return false; @@ -292,10 +282,10 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const VoronoiSimplex& shape2->getLocalSupportPointWithMargin(rotateToBody2 * n, shape2CachedCollisionData); points[4] = suppPointsA[4] - suppPointsB[4]; - TriangleEPA* face0 = NULL; - TriangleEPA* face1 = NULL; - TriangleEPA* face2 = NULL; - TriangleEPA* face3 = NULL; + TriangleEPA* face0 = nullptr; + TriangleEPA* face1 = nullptr; + TriangleEPA* face2 = nullptr; + TriangleEPA* face3 = nullptr; // If the origin is in the first tetrahedron if (isOriginInTetrahedron(points[0], points[1], @@ -326,7 +316,7 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const VoronoiSimplex& } // If the constructed tetrahedron is not correct - if (!((face0 != NULL) && (face1 != NULL) && (face2 != NULL) && (face3 != NULL) + if (!((face0 != nullptr) && (face1 != nullptr) && (face2 != nullptr) && (face3 != nullptr) && face0->getDistSquare() > 0.0 && face1->getDistSquare() > 0.0 && face2->getDistSquare() > 0.0 && face3->getDistSquare() > 0.0)) { return false; diff --git a/src/collision/narrowphase/EPA/EPAAlgorithm.h b/src/collision/narrowphase/EPA/EPAAlgorithm.h index 377ccc11..f585ac15 100644 --- a/src/collision/narrowphase/EPA/EPAAlgorithm.h +++ b/src/collision/narrowphase/EPA/EPAAlgorithm.h @@ -43,10 +43,10 @@ namespace reactphysics3d { // ---------- Constants ---------- // /// Maximum number of support points of the polytope -const unsigned int MAX_SUPPORT_POINTS = 100; +constexpr unsigned int MAX_SUPPORT_POINTS = 100; /// Maximum number of facets of the polytope -const unsigned int MAX_FACETS = 200; +constexpr unsigned int MAX_FACETS = 200; // Class TriangleComparison @@ -95,12 +95,6 @@ class EPAAlgorithm { // -------------------- Methods -------------------- // - /// Private copy-constructor - EPAAlgorithm(const EPAAlgorithm& algorithm); - - /// Private assignment operator - EPAAlgorithm& operator=(const EPAAlgorithm& algorithm); - /// Add a triangle face in the candidate triangle heap void addFaceCandidate(TriangleEPA* triangle, TriangleEPA** heap, uint& nbTriangles, decimal upperBoundSquarePenDepth); @@ -114,10 +108,16 @@ class EPAAlgorithm { // -------------------- Methods -------------------- // /// Constructor - EPAAlgorithm(); + EPAAlgorithm() = default; /// Destructor - ~EPAAlgorithm(); + ~EPAAlgorithm() = default; + + /// Deleted copy-constructor + EPAAlgorithm(const EPAAlgorithm& algorithm) = delete; + + /// Deleted assignment operator + EPAAlgorithm& operator=(const EPAAlgorithm& algorithm) = delete; /// Initalize the algorithm void init(MemoryAllocator* memoryAllocator); diff --git a/src/collision/narrowphase/EPA/EdgeEPA.cpp b/src/collision/narrowphase/EPA/EdgeEPA.cpp index d7abbaf6..dcbf61fd 100644 --- a/src/collision/narrowphase/EPA/EdgeEPA.cpp +++ b/src/collision/narrowphase/EPA/EdgeEPA.cpp @@ -32,12 +32,6 @@ // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; - -// Constructor -EdgeEPA::EdgeEPA() { - -} - // Constructor EdgeEPA::EdgeEPA(TriangleEPA* ownerTriangle, int index) : mOwnerTriangle(ownerTriangle), mIndex(index) { @@ -50,11 +44,6 @@ EdgeEPA::EdgeEPA(const EdgeEPA& edge) { mIndex = edge.mIndex; } -// Destructor -EdgeEPA::~EdgeEPA() { - -} - // Return the index of the source vertex of the edge (vertex starting the edge) uint EdgeEPA::getSourceVertexIndex() const { return (*mOwnerTriangle)[mIndex]; @@ -78,7 +67,7 @@ bool EdgeEPA::computeSilhouette(const Vector3* vertices, uint indexNewVertex, getSourceVertexIndex()); // If the triangle has been created - if (triangle != NULL) { + if (triangle != nullptr) { halfLink(EdgeEPA(triangle, 1), *this); return true; } @@ -103,7 +92,7 @@ bool EdgeEPA::computeSilhouette(const Vector3* vertices, uint indexNewVertex, getSourceVertexIndex()); // If the triangle has been created - if (triangle != NULL) { + if (triangle != nullptr) { halfLink(EdgeEPA(triangle, 1), *this); return true; } @@ -122,7 +111,7 @@ bool EdgeEPA::computeSilhouette(const Vector3* vertices, uint indexNewVertex, getTargetVertexIndex(), getSourceVertexIndex()); - if (triangle != NULL) { + if (triangle != nullptr) { halfLink(EdgeEPA(triangle, 1), *this); return true; } diff --git a/src/collision/narrowphase/EPA/EdgeEPA.h b/src/collision/narrowphase/EPA/EdgeEPA.h index ca580919..ba3dcfee 100644 --- a/src/collision/narrowphase/EPA/EdgeEPA.h +++ b/src/collision/narrowphase/EPA/EdgeEPA.h @@ -59,7 +59,7 @@ class EdgeEPA { // -------------------- Methods -------------------- // /// Constructor - EdgeEPA(); + EdgeEPA() = default; /// Constructor EdgeEPA(TriangleEPA* ownerTriangle, int index); @@ -68,7 +68,7 @@ class EdgeEPA { EdgeEPA(const EdgeEPA& edge); /// Destructor - ~EdgeEPA(); + ~EdgeEPA() = default; /// Return the pointer to the owner triangle TriangleEPA* getOwnerTriangle() const; diff --git a/src/collision/narrowphase/EPA/TriangleEPA.cpp b/src/collision/narrowphase/EPA/TriangleEPA.cpp index c4a279a2..c322059f 100644 --- a/src/collision/narrowphase/EPA/TriangleEPA.cpp +++ b/src/collision/narrowphase/EPA/TriangleEPA.cpp @@ -32,11 +32,6 @@ // We use the ReactPhysics3D namespace using namespace reactphysics3d; -// Constructor -TriangleEPA::TriangleEPA() { - -} - // Constructor TriangleEPA::TriangleEPA(uint indexVertex1, uint indexVertex2, uint indexVertex3) : mIsObsolete(false) { @@ -45,11 +40,6 @@ TriangleEPA::TriangleEPA(uint indexVertex1, uint indexVertex2, uint indexVertex3 mIndicesVertices[2] = indexVertex3; } -// Destructor -TriangleEPA::~TriangleEPA() { - -} - // Compute the point v closest to the origin of this triangle bool TriangleEPA::computeClosestPoint(const Vector3* vertices) { const Vector3& p0 = vertices[mIndicesVertices[0]]; diff --git a/src/collision/narrowphase/EPA/TriangleEPA.h b/src/collision/narrowphase/EPA/TriangleEPA.h index e2a8ce26..865c69d4 100644 --- a/src/collision/narrowphase/EPA/TriangleEPA.h +++ b/src/collision/narrowphase/EPA/TriangleEPA.h @@ -74,26 +74,24 @@ class TriangleEPA { /// Square distance of the point closest point v to the origin decimal mDistSquare; - // -------------------- Methods -------------------- // - - /// Private copy-constructor - TriangleEPA(const TriangleEPA& triangle); - - /// Private assignment operator - TriangleEPA& operator=(const TriangleEPA& triangle); - public: // -------------------- Methods -------------------- // /// Constructor - TriangleEPA(); + TriangleEPA() = default; /// Constructor TriangleEPA(uint v1, uint v2, uint v3); /// Destructor - ~TriangleEPA(); + ~TriangleEPA() = default; + + /// Deleted copy-constructor + TriangleEPA(const TriangleEPA& triangle) = delete; + + /// Deleted assignment operator + TriangleEPA& operator=(const TriangleEPA& triangle) = delete; /// Return an adjacent edge of the triangle EdgeEPA& getAdjacentEdge(int index); diff --git a/src/collision/narrowphase/EPA/TrianglesStore.cpp b/src/collision/narrowphase/EPA/TrianglesStore.cpp index ebc214fb..93fb95a6 100644 --- a/src/collision/narrowphase/EPA/TrianglesStore.cpp +++ b/src/collision/narrowphase/EPA/TrianglesStore.cpp @@ -33,8 +33,3 @@ using namespace reactphysics3d; TrianglesStore::TrianglesStore() : mNbTriangles(0) { } - -// Destructor -TrianglesStore::~TrianglesStore() { - -} diff --git a/src/collision/narrowphase/EPA/TrianglesStore.h b/src/collision/narrowphase/EPA/TrianglesStore.h index b207eb77..d21ccd35 100644 --- a/src/collision/narrowphase/EPA/TrianglesStore.h +++ b/src/collision/narrowphase/EPA/TrianglesStore.h @@ -36,7 +36,7 @@ namespace reactphysics3d { // Constants -const unsigned int MAX_TRIANGLES = 200; // Maximum number of triangles +constexpr unsigned int MAX_TRIANGLES = 200; // Maximum number of triangles // Class TriangleStore /** @@ -52,15 +52,7 @@ class TrianglesStore { TriangleEPA mTriangles[MAX_TRIANGLES]; /// Number of triangles - int mNbTriangles; - - // -------------------- Methods -------------------- // - - /// Private copy-constructor - TrianglesStore(const TrianglesStore& triangleStore); - - /// Private assignment operator - TrianglesStore& operator=(const TrianglesStore& triangleStore); + int mNbTriangles; public: @@ -70,7 +62,13 @@ class TrianglesStore { TrianglesStore(); /// Destructor - ~TrianglesStore(); + ~TrianglesStore() = default; + + /// Deleted copy-constructor + TrianglesStore(const TrianglesStore& triangleStore) = delete; + + /// Deleted assignment operator + TrianglesStore& operator=(const TrianglesStore& triangleStore) = delete; /// Clear all the storage void clear(); @@ -115,7 +113,7 @@ inline TriangleEPA& TrianglesStore::last() { // Create a new triangle inline TriangleEPA* TrianglesStore::newTriangle(const Vector3* vertices, uint v0,uint v1, uint v2) { - TriangleEPA* newTriangle = NULL; + TriangleEPA* newTriangle = nullptr; // If we have not reached the maximum number of triangles if (mNbTriangles != MAX_TRIANGLES) { @@ -123,7 +121,7 @@ inline TriangleEPA* TrianglesStore::newTriangle(const Vector3* vertices, new (newTriangle) TriangleEPA(v0, v1, v2); if (!newTriangle->computeClosestPoint(vertices)) { mNbTriangles--; - newTriangle = NULL; + newTriangle = nullptr; } } diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp index 89c4f459..b7916a53 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp @@ -41,11 +41,6 @@ GJKAlgorithm::GJKAlgorithm() : NarrowPhaseAlgorithm() { } -// Destructor -GJKAlgorithm::~GJKAlgorithm() { - -} - // Compute a contact info if the two collision shapes collide. /// This method implements the Hybrid Technique for computing the penetration depth by /// running the GJK algorithm on original objects (without margin). If the shapes intersect diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.h b/src/collision/narrowphase/GJK/GJKAlgorithm.h index 8617a002..e81ee9b3 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.h +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.h @@ -37,9 +37,9 @@ namespace reactphysics3d { // Constants -const decimal REL_ERROR = decimal(1.0e-3); -const decimal REL_ERROR_SQUARE = REL_ERROR * REL_ERROR; -const int MAX_ITERATIONS_GJK_RAYCAST = 32; +constexpr decimal REL_ERROR = decimal(1.0e-3); +constexpr decimal REL_ERROR_SQUARE = REL_ERROR * REL_ERROR; +constexpr int MAX_ITERATIONS_GJK_RAYCAST = 32; // Class GJKAlgorithm /** @@ -68,12 +68,6 @@ class GJKAlgorithm : public NarrowPhaseAlgorithm { // -------------------- Methods -------------------- // - /// Private copy-constructor - GJKAlgorithm(const GJKAlgorithm& algorithm); - - /// Private assignment operator - GJKAlgorithm& operator=(const GJKAlgorithm& algorithm); - /// Compute the penetration depth for enlarged objects. bool computePenetrationDepthForEnlargedObjects(const CollisionShapeInfo& shape1Info, const Transform& transform1, @@ -90,16 +84,22 @@ class GJKAlgorithm : public NarrowPhaseAlgorithm { GJKAlgorithm(); /// Destructor - ~GJKAlgorithm(); + ~GJKAlgorithm() = default; + + /// Deleted copy-constructor + GJKAlgorithm(const GJKAlgorithm& algorithm) = delete; + + /// Deleted assignment operator + GJKAlgorithm& operator=(const GJKAlgorithm& algorithm) = delete; /// Initalize the algorithm virtual void init(CollisionDetection* collisionDetection, - MemoryAllocator* memoryAllocator); + MemoryAllocator* memoryAllocator) override; /// Compute a contact info if the two bounding volumes collide. virtual void testCollision(const CollisionShapeInfo& shape1Info, const CollisionShapeInfo& shape2Info, - NarrowPhaseCallback* narrowPhaseCallback); + NarrowPhaseCallback* narrowPhaseCallback) override; /// Use the GJK Algorithm to find if a point is inside a convex collision shape bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape); diff --git a/src/collision/narrowphase/NarrowPhaseAlgorithm.cpp b/src/collision/narrowphase/NarrowPhaseAlgorithm.cpp index d61d78e9..0fbbe5fe 100644 --- a/src/collision/narrowphase/NarrowPhaseAlgorithm.cpp +++ b/src/collision/narrowphase/NarrowPhaseAlgorithm.cpp @@ -31,12 +31,7 @@ using namespace reactphysics3d; // Constructor NarrowPhaseAlgorithm::NarrowPhaseAlgorithm() - : mMemoryAllocator(NULL), mCurrentOverlappingPair(NULL) { - -} - -// Destructor -NarrowPhaseAlgorithm::~NarrowPhaseAlgorithm() { + : mMemoryAllocator(nullptr), mCurrentOverlappingPair(nullptr) { } diff --git a/src/collision/narrowphase/NarrowPhaseAlgorithm.h b/src/collision/narrowphase/NarrowPhaseAlgorithm.h index e8efaaa6..30b216f0 100644 --- a/src/collision/narrowphase/NarrowPhaseAlgorithm.h +++ b/src/collision/narrowphase/NarrowPhaseAlgorithm.h @@ -47,6 +47,8 @@ class NarrowPhaseCallback { public: + virtual ~NarrowPhaseCallback() = default; + /// Called by a narrow-phase collision algorithm when a new contact has been found virtual void notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo)=0; @@ -73,14 +75,6 @@ class NarrowPhaseAlgorithm { /// Overlapping pair of the bodies currently tested for collision OverlappingPair* mCurrentOverlappingPair; - - // -------------------- Methods -------------------- // - - /// Private copy-constructor - NarrowPhaseAlgorithm(const NarrowPhaseAlgorithm& algorithm); - - /// Private assignment operator - NarrowPhaseAlgorithm& operator=(const NarrowPhaseAlgorithm& algorithm); public : @@ -90,7 +84,13 @@ class NarrowPhaseAlgorithm { NarrowPhaseAlgorithm(); /// Destructor - virtual ~NarrowPhaseAlgorithm(); + virtual ~NarrowPhaseAlgorithm() = default; + + /// Deleted copy-constructor + NarrowPhaseAlgorithm(const NarrowPhaseAlgorithm& algorithm) = delete; + + /// Deleted assignment operator + NarrowPhaseAlgorithm& operator=(const NarrowPhaseAlgorithm& algorithm) = delete; /// Initalize the algorithm virtual void init(CollisionDetection* collisionDetection, MemoryAllocator* memoryAllocator); diff --git a/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp b/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp index 89e2987e..9d2c4baa 100644 --- a/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp @@ -28,17 +28,7 @@ #include "collision/shapes/SphereShape.h" // We want to use the ReactPhysics3D namespace -using namespace reactphysics3d; - -// Constructor -SphereVsSphereAlgorithm::SphereVsSphereAlgorithm() : NarrowPhaseAlgorithm() { - -} - -// Destructor -SphereVsSphereAlgorithm::~SphereVsSphereAlgorithm() { - -} +using namespace reactphysics3d; void SphereVsSphereAlgorithm::testCollision(const CollisionShapeInfo& shape1Info, const CollisionShapeInfo& shape2Info, diff --git a/src/collision/narrowphase/SphereVsSphereAlgorithm.h b/src/collision/narrowphase/SphereVsSphereAlgorithm.h index 0c73d57a..525c55d5 100644 --- a/src/collision/narrowphase/SphereVsSphereAlgorithm.h +++ b/src/collision/narrowphase/SphereVsSphereAlgorithm.h @@ -44,28 +44,26 @@ class SphereVsSphereAlgorithm : public NarrowPhaseAlgorithm { protected : - // -------------------- Methods -------------------- // - - /// Private copy-constructor - SphereVsSphereAlgorithm(const SphereVsSphereAlgorithm& algorithm); - - /// Private assignment operator - SphereVsSphereAlgorithm& operator=(const SphereVsSphereAlgorithm& algorithm); - public : // -------------------- Methods -------------------- // /// Constructor - SphereVsSphereAlgorithm(); + SphereVsSphereAlgorithm() = default; /// Destructor - virtual ~SphereVsSphereAlgorithm(); + virtual ~SphereVsSphereAlgorithm() override = default; + + /// Deleted copy-constructor + SphereVsSphereAlgorithm(const SphereVsSphereAlgorithm& algorithm) = delete; + + /// Deleted assignment operator + SphereVsSphereAlgorithm& operator=(const SphereVsSphereAlgorithm& algorithm) = delete; /// Compute a contact info if the two bounding volume collide virtual void testCollision(const CollisionShapeInfo& shape1Info, const CollisionShapeInfo& shape2Info, - NarrowPhaseCallback* narrowPhaseCallback); + NarrowPhaseCallback* narrowPhaseCallback) override; }; } diff --git a/src/collision/shapes/AABB.cpp b/src/collision/shapes/AABB.cpp index 0e18eebd..6c43aeb6 100644 --- a/src/collision/shapes/AABB.cpp +++ b/src/collision/shapes/AABB.cpp @@ -31,11 +31,6 @@ using namespace reactphysics3d; using namespace std; -// Constructor -AABB::AABB() { - -} - // Constructor AABB::AABB(const Vector3& minCoordinates, const Vector3& maxCoordinates) :mMinCoordinates(minCoordinates), mMaxCoordinates(maxCoordinates) { @@ -48,11 +43,6 @@ AABB::AABB(const AABB& aabb) } -// Destructor -AABB::~AABB() { - -} - // Merge the AABB in parameter with the current one void AABB::mergeWithAABB(const AABB& aabb) { mMinCoordinates.x = std::min(mMinCoordinates.x, aabb.mMinCoordinates.x); diff --git a/src/collision/shapes/AABB.h b/src/collision/shapes/AABB.h index 364dfc83..8683db55 100644 --- a/src/collision/shapes/AABB.h +++ b/src/collision/shapes/AABB.h @@ -56,7 +56,7 @@ class AABB { // -------------------- Methods -------------------- // /// Constructor - AABB(); + AABB() = default; /// Constructor AABB(const Vector3& minCoordinates, const Vector3& maxCoordinates); @@ -65,7 +65,7 @@ class AABB { AABB(const AABB& aabb); /// Destructor - ~AABB(); + ~AABB() = default; /// Return the center point Vector3 getCenter() const; diff --git a/src/collision/shapes/BoxShape.cpp b/src/collision/shapes/BoxShape.cpp index fe1f5693..ce3197e3 100644 --- a/src/collision/shapes/BoxShape.cpp +++ b/src/collision/shapes/BoxShape.cpp @@ -38,17 +38,12 @@ using namespace reactphysics3d; * @param margin The collision margin (in meters) around the collision shape */ BoxShape::BoxShape(const Vector3& extent, decimal margin) - : ConvexShape(BOX, margin), mExtent(extent - Vector3(margin, margin, margin)) { + : ConvexShape(CollisionShapeType::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); } -// Destructor -BoxShape::~BoxShape() { - -} - // Return the local inertia tensor of the collision shape /** * @param[out] tensor The 3x3 inertia tensor matrix of the shape in local-space diff --git a/src/collision/shapes/BoxShape.h b/src/collision/shapes/BoxShape.h index bda4bf3f..2d0fef75 100644 --- a/src/collision/shapes/BoxShape.h +++ b/src/collision/shapes/BoxShape.h @@ -61,24 +61,18 @@ class BoxShape : public ConvexShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - BoxShape(const BoxShape& shape); - - /// Private assignment operator - BoxShape& operator=(const BoxShape& shape); - /// Return a local support point in a given direction without the object margin virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const; + void** cachedCollisionData) const override; /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const; + virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override; /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; public : @@ -88,22 +82,28 @@ class BoxShape : public ConvexShape { BoxShape(const Vector3& extent, decimal margin = OBJECT_MARGIN); /// Destructor - virtual ~BoxShape(); + virtual ~BoxShape() override = default; + + /// Deleted copy-constructor + BoxShape(const BoxShape& shape) = delete; + + /// Deleted assignment operator + BoxShape& operator=(const BoxShape& shape) = delete; /// Return the extents of the box Vector3 getExtent() const; /// Set the scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return the local bounds of the shape in x, y and z directions - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Return true if the collision shape is a polyhedron virtual bool isPolyhedron() const; /// Return the local inertia tensor of the collision shape - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; }; // Return the extents of the box diff --git a/src/collision/shapes/CapsuleShape.cpp b/src/collision/shapes/CapsuleShape.cpp index 110fbd30..f9f442ce 100644 --- a/src/collision/shapes/CapsuleShape.cpp +++ b/src/collision/shapes/CapsuleShape.cpp @@ -37,16 +37,11 @@ using namespace reactphysics3d; * @param height The height of the capsule (in meters) */ CapsuleShape::CapsuleShape(decimal radius, decimal height) - : ConvexShape(CAPSULE, radius), mHalfHeight(height * decimal(0.5)) { + : ConvexShape(CollisionShapeType::CAPSULE, radius), mHalfHeight(height * decimal(0.5)) { assert(radius > decimal(0.0)); assert(height > decimal(0.0)); } -// Destructor -CapsuleShape::~CapsuleShape() { - -} - // Return the local inertia tensor of the capsule /** * @param[out] tensor The 3x3 inertia tensor matrix of the shape in local-space diff --git a/src/collision/shapes/CapsuleShape.h b/src/collision/shapes/CapsuleShape.h index 8e77f050..542fb12f 100644 --- a/src/collision/shapes/CapsuleShape.h +++ b/src/collision/shapes/CapsuleShape.h @@ -55,21 +55,15 @@ class CapsuleShape : public ConvexShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - CapsuleShape(const CapsuleShape& shape); - - /// Private assignment operator - CapsuleShape& operator=(const CapsuleShape& shape); - /// Return a local support point in a given direction without the object margin virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const; + void** cachedCollisionData) const override; /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const; + virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override; /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override; /// Raycasting method between a ray one of the two spheres end cap of the capsule bool raycastWithSphereEndCap(const Vector3& point1, const Vector3& point2, @@ -77,7 +71,7 @@ class CapsuleShape : public ConvexShape { Vector3& hitLocalPoint, decimal& hitFraction) const; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; public : @@ -87,7 +81,13 @@ class CapsuleShape : public ConvexShape { CapsuleShape(decimal radius, decimal height); /// Destructor - virtual ~CapsuleShape(); + virtual ~CapsuleShape() override = default; + + /// Deleted copy-constructor + CapsuleShape(const CapsuleShape& shape) = delete; + + /// Deleted assignment operator + CapsuleShape& operator=(const CapsuleShape& shape) = delete; /// Return the radius of the capsule decimal getRadius() const; @@ -96,16 +96,16 @@ class CapsuleShape : public ConvexShape { decimal getHeight() const; /// Set the scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return the local bounds of the shape in x, y and z directions - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Return true if the collision shape is a polyhedron virtual bool isPolyhedron() const; /// Return the local inertia tensor of the collision shape - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; }; // Get the radius of the capsule diff --git a/src/collision/shapes/CollisionShape.cpp b/src/collision/shapes/CollisionShape.cpp index b71c9467..301c97d2 100644 --- a/src/collision/shapes/CollisionShape.cpp +++ b/src/collision/shapes/CollisionShape.cpp @@ -36,11 +36,6 @@ CollisionShape::CollisionShape(CollisionShapeType type) : mType(type), mScaling( } -// Destructor -CollisionShape::~CollisionShape() { - -} - // Compute the world-space AABB of the collision shape given a transform /** * @param[out] aabb The axis-aligned bounding box (AABB) of the collision shape diff --git a/src/collision/shapes/CollisionShape.h b/src/collision/shapes/CollisionShape.h index 80419c03..1e2e3f14 100644 --- a/src/collision/shapes/CollisionShape.h +++ b/src/collision/shapes/CollisionShape.h @@ -40,7 +40,7 @@ namespace reactphysics3d { /// Type of the collision shape -enum CollisionShapeType {TRIANGLE, BOX, SPHERE, CONE, CYLINDER, +enum class CollisionShapeType {TRIANGLE, BOX, SPHERE, CONE, CYLINDER, CAPSULE, CONVEX_MESH, CONCAVE_MESH, HEIGHTFIELD}; const int NB_COLLISION_SHAPE_TYPES = 9; @@ -67,12 +67,6 @@ class CollisionShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - CollisionShape(const CollisionShape& shape); - - /// Private assignment operator - CollisionShape& operator=(const CollisionShape& shape); - /// Return true if a point is inside the collision shape virtual bool testPointInside(const Vector3& worldPoint, ProxyShape* proxyShape) const=0; @@ -90,7 +84,13 @@ class CollisionShape { CollisionShape(CollisionShapeType type); /// Destructor - virtual ~CollisionShape(); + virtual ~CollisionShape() = default; + + /// Deleted copy-constructor + CollisionShape(const CollisionShape& shape) = delete; + + /// Deleted assignment operator + CollisionShape& operator=(const CollisionShape& shape) = delete; /// Return the type of the collision shapes CollisionShapeType getType() const; @@ -139,7 +139,7 @@ inline CollisionShapeType CollisionShape::getType() const { // Return true if the collision shape type is a convex shape inline bool CollisionShape::isConvex(CollisionShapeType shapeType) { - return shapeType != CONCAVE_MESH && shapeType != HEIGHTFIELD; + return shapeType != CollisionShapeType::CONCAVE_MESH && shapeType != CollisionShapeType::HEIGHTFIELD; } // Return the scaling vector of the collision shape diff --git a/src/collision/shapes/ConcaveMeshShape.cpp b/src/collision/shapes/ConcaveMeshShape.cpp index 317a1c65..a0bd1094 100644 --- a/src/collision/shapes/ConcaveMeshShape.cpp +++ b/src/collision/shapes/ConcaveMeshShape.cpp @@ -30,19 +30,14 @@ using namespace reactphysics3d; // Constructor ConcaveMeshShape::ConcaveMeshShape(TriangleMesh* triangleMesh) - : ConcaveShape(CONCAVE_MESH) { + : ConcaveShape(CollisionShapeType::CONCAVE_MESH) { mTriangleMesh = triangleMesh; - mRaycastTestType = FRONT; + mRaycastTestType = TriangleRaycastSide::FRONT; // Insert all the triangles into the dynamic AABB tree initBVHTree(); } -// Destructor -ConcaveMeshShape::~ConcaveMeshShape() { - -} - // Insert all the triangles into the dynamic AABB tree void ConcaveMeshShape::initBVHTree() { @@ -72,10 +67,10 @@ void ConcaveMeshShape::initBVHTree() { // Get the index of the current vertex in the triangle int vertexIndex = 0; - if (indexType == TriangleVertexArray::INDEX_INTEGER_TYPE) { + if (indexType == TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE) { vertexIndex = ((uint*)vertexIndexPointer)[k]; } - else if (indexType == TriangleVertexArray::INDEX_SHORT_TYPE) { + else if (indexType == TriangleVertexArray::IndexDataType::INDEX_SHORT_TYPE) { vertexIndex = ((unsigned short*)vertexIndexPointer)[k]; } else { @@ -83,13 +78,13 @@ void ConcaveMeshShape::initBVHTree() { } // Get the vertices components of the triangle - if (vertexType == TriangleVertexArray::VERTEX_FLOAT_TYPE) { + if (vertexType == TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE) { const float* vertices = (float*)(verticesStart + vertexIndex * vertexStride); trianglePoints[k][0] = decimal(vertices[0]) * mScaling.x; trianglePoints[k][1] = decimal(vertices[1]) * mScaling.y; trianglePoints[k][2] = decimal(vertices[2]) * mScaling.z; } - else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) { + else if (vertexType == TriangleVertexArray::VertexDataType::VERTEX_DOUBLE_TYPE) { const double* vertices = (double*)(verticesStart + vertexIndex * vertexStride); trianglePoints[k][0] = decimal(vertices[0]) * mScaling.x; trianglePoints[k][1] = decimal(vertices[1]) * mScaling.y; @@ -132,10 +127,10 @@ void ConcaveMeshShape::getTriangleVerticesWithIndexPointer(int32 subPart, int32 // Get the index of the current vertex in the triangle int vertexIndex = 0; - if (indexType == TriangleVertexArray::INDEX_INTEGER_TYPE) { + if (indexType == TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE) { vertexIndex = ((uint*)vertexIndexPointer)[k]; } - else if (indexType == TriangleVertexArray::INDEX_SHORT_TYPE) { + else if (indexType == TriangleVertexArray::IndexDataType::INDEX_SHORT_TYPE) { vertexIndex = ((unsigned short*)vertexIndexPointer)[k]; } else { @@ -143,13 +138,13 @@ void ConcaveMeshShape::getTriangleVerticesWithIndexPointer(int32 subPart, int32 } // Get the vertices components of the triangle - if (vertexType == TriangleVertexArray::VERTEX_FLOAT_TYPE) { + if (vertexType == TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE) { const float* vertices = (float*)(verticesStart + vertexIndex * vertexStride); outTriangleVertices[k][0] = decimal(vertices[0]) * mScaling.x; outTriangleVertices[k][1] = decimal(vertices[1]) * mScaling.y; outTriangleVertices[k][2] = decimal(vertices[2]) * mScaling.z; } - else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) { + else if (vertexType == TriangleVertexArray::VertexDataType::VERTEX_DOUBLE_TYPE) { const double* vertices = (double*)(verticesStart + vertexIndex * vertexStride); outTriangleVertices[k][0] = decimal(vertices[0]) * mScaling.x; outTriangleVertices[k][1] = decimal(vertices[1]) * mScaling.y; diff --git a/src/collision/shapes/ConcaveMeshShape.h b/src/collision/shapes/ConcaveMeshShape.h index 015c8159..83e5103a 100644 --- a/src/collision/shapes/ConcaveMeshShape.h +++ b/src/collision/shapes/ConcaveMeshShape.h @@ -61,7 +61,7 @@ class ConvexTriangleAABBOverlapCallback : public DynamicAABBTreeOverlapCallback // Called when a overlapping node has been found during the call to // DynamicAABBTree:reportAllShapesOverlappingWithAABB() - virtual void notifyOverlappingNode(int nodeId); + virtual void notifyOverlappingNode(int nodeId) override; }; @@ -89,7 +89,7 @@ class ConcaveMeshRaycastCallback : public DynamicAABBTreeRaycastCallback { } /// Collect all the AABB nodes that are hit by the ray in the Dynamic AABB Tree - virtual decimal raycastBroadPhaseShape(int32 nodeId, const Ray& ray); + virtual decimal raycastBroadPhaseShape(int32 nodeId, const Ray& ray) override; /// Raycast all collision shapes that have been collected void raycastTriangles(); @@ -120,17 +120,11 @@ class ConcaveMeshShape : public ConcaveShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - ConcaveMeshShape(const ConcaveMeshShape& shape); - - /// Private assignment operator - ConcaveMeshShape& operator=(const ConcaveMeshShape& shape); - /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; /// Insert all the triangles into the dynamic AABB tree void initBVHTree(); @@ -146,19 +140,25 @@ class ConcaveMeshShape : public ConcaveShape { ConcaveMeshShape(TriangleMesh* triangleMesh); /// Destructor - ~ConcaveMeshShape(); + virtual ~ConcaveMeshShape() = default; + + /// Deleted copy-constructor + ConcaveMeshShape(const ConcaveMeshShape& shape) = delete; + + /// Deleted assignment operator + ConcaveMeshShape& operator=(const ConcaveMeshShape& shape) = delete; /// Return the local bounds of the shape in x, y and z directions. - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Set the local scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return the local inertia tensor of the collision shape - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; /// Use a callback method on all triangles of the concave shape inside a given AABB - virtual void testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const; + virtual void testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const override; // ---------- Friendship ----------- // diff --git a/src/collision/shapes/ConcaveShape.cpp b/src/collision/shapes/ConcaveShape.cpp index 65a0c8b4..3f691468 100644 --- a/src/collision/shapes/ConcaveShape.cpp +++ b/src/collision/shapes/ConcaveShape.cpp @@ -33,11 +33,6 @@ using namespace reactphysics3d; // Constructor ConcaveShape::ConcaveShape(CollisionShapeType type) : CollisionShape(type), mIsSmoothMeshCollisionEnabled(false), - mTriangleMargin(0), mRaycastTestType(FRONT) { - -} - -// Destructor -ConcaveShape::~ConcaveShape() { + mTriangleMargin(0), mRaycastTestType(TriangleRaycastSide::FRONT) { } diff --git a/src/collision/shapes/ConcaveShape.h b/src/collision/shapes/ConcaveShape.h index 9cee92ab..4af49338 100644 --- a/src/collision/shapes/ConcaveShape.h +++ b/src/collision/shapes/ConcaveShape.h @@ -42,6 +42,9 @@ class TriangleCallback { public: + /// Destructor + virtual ~TriangleCallback() = default; + /// Report a triangle virtual void testTriangle(const Vector3* trianglePoints)=0; @@ -70,14 +73,8 @@ class ConcaveShape : public CollisionShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - ConcaveShape(const ConcaveShape& shape); - - /// Private assignment operator - ConcaveShape& operator=(const ConcaveShape& shape); - /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const; + virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override; public : @@ -87,7 +84,13 @@ class ConcaveShape : public CollisionShape { ConcaveShape(CollisionShapeType type); /// Destructor - virtual ~ConcaveShape(); + virtual ~ConcaveShape() override = default; + + /// Deleted copy-constructor + ConcaveShape(const ConcaveShape& shape) = delete; + + /// Deleted assignment operator + ConcaveShape& operator=(const ConcaveShape& shape) = delete; /// Return the triangle margin decimal getTriangleMargin() const; @@ -99,7 +102,7 @@ class ConcaveShape : public CollisionShape { void setRaycastTestType(TriangleRaycastSide testType); /// Return true if the collision shape is convex, false if it is concave - virtual bool isConvex() const; + virtual bool isConvex() const override; /// Return true if the collision shape is a polyhedron virtual bool isPolyhedron() const; diff --git a/src/collision/shapes/ConeShape.cpp b/src/collision/shapes/ConeShape.cpp index 373061d2..4a1ece33 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) - : ConvexShape(CONE, margin), mRadius(radius), mHalfHeight(height * decimal(0.5)) { + : ConvexShape(CollisionShapeType::CONE, margin), mRadius(radius), mHalfHeight(height * decimal(0.5)) { assert(mRadius > decimal(0.0)); assert(mHalfHeight > decimal(0.0)); @@ -46,11 +46,6 @@ ConeShape::ConeShape(decimal radius, decimal height, decimal margin) mSinTheta = mRadius / (sqrt(mRadius * mRadius + height * height)); } -// Destructor -ConeShape::~ConeShape() { - -} - // Return a local support point in a given direction without the object margin Vector3 ConeShape::getLocalSupportPointWithoutMargin(const Vector3& direction, void** cachedCollisionData) const { @@ -137,7 +132,7 @@ bool ConeShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* pr } // If the origin of the ray is inside the cone, we return no hit - if (testPointInside(ray.point1, NULL)) return false; + if (testPointInside(ray.point1, nullptr)) return false; localHitPoint[0] = ray.point1 + tHit[0] * r; localHitPoint[1] = ray.point1 + tHit[1] * r; diff --git a/src/collision/shapes/ConeShape.h b/src/collision/shapes/ConeShape.h index 53630817..65ddb35e 100644 --- a/src/collision/shapes/ConeShape.h +++ b/src/collision/shapes/ConeShape.h @@ -66,24 +66,18 @@ class ConeShape : public ConvexShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - ConeShape(const ConeShape& shape); - - /// Private assignment operator - ConeShape& operator=(const ConeShape& shape); - /// Return a local support point in a given direction without the object margin virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const; + void** cachedCollisionData) const override; /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const; + virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override; /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; public : @@ -93,7 +87,13 @@ class ConeShape : public ConvexShape { ConeShape(decimal mRadius, decimal height, decimal margin = OBJECT_MARGIN); /// Destructor - virtual ~ConeShape(); + virtual ~ConeShape() override = default; + + /// Deleted copy-constructor + ConeShape(const ConeShape& shape) = delete; + + /// Deleted assignment operator + ConeShape& operator=(const ConeShape& shape) = delete; /// Return the radius decimal getRadius() const; @@ -102,16 +102,16 @@ class ConeShape : public ConvexShape { decimal getHeight() const; /// Set the scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return the local bounds of the shape in x, y and z directions - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Return true if the collision shape is a polyhedron virtual bool isPolyhedron() const; /// Return the local inertia tensor of the collision shape - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; }; // Return the radius diff --git a/src/collision/shapes/ConvexMeshShape.cpp b/src/collision/shapes/ConvexMeshShape.cpp index e3643a97..cc880a25 100644 --- a/src/collision/shapes/ConvexMeshShape.cpp +++ b/src/collision/shapes/ConvexMeshShape.cpp @@ -39,7 +39,7 @@ using namespace reactphysics3d; * @param margin Collision margin (in meters) around the collision shape */ ConvexMeshShape::ConvexMeshShape(const decimal* arrayVertices, uint nbVertices, int stride, decimal margin) - : ConvexShape(CONVEX_MESH, margin), mNbVertices(nbVertices), mMinBounds(0, 0, 0), + : ConvexShape(CollisionShapeType::CONVEX_MESH, margin), mNbVertices(nbVertices), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(false) { assert(nbVertices > 0); assert(stride > 0); @@ -65,7 +65,7 @@ ConvexMeshShape::ConvexMeshShape(const decimal* arrayVertices, uint nbVertices, * @param margin Collision margin (in meters) around the collision shape */ ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool isEdgesInformationUsed, decimal margin) - : ConvexShape(CONVEX_MESH, margin), mMinBounds(0, 0, 0), + : ConvexShape(CollisionShapeType::CONVEX_MESH, margin), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(isEdgesInformationUsed) { TriangleVertexArray::VertexDataType vertexType = triangleVertexArray->getVertexDataType(); @@ -79,14 +79,14 @@ ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool for (uint v = 0; v < triangleVertexArray->getNbVertices(); v++) { // Get the vertices components of the triangle - if (vertexType == TriangleVertexArray::VERTEX_FLOAT_TYPE) { + if (vertexType == TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE) { const float* vertices = (float*)(verticesStart + v * vertexStride); Vector3 vertex(vertices[0], vertices[1], vertices[2] ); vertex = vertex * mScaling; mVertices.push_back(vertex); } - else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) { + else if (vertexType == TriangleVertexArray::VertexDataType::VERTEX_DOUBLE_TYPE) { const double* vertices = (double*)(verticesStart + v * vertexStride); Vector3 vertex(vertices[0], vertices[1], vertices[2] ); @@ -109,10 +109,10 @@ ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool for (int k=0; k < 3; k++) { // Get the index of the current vertex in the triangle - if (indexType == TriangleVertexArray::INDEX_INTEGER_TYPE) { + if (indexType == TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE) { vertexIndex[k] = ((uint*)vertexIndexPointer)[k]; } - else if (indexType == TriangleVertexArray::INDEX_SHORT_TYPE) { + else if (indexType == TriangleVertexArray::IndexDataType::INDEX_SHORT_TYPE) { vertexIndex[k] = ((unsigned short*)vertexIndexPointer)[k]; } else { @@ -135,16 +135,11 @@ ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool /// If you use this constructor, you will need to set the vertices manually one by one using /// the addVertex() method. ConvexMeshShape::ConvexMeshShape(decimal margin) - : ConvexShape(CONVEX_MESH, margin), mNbVertices(0), mMinBounds(0, 0, 0), + : ConvexShape(CollisionShapeType::CONVEX_MESH, margin), mNbVertices(0), mMinBounds(0, 0, 0), mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(false) { } -// Destructor -ConvexMeshShape::~ConvexMeshShape() { - -} - // Return a local support point in a given direction without the object margin. /// If the edges information is not used for collision detection, this method will go through /// the whole vertices list and pick up the vertex with the largest dot product in the support @@ -157,10 +152,10 @@ Vector3 ConvexMeshShape::getLocalSupportPointWithoutMargin(const Vector3& direct void** cachedCollisionData) const { assert(mNbVertices == mVertices.size()); - assert(cachedCollisionData != NULL); + assert(cachedCollisionData != nullptr); // Allocate memory for the cached collision data if not allocated yet - if ((*cachedCollisionData) == NULL) { + if ((*cachedCollisionData) == nullptr) { *cachedCollisionData = (int*) malloc(sizeof(int)); *((int*)(*cachedCollisionData)) = 0; } diff --git a/src/collision/shapes/ConvexMeshShape.h b/src/collision/shapes/ConvexMeshShape.h index 94ec67f9..aeb1edbe 100644 --- a/src/collision/shapes/ConvexMeshShape.h +++ b/src/collision/shapes/ConvexMeshShape.h @@ -85,30 +85,24 @@ class ConvexMeshShape : public ConvexShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - ConvexMeshShape(const ConvexMeshShape& shape); - - /// Private assignment operator - ConvexMeshShape& operator=(const ConvexMeshShape& shape); - /// Recompute the bounds of the mesh void recalculateBounds(); /// Set the scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return a local support point in a given direction without the object margin. virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const; + void** cachedCollisionData) const override; /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const; + virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override; /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; public : @@ -126,13 +120,19 @@ class ConvexMeshShape : public ConvexShape { ConvexMeshShape(decimal margin = OBJECT_MARGIN); /// Destructor - virtual ~ConvexMeshShape(); + virtual ~ConvexMeshShape() override = default; + + /// Deleted copy-constructor + ConvexMeshShape(const ConvexMeshShape& shape) = delete; + + /// Deleted assignment operator + ConvexMeshShape& operator=(const ConvexMeshShape& shape) = delete; /// Return the local bounds of the shape in x, y and z directions - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Return the local inertia tensor of the collision shape. - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; /// Add a vertex into the convex mesh void addVertex(const Vector3& vertex); diff --git a/src/collision/shapes/ConvexShape.cpp b/src/collision/shapes/ConvexShape.cpp index 2faa877f..f077cdcb 100644 --- a/src/collision/shapes/ConvexShape.cpp +++ b/src/collision/shapes/ConvexShape.cpp @@ -36,11 +36,6 @@ ConvexShape::ConvexShape(CollisionShapeType type, decimal margin) } -// Destructor -ConvexShape::~ConvexShape() { - -} - // Return a local support point in a given direction with the object margin Vector3 ConvexShape::getLocalSupportPointWithMargin(const Vector3& direction, void** cachedCollisionData) const { diff --git a/src/collision/shapes/ConvexShape.h b/src/collision/shapes/ConvexShape.h index a3cd3131..4b12cae4 100644 --- a/src/collision/shapes/ConvexShape.h +++ b/src/collision/shapes/ConvexShape.h @@ -48,12 +48,6 @@ class ConvexShape : public CollisionShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - ConvexShape(const ConvexShape& shape); - - /// Private assignment operator - ConvexShape& operator=(const ConvexShape& shape); - // Return a local support point in a given direction with the object margin Vector3 getLocalSupportPointWithMargin(const Vector3& direction, void** cachedCollisionData) const; @@ -62,9 +56,6 @@ class ConvexShape : public CollisionShape { virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, void** cachedCollisionData) const=0; - /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& worldPoint, ProxyShape* proxyShape) const=0; - public : // -------------------- Methods -------------------- // @@ -73,13 +64,19 @@ class ConvexShape : public CollisionShape { ConvexShape(CollisionShapeType type, decimal margin); /// Destructor - virtual ~ConvexShape(); + virtual ~ConvexShape() override = default; + + /// Deleted copy-constructor + ConvexShape(const ConvexShape& shape) = delete; + + /// Deleted assignment operator + ConvexShape& operator=(const ConvexShape& shape) = delete; /// Return the current object margin decimal getMargin() const; /// Return true if the collision shape is convex, false if it is concave - virtual bool isConvex() const; + virtual bool isConvex() const override; // -------------------- Friendship -------------------- // diff --git a/src/collision/shapes/CylinderShape.cpp b/src/collision/shapes/CylinderShape.cpp index fd3da01c..8cb405f1 100644 --- a/src/collision/shapes/CylinderShape.cpp +++ b/src/collision/shapes/CylinderShape.cpp @@ -37,17 +37,12 @@ using namespace reactphysics3d; * @param margin Collision margin (in meters) around the collision shape */ CylinderShape::CylinderShape(decimal radius, decimal height, decimal margin) - : ConvexShape(CYLINDER, margin), mRadius(radius), + : ConvexShape(CollisionShapeType::CYLINDER, margin), mRadius(radius), mHalfHeight(height/decimal(2.0)) { assert(radius > decimal(0.0)); assert(height > decimal(0.0)); } -// Destructor -CylinderShape::~CylinderShape() { - -} - // Return a local support point in a given direction without the object margin Vector3 CylinderShape::getLocalSupportPointWithoutMargin(const Vector3& direction, void** cachedCollisionData) const { @@ -55,7 +50,7 @@ Vector3 CylinderShape::getLocalSupportPointWithoutMargin(const Vector3& directio Vector3 supportPoint(0.0, 0.0, 0.0); decimal uDotv = direction.y; Vector3 w(direction.x, 0.0, direction.z); - decimal lengthW = sqrt(direction.x * direction.x + direction.z * direction.z); + decimal lengthW = std::sqrt(direction.x * direction.x + direction.z * direction.z); if (lengthW > MACHINE_EPSILON) { if (uDotv < 0.0) supportPoint.y = -mHalfHeight; diff --git a/src/collision/shapes/CylinderShape.h b/src/collision/shapes/CylinderShape.h index a732ecf6..b58c454d 100644 --- a/src/collision/shapes/CylinderShape.h +++ b/src/collision/shapes/CylinderShape.h @@ -63,24 +63,18 @@ class CylinderShape : public ConvexShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - CylinderShape(const CylinderShape& shape); - - /// Private assignment operator - CylinderShape& operator=(const CylinderShape& shape); - /// Return a local support point in a given direction without the object margin virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const; + void** cachedCollisionData) const override; /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const; + virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override; /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override ; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; public : @@ -90,7 +84,13 @@ class CylinderShape : public ConvexShape { CylinderShape(decimal radius, decimal height, decimal margin = OBJECT_MARGIN); /// Destructor - virtual ~CylinderShape(); + virtual ~CylinderShape() override = default; + + /// Deleted copy-constructor + CylinderShape(const CylinderShape& shape) = delete; + + /// Deleted assignment operator + CylinderShape& operator=(const CylinderShape& shape) = delete; /// Return the radius decimal getRadius() const; @@ -102,13 +102,13 @@ class CylinderShape : public ConvexShape { virtual bool isPolyhedron() const; /// Set the scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return the local bounds of the shape in x, y and z directions - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Return the local inertia tensor of the collision shape - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; }; // Return the radius diff --git a/src/collision/shapes/HeightFieldShape.cpp b/src/collision/shapes/HeightFieldShape.cpp index 88224e2d..02ef852f 100644 --- a/src/collision/shapes/HeightFieldShape.cpp +++ b/src/collision/shapes/HeightFieldShape.cpp @@ -42,7 +42,7 @@ using namespace reactphysics3d; HeightFieldShape::HeightFieldShape(int nbGridColumns, int nbGridRows, decimal minHeight, decimal maxHeight, const void* heightFieldData, HeightDataType dataType, int upAxis, decimal integerHeightScale) - : ConcaveShape(HEIGHTFIELD), mNbColumns(nbGridColumns), mNbRows(nbGridRows), + : ConcaveShape(CollisionShapeType::HEIGHTFIELD), mNbColumns(nbGridColumns), mNbRows(nbGridRows), mWidth(nbGridColumns - 1), mLength(nbGridRows - 1), mMinHeight(minHeight), mMaxHeight(maxHeight), mUpAxis(upAxis), mIntegerHeightScale(integerHeightScale), mHeightDataType(dataType) { @@ -74,11 +74,6 @@ HeightFieldShape::HeightFieldShape(int nbGridColumns, int nbGridRows, decimal mi } } -// Destructor -HeightFieldShape::~HeightFieldShape() { - -} - // Return the local bounds of the shape in x, y and z directions. // This method is used to compute the AABB of the box /** diff --git a/src/collision/shapes/HeightFieldShape.h b/src/collision/shapes/HeightFieldShape.h index 49adff48..6f2b8459 100644 --- a/src/collision/shapes/HeightFieldShape.h +++ b/src/collision/shapes/HeightFieldShape.h @@ -64,7 +64,7 @@ class TriangleOverlapCallback : public TriangleCallback { bool getIsHit() const {return mIsHit;} /// Raycast test between a ray and a triangle of the heightfield - virtual void testTriangle(const Vector3* trianglePoints); + virtual void testTriangle(const Vector3* trianglePoints) override; }; @@ -84,7 +84,7 @@ class HeightFieldShape : public ConcaveShape { public: /// Data type for the height data of the height field - enum HeightDataType {HEIGHT_FLOAT_TYPE, HEIGHT_DOUBLE_TYPE, HEIGHT_INT_TYPE}; + enum class HeightDataType {HEIGHT_FLOAT_TYPE, HEIGHT_DOUBLE_TYPE, HEIGHT_INT_TYPE}; protected: @@ -125,17 +125,11 @@ class HeightFieldShape : public ConcaveShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - HeightFieldShape(const HeightFieldShape& shape); - - /// Private assignment operator - HeightFieldShape& operator=(const HeightFieldShape& shape); - /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; /// Insert all the triangles into the dynamic AABB tree void initBVHTree(); @@ -165,7 +159,13 @@ class HeightFieldShape : public ConcaveShape { int upAxis = 1, decimal integerHeightScale = 1.0f); /// Destructor - ~HeightFieldShape(); + virtual ~HeightFieldShape() override = default; + + /// Deleted copy-constructor + HeightFieldShape(const HeightFieldShape& shape) = delete; + + /// Deleted assignment operator + HeightFieldShape& operator=(const HeightFieldShape& shape) = delete; /// Return the number of rows in the height field int getNbRows() const; @@ -177,16 +177,16 @@ class HeightFieldShape : public ConcaveShape { HeightDataType getHeightDataType() const; /// Return the local bounds of the shape in x, y and z directions. - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Set the local scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return the local inertia tensor of the collision shape - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; /// Use a callback method on all triangles of the concave shape inside a given AABB - virtual void testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const; + virtual void testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const override; // ---------- Friendship ----------- // @@ -223,9 +223,9 @@ inline void HeightFieldShape::setLocalScaling(const Vector3& scaling) { inline decimal HeightFieldShape::getHeightAt(int x, int y) const { switch(mHeightDataType) { - case HEIGHT_FLOAT_TYPE : return ((float*)mHeightFieldData)[y * mNbColumns + x]; - case HEIGHT_DOUBLE_TYPE : return ((double*)mHeightFieldData)[y * mNbColumns + x]; - case HEIGHT_INT_TYPE : return ((int*)mHeightFieldData)[y * mNbColumns + x] * mIntegerHeightScale; + case HeightDataType::HEIGHT_FLOAT_TYPE : return ((float*)mHeightFieldData)[y * mNbColumns + x]; + case HeightDataType::HEIGHT_DOUBLE_TYPE : return ((double*)mHeightFieldData)[y * mNbColumns + x]; + case HeightDataType::HEIGHT_INT_TYPE : return ((int*)mHeightFieldData)[y * mNbColumns + x] * mIntegerHeightScale; default: assert(false); return 0; } } diff --git a/src/collision/shapes/SphereShape.cpp b/src/collision/shapes/SphereShape.cpp index 549a6359..73fe49aa 100644 --- a/src/collision/shapes/SphereShape.cpp +++ b/src/collision/shapes/SphereShape.cpp @@ -35,15 +35,10 @@ using namespace reactphysics3d; /** * @param radius Radius of the sphere (in meters) */ -SphereShape::SphereShape(decimal radius) : ConvexShape(SPHERE, radius) { +SphereShape::SphereShape(decimal radius) : ConvexShape(CollisionShapeType::SPHERE, radius) { assert(radius > decimal(0.0)); } -// Destructor -SphereShape::~SphereShape() { - -} - // Raycast method with feedback information bool SphereShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const { diff --git a/src/collision/shapes/SphereShape.h b/src/collision/shapes/SphereShape.h index bfbe46b5..58f20e6f 100644 --- a/src/collision/shapes/SphereShape.h +++ b/src/collision/shapes/SphereShape.h @@ -46,29 +46,20 @@ class SphereShape : public ConvexShape { protected : - // -------------------- Attributes -------------------- // - - // -------------------- Methods -------------------- // - /// Private copy-constructor - SphereShape(const SphereShape& shape); - - /// Private assignment operator - SphereShape& operator=(const SphereShape& shape); - /// Return a local support point in a given direction without the object margin virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const; + void** cachedCollisionData) const override; /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const; + virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override; /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; public : @@ -78,7 +69,13 @@ class SphereShape : public ConvexShape { SphereShape(decimal radius); /// Destructor - virtual ~SphereShape(); + virtual ~SphereShape() override = default; + + /// Deleted copy-constructor + SphereShape(const SphereShape& shape) = delete; + + /// Deleted assignment operator + SphereShape& operator=(const SphereShape& shape) = delete; /// Return the radius of the sphere decimal getRadius() const; @@ -87,16 +84,16 @@ class SphereShape : public ConvexShape { virtual bool isPolyhedron() const; /// Set the scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return the local bounds of the shape in x, y and z directions. - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Return the local inertia tensor of the collision shape - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; /// Update the AABB of a body using its collision shape - virtual void computeAABB(AABB& aabb, const Transform& transform) const; + virtual void computeAABB(AABB& aabb, const Transform& transform) const override; }; // Get the radius of the sphere diff --git a/src/collision/shapes/TriangleShape.cpp b/src/collision/shapes/TriangleShape.cpp index 24bd3fda..4767435b 100644 --- a/src/collision/shapes/TriangleShape.cpp +++ b/src/collision/shapes/TriangleShape.cpp @@ -40,16 +40,11 @@ using namespace reactphysics3d; * @param margin The collision margin (in meters) around the collision shape */ TriangleShape::TriangleShape(const Vector3& point1, const Vector3& point2, const Vector3& point3, decimal margin) - : ConvexShape(TRIANGLE, margin) { + : ConvexShape(CollisionShapeType::TRIANGLE, margin) { mPoints[0] = point1; mPoints[1] = point2; mPoints[2] = point3; - mRaycastTestType = FRONT; -} - -// Destructor -TriangleShape::~TriangleShape() { - + mRaycastTestType = TriangleRaycastSide::FRONT; } // Raycast method with feedback information @@ -68,32 +63,32 @@ bool TriangleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape // product for this test. const Vector3 m = pq.cross(pc); decimal u = pb.dot(m); - if (mRaycastTestType == FRONT) { + if (mRaycastTestType == TriangleRaycastSide::FRONT) { if (u < decimal(0.0)) return false; } - else if (mRaycastTestType == BACK) { + else if (mRaycastTestType == TriangleRaycastSide::BACK) { if (u > decimal(0.0)) return false; } decimal v = -pa.dot(m); - if (mRaycastTestType == FRONT) { + if (mRaycastTestType == TriangleRaycastSide::FRONT) { if (v < decimal(0.0)) return false; } - else if (mRaycastTestType == BACK) { + else if (mRaycastTestType == TriangleRaycastSide::BACK) { if (v > decimal(0.0)) return false; } - else if (mRaycastTestType == FRONT_AND_BACK) { + else if (mRaycastTestType == TriangleRaycastSide::FRONT_AND_BACK) { if (!sameSign(u, v)) return false; } decimal w = pa.dot(pq.cross(pb)); - if (mRaycastTestType == FRONT) { + if (mRaycastTestType == TriangleRaycastSide::FRONT) { if (w < decimal(0.0)) return false; } - else if (mRaycastTestType == BACK) { + else if (mRaycastTestType == TriangleRaycastSide::BACK) { if (w > decimal(0.0)) return false; } - else if (mRaycastTestType == FRONT_AND_BACK) { + else if (mRaycastTestType == TriangleRaycastSide::FRONT_AND_BACK) { if (!sameSign(u, w)) return false; } diff --git a/src/collision/shapes/TriangleShape.h b/src/collision/shapes/TriangleShape.h index 71af0f89..d1c82f70 100644 --- a/src/collision/shapes/TriangleShape.h +++ b/src/collision/shapes/TriangleShape.h @@ -34,7 +34,7 @@ namespace reactphysics3d { /// Raycast test side for the triangle -enum TriangleRaycastSide { +enum class TriangleRaycastSide { /// Raycast against front triangle FRONT, @@ -65,24 +65,18 @@ class TriangleShape : public ConvexShape { // -------------------- Methods -------------------- // - /// Private copy-constructor - TriangleShape(const TriangleShape& shape); - - /// Private assignment operator - TriangleShape& operator=(const TriangleShape& shape); - /// Return a local support point in a given direction without the object margin virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction, - void** cachedCollisionData) const; + void** cachedCollisionData) const override; /// Return true if a point is inside the collision shape - virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const; + virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override; /// Raycast method with feedback information - virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const; + virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const override; /// Return the number of bytes used by the collision shape - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; public: @@ -93,19 +87,25 @@ class TriangleShape : public ConvexShape { decimal margin = OBJECT_MARGIN); /// Destructor - virtual ~TriangleShape(); + virtual ~TriangleShape() override = default; + + /// Deleted copy-constructor + TriangleShape(const TriangleShape& shape) = delete; + + /// Deleted assignment operator + TriangleShape& operator=(const TriangleShape& shape) = delete; /// Return the local bounds of the shape in x, y and z directions. - virtual void getLocalBounds(Vector3& min, Vector3& max) const; + virtual void getLocalBounds(Vector3& min, Vector3& max) const override; /// Set the local scaling vector of the collision shape - virtual void setLocalScaling(const Vector3& scaling); + virtual void setLocalScaling(const Vector3& scaling) override; /// Return the local inertia tensor of the collision shape - virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const; + virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const override; /// Update the AABB of a body using its collision shape - virtual void computeAABB(AABB& aabb, const Transform& transform) const; + virtual void computeAABB(AABB& aabb, const Transform& transform) const override; /// Return the raycast test type (front, back, front-back) TriangleRaycastSide getRaycastTestType() const; diff --git a/src/configuration.h b/src/configuration.h index 134668bd..4364c548 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -46,22 +46,22 @@ namespace reactphysics3d { // ------------------- Type definitions ------------------- // -typedef unsigned int uint; -typedef long unsigned int luint; -typedef luint bodyindex; -typedef std::pair bodyindexpair; +using uint = unsigned int; +using luint = long unsigned int; +using bodyindex = luint; +using bodyindexpair = std::pair; -typedef signed short int16; -typedef signed int int32; -typedef unsigned short uint16; -typedef unsigned int uint32; +using int16 = signed short; +using int32 = signed int; +using uint16 = unsigned short; +using uint32 = unsigned int; // ------------------- Enumerations ------------------- // /// Position correction technique used in the constraint solver (for joints). /// BAUMGARTE_JOINTS : Faster but can be innacurate in some situations. /// NON_LINEAR_GAUSS_SEIDEL : Slower but more precise. This is the option used by default. -enum JointsPositionCorrectionTechnique {BAUMGARTE_JOINTS, NON_LINEAR_GAUSS_SEIDEL}; +enum class JointsPositionCorrectionTechnique {BAUMGARTE_JOINTS, NON_LINEAR_GAUSS_SEIDEL}; /// Position correction technique used in the contact solver (for contacts) /// BAUMGARTE_CONTACTS : Faster but can be innacurate and can lead to unexpected bounciness @@ -69,7 +69,7 @@ enum JointsPositionCorrectionTechnique {BAUMGARTE_JOINTS, NON_LINEAR_GAUSS_SEIDE /// the bodies momentum). /// SPLIT_IMPULSES : A bit slower but the error correction factor is not added to the /// bodies momentum. This is the option used by default. -enum ContactsPositionCorrectionTechnique {BAUMGARTE_CONTACTS, SPLIT_IMPULSES}; +enum class ContactsPositionCorrectionTechnique {BAUMGARTE_CONTACTS, SPLIT_IMPULSES}; // ------------------- Constants ------------------- // @@ -83,66 +83,66 @@ const decimal DECIMAL_LARGEST = std::numeric_limits::max(); const decimal MACHINE_EPSILON = std::numeric_limits::epsilon(); /// Pi constant -const decimal PI = decimal(3.14159265); +constexpr decimal PI = decimal(3.14159265); /// 2*Pi constant -const decimal PI_TIMES_2 = decimal(6.28318530); +constexpr decimal PI_TIMES_2 = decimal(6.28318530); /// Default friction coefficient for a rigid body -const decimal DEFAULT_FRICTION_COEFFICIENT = decimal(0.3); +constexpr decimal DEFAULT_FRICTION_COEFFICIENT = decimal(0.3); /// Default bounciness factor for a rigid body -const decimal DEFAULT_BOUNCINESS = decimal(0.5); +constexpr decimal DEFAULT_BOUNCINESS = decimal(0.5); /// Default rolling resistance -const decimal DEFAULT_ROLLING_RESISTANCE = decimal(0.0); +constexpr decimal DEFAULT_ROLLING_RESISTANCE = decimal(0.0); /// True if the spleeping technique is enabled -const bool SPLEEPING_ENABLED = true; +constexpr bool SPLEEPING_ENABLED = true; /// Object margin for collision detection in meters (for the GJK-EPA Algorithm) -const decimal OBJECT_MARGIN = decimal(0.04); +constexpr decimal OBJECT_MARGIN = decimal(0.04); /// Distance threshold for two contact points for a valid persistent contact (in meters) -const decimal PERSISTENT_CONTACT_DIST_THRESHOLD = decimal(0.03); +constexpr decimal PERSISTENT_CONTACT_DIST_THRESHOLD = decimal(0.03); /// Velocity threshold for contact velocity restitution -const decimal RESTITUTION_VELOCITY_THRESHOLD = decimal(1.0); +constexpr decimal RESTITUTION_VELOCITY_THRESHOLD = decimal(1.0); /// Number of iterations when solving the velocity constraints of the Sequential Impulse technique -const uint DEFAULT_VELOCITY_SOLVER_NB_ITERATIONS = 10; +constexpr uint DEFAULT_VELOCITY_SOLVER_NB_ITERATIONS = 10; /// Number of iterations when solving the position constraints of the Sequential Impulse technique -const uint DEFAULT_POSITION_SOLVER_NB_ITERATIONS = 5; +constexpr uint DEFAULT_POSITION_SOLVER_NB_ITERATIONS = 5; /// Time (in seconds) that a body must stay still to be considered sleeping -const float DEFAULT_TIME_BEFORE_SLEEP = 1.0f; +constexpr float DEFAULT_TIME_BEFORE_SLEEP = 1.0f; /// A body with a linear velocity smaller than the sleep linear velocity (in m/s) /// might enter sleeping mode. -const decimal DEFAULT_SLEEP_LINEAR_VELOCITY = decimal(0.02); +constexpr decimal DEFAULT_SLEEP_LINEAR_VELOCITY = decimal(0.02); /// A body with angular velocity smaller than the sleep angular velocity (in rad/s) /// might enter sleeping mode -const decimal DEFAULT_SLEEP_ANGULAR_VELOCITY = decimal(3.0 * (PI / 180.0)); +constexpr decimal DEFAULT_SLEEP_ANGULAR_VELOCITY = decimal(3.0 * (PI / 180.0)); /// In the broad-phase collision detection (dynamic AABB tree), the AABBs are /// inflated with a constant gap to allow the collision shape to move a little bit /// without triggering a large modification of the tree which can be costly -const decimal DYNAMIC_TREE_AABB_GAP = decimal(0.1); +constexpr decimal DYNAMIC_TREE_AABB_GAP = decimal(0.1); /// In the broad-phase collision detection (dynamic AABB tree), the AABBs are /// also inflated in direction of the linear motion of the body by mutliplying the /// followin constant with the linear velocity and the elapsed time between two frames. -const decimal DYNAMIC_TREE_AABB_LIN_GAP_MULTIPLIER = decimal(1.7); +constexpr decimal DYNAMIC_TREE_AABB_LIN_GAP_MULTIPLIER = decimal(1.7); /// Maximum number of contact manifolds in an overlapping pair that involves two /// convex collision shapes. -const int NB_MAX_CONTACT_MANIFOLDS_CONVEX_SHAPE = 1; +constexpr int NB_MAX_CONTACT_MANIFOLDS_CONVEX_SHAPE = 1; /// Maximum number of contact manifolds in an overlapping pair that involves at /// least one concave collision shape. -const int NB_MAX_CONTACT_MANIFOLDS_CONCAVE_SHAPE = 3; +constexpr int NB_MAX_CONTACT_MANIFOLDS_CONCAVE_SHAPE = 3; } diff --git a/src/constraint/BallAndSocketJoint.cpp b/src/constraint/BallAndSocketJoint.cpp index 275b5643..497a45dc 100644 --- a/src/constraint/BallAndSocketJoint.cpp +++ b/src/constraint/BallAndSocketJoint.cpp @@ -30,7 +30,7 @@ using namespace reactphysics3d; // Static variables definition -const decimal BallAndSocketJoint::BETA = decimal(0.2); +constexpr decimal BallAndSocketJoint::BETA = decimal(0.2); // Constructor BallAndSocketJoint::BallAndSocketJoint(const BallAndSocketJointInfo& jointInfo) @@ -41,11 +41,6 @@ BallAndSocketJoint::BallAndSocketJoint(const BallAndSocketJointInfo& jointInfo) mLocalAnchorPointBody2 = mBody2->getTransform().getInverse() * jointInfo.anchorPointWorldSpace; } -// Destructor -BallAndSocketJoint::~BallAndSocketJoint() { - -} - // Initialize before solving the constraint void BallAndSocketJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverData) { @@ -81,13 +76,13 @@ void BallAndSocketJoint::initBeforeSolve(const ConstraintSolverData& constraintS // Compute the inverse mass matrix K^-1 mInverseMassMatrix.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrix = massMatrix.getInverse(); } // Compute the bias "b" of the constraint mBiasVector.setToZero(); - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { decimal biasFactor = (BETA / constraintSolverData.timeStep); mBiasVector = biasFactor * (x2 + mR2World - x1 - mR1World); } @@ -162,7 +157,7 @@ void BallAndSocketJoint::solvePositionConstraint(const ConstraintSolverData& con // If the error position correction technique is not the non-linear-gauss-seidel, we do // do not execute this method - if (mPositionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return; + if (mPositionCorrectionTechnique != JointsPositionCorrectionTechnique::NON_LINEAR_GAUSS_SEIDEL) return; // Get the bodies center of mass and orientations Vector3& x1 = constraintSolverData.positions[mIndexBody1]; @@ -194,7 +189,7 @@ void BallAndSocketJoint::solvePositionConstraint(const ConstraintSolverData& con skewSymmetricMatrixU1 * mI1 * skewSymmetricMatrixU1.getTranspose() + skewSymmetricMatrixU2 * mI2 * skewSymmetricMatrixU2.getTranspose(); mInverseMassMatrix.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrix = massMatrix.getInverse(); } diff --git a/src/constraint/BallAndSocketJoint.h b/src/constraint/BallAndSocketJoint.h index f4671e87..c8836a23 100644 --- a/src/constraint/BallAndSocketJoint.h +++ b/src/constraint/BallAndSocketJoint.h @@ -55,7 +55,7 @@ struct BallAndSocketJointInfo : public JointInfo { */ BallAndSocketJointInfo(RigidBody* rigidBody1, RigidBody* rigidBody2, const Vector3& initAnchorPointWorldSpace) - : JointInfo(rigidBody1, rigidBody2, BALLSOCKETJOINT), + : JointInfo(rigidBody1, rigidBody2, JointType::BALLSOCKETJOINT), anchorPointWorldSpace(initAnchorPointWorldSpace) {} }; @@ -105,26 +105,20 @@ class BallAndSocketJoint : public Joint { // -------------------- Methods -------------------- // - /// Private copy-constructor - BallAndSocketJoint(const BallAndSocketJoint& constraint); - - /// Private assignment operator - BallAndSocketJoint& operator=(const BallAndSocketJoint& constraint); - /// Return the number of bytes used by the joint - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; /// Initialize before solving the constraint - virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData); + virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData) override; /// Warm start the constraint (apply the previous impulse at the beginning of the step) - virtual void warmstart(const ConstraintSolverData& constraintSolverData); + virtual void warmstart(const ConstraintSolverData& constraintSolverData) override; /// Solve the velocity constraint - virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData); + virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) override; /// Solve the position constraint (for position error correction) - virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData); + virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData) override; public : @@ -134,7 +128,13 @@ class BallAndSocketJoint : public Joint { BallAndSocketJoint(const BallAndSocketJointInfo& jointInfo); /// Destructor - virtual ~BallAndSocketJoint(); + virtual ~BallAndSocketJoint() override = default; + + /// Deleted copy-constructor + BallAndSocketJoint(const BallAndSocketJoint& constraint) = delete; + + /// Deleted assignment operator + BallAndSocketJoint& operator=(const BallAndSocketJoint& constraint) = delete; }; // Return the number of bytes used by the joint diff --git a/src/constraint/ContactPoint.cpp b/src/constraint/ContactPoint.cpp index ccc7e960..3be8476a 100644 --- a/src/constraint/ContactPoint.cpp +++ b/src/constraint/ContactPoint.cpp @@ -51,8 +51,3 @@ ContactPoint::ContactPoint(const ContactPointInfo& contactInfo) assert(mPenetrationDepth > 0.0); } - -// Destructor -ContactPoint::~ContactPoint() { - -} diff --git a/src/constraint/ContactPoint.h b/src/constraint/ContactPoint.h index 9b172e6c..d2e8f189 100644 --- a/src/constraint/ContactPoint.h +++ b/src/constraint/ContactPoint.h @@ -142,14 +142,6 @@ class ContactPoint { /// Cached rolling resistance impulse Vector3 mRollingResistanceImpulse; - - // -------------------- Methods -------------------- // - - /// Private copy-constructor - ContactPoint(const ContactPoint& contact); - - /// Private assignment operator - ContactPoint& operator=(const ContactPoint& contact); public : @@ -159,7 +151,13 @@ class ContactPoint { ContactPoint(const ContactPointInfo& contactInfo); /// Destructor - ~ContactPoint(); + ~ContactPoint() = default; + + /// Deleted copy-constructor + ContactPoint(const ContactPoint& contact) = delete; + + /// Deleted assignment operator + ContactPoint& operator=(const ContactPoint& contact) = delete; /// Return the reference to the body 1 CollisionBody* getBody1() const; diff --git a/src/constraint/FixedJoint.cpp b/src/constraint/FixedJoint.cpp index 57c8d8c6..9ed31f01 100644 --- a/src/constraint/FixedJoint.cpp +++ b/src/constraint/FixedJoint.cpp @@ -30,7 +30,7 @@ using namespace reactphysics3d; // Static variables definition -const decimal FixedJoint::BETA = decimal(0.2); +constexpr decimal FixedJoint::BETA = decimal(0.2); // Constructor FixedJoint::FixedJoint(const FixedJointInfo& jointInfo) @@ -49,11 +49,6 @@ FixedJoint::FixedJoint(const FixedJointInfo& jointInfo) mInitOrientationDifferenceInv.inverse(); } -// Destructor -FixedJoint::~FixedJoint() { - -} - // Initialize before solving the constraint void FixedJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverData) { @@ -89,27 +84,27 @@ void FixedJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat // Compute the inverse mass matrix K^-1 for the 3 translation constraints mInverseMassMatrixTranslation.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixTranslation = massMatrix.getInverse(); } // Compute the bias "b" of the constraint for the 3 translation constraints decimal biasFactor = (BETA / constraintSolverData.timeStep); mBiasTranslation.setToZero(); - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mBiasTranslation = biasFactor * (x2 + mR2World - x1 - mR1World); } // Compute the inverse of the mass matrix K=JM^-1J^t for the 3 rotation // contraints (3x3 matrix) mInverseMassMatrixRotation = mI1 + mI2; - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixRotation = mInverseMassMatrixRotation.getInverse(); } // Compute the bias "b" for the 3 rotation constraints mBiasRotation.setToZero(); - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { Quaternion currentOrientationDifference = orientationBody2 * orientationBody1.getInverse(); currentOrientationDifference.normalize(); const Quaternion qError = currentOrientationDifference * mInitOrientationDifferenceInv; @@ -222,7 +217,7 @@ void FixedJoint::solvePositionConstraint(const ConstraintSolverData& constraintS // If the error position correction technique is not the non-linear-gauss-seidel, we do // do not execute this method - if (mPositionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return; + if (mPositionCorrectionTechnique != JointsPositionCorrectionTechnique::NON_LINEAR_GAUSS_SEIDEL) return; // Get the bodies positions and orientations Vector3& x1 = constraintSolverData.positions[mIndexBody1]; @@ -256,7 +251,7 @@ void FixedJoint::solvePositionConstraint(const ConstraintSolverData& constraintS skewSymmetricMatrixU1 * mI1 * skewSymmetricMatrixU1.getTranspose() + skewSymmetricMatrixU2 * mI2 * skewSymmetricMatrixU2.getTranspose(); mInverseMassMatrixTranslation.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixTranslation = massMatrix.getInverse(); } @@ -296,7 +291,7 @@ void FixedJoint::solvePositionConstraint(const ConstraintSolverData& constraintS // Compute the inverse of the mass matrix K=JM^-1J^t for the 3 rotation // contraints (3x3 matrix) mInverseMassMatrixRotation = mI1 + mI2; - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixRotation = mInverseMassMatrixRotation.getInverse(); } diff --git a/src/constraint/FixedJoint.h b/src/constraint/FixedJoint.h index aa9f2798..e08b31cc 100644 --- a/src/constraint/FixedJoint.h +++ b/src/constraint/FixedJoint.h @@ -55,7 +55,7 @@ struct FixedJointInfo : public JointInfo { */ FixedJointInfo(RigidBody* rigidBody1, RigidBody* rigidBody2, const Vector3& initAnchorPointWorldSpace) - : JointInfo(rigidBody1, rigidBody2, FIXEDJOINT), + : JointInfo(rigidBody1, rigidBody2, JointType::FIXEDJOINT), anchorPointWorldSpace(initAnchorPointWorldSpace){} }; @@ -116,26 +116,20 @@ class FixedJoint : public Joint { // -------------------- Methods -------------------- // - /// Private copy-constructor - FixedJoint(const FixedJoint& constraint); - - /// Private assignment operator - FixedJoint& operator=(const FixedJoint& constraint); - /// Return the number of bytes used by the joint - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; /// Initialize before solving the constraint - virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData); + virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData) override; /// Warm start the constraint (apply the previous impulse at the beginning of the step) - virtual void warmstart(const ConstraintSolverData& constraintSolverData); + virtual void warmstart(const ConstraintSolverData& constraintSolverData) override; /// Solve the velocity constraint - virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData); + virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) override; /// Solve the position constraint (for position error correction) - virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData); + virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData) override; public : @@ -145,7 +139,13 @@ class FixedJoint : public Joint { FixedJoint(const FixedJointInfo& jointInfo); /// Destructor - virtual ~FixedJoint(); + virtual ~FixedJoint() override = default; + + /// Deleted copy-constructor + FixedJoint(const FixedJoint& constraint) = delete; + + /// Deleted assignment operator + FixedJoint& operator=(const FixedJoint& constraint) = delete; }; // Return the number of bytes used by the joint diff --git a/src/constraint/HingeJoint.cpp b/src/constraint/HingeJoint.cpp index e64cbde8..4b152caa 100644 --- a/src/constraint/HingeJoint.cpp +++ b/src/constraint/HingeJoint.cpp @@ -31,7 +31,7 @@ using namespace reactphysics3d; // Static variables definition -const decimal HingeJoint::BETA = decimal(0.2); +constexpr decimal HingeJoint::BETA = decimal(0.2); // Constructor HingeJoint::HingeJoint(const HingeJointInfo& jointInfo) @@ -64,11 +64,6 @@ HingeJoint::HingeJoint(const HingeJointInfo& jointInfo) mInitOrientationDifferenceInv.inverse(); } -// Destructor -HingeJoint::~HingeJoint() { - -} - // Initialize before solving the constraint void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverData) { @@ -129,14 +124,14 @@ void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat skewSymmetricMatrixU1 * mI1 * skewSymmetricMatrixU1.getTranspose() + skewSymmetricMatrixU2 * mI2 * skewSymmetricMatrixU2.getTranspose(); mInverseMassMatrixTranslation.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixTranslation = massMatrix.getInverse(); } // Compute the bias "b" of the translation constraints mBTranslation.setToZero(); decimal biasFactor = (BETA / constraintSolverData.timeStep); - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mBTranslation = biasFactor * (x2 + mR2World - x1 - mR1World); } @@ -155,13 +150,13 @@ void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat mC2CrossA1.dot(I2C2CrossA1); const Matrix2x2 matrixKRotation(el11, el12, el21, el22); mInverseMassMatrixRotation.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixRotation = matrixKRotation.getInverse(); } // Compute the bias "b" of the rotation constraints mBRotation.setToZero(); - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mBRotation = biasFactor * Vector2(mA1.dot(b2), mA1.dot(c2)); } @@ -188,13 +183,13 @@ void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat // Compute the bias "b" of the lower limit constraint mBLowerLimit = 0.0; - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mBLowerLimit = biasFactor * lowerLimitError; } // Compute the bias "b" of the upper limit constraint mBUpperLimit = 0.0; - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mBUpperLimit = biasFactor * upperLimitError; } } @@ -408,7 +403,7 @@ void HingeJoint::solvePositionConstraint(const ConstraintSolverData& constraintS // If the error position correction technique is not the non-linear-gauss-seidel, we do // do not execute this method - if (mPositionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return; + if (mPositionCorrectionTechnique != JointsPositionCorrectionTechnique::NON_LINEAR_GAUSS_SEIDEL) return; // Get the bodies positions and orientations Vector3& x1 = constraintSolverData.positions[mIndexBody1]; @@ -461,7 +456,7 @@ void HingeJoint::solvePositionConstraint(const ConstraintSolverData& constraintS skewSymmetricMatrixU1 * mI1 * skewSymmetricMatrixU1.getTranspose() + skewSymmetricMatrixU2 * mI2 * skewSymmetricMatrixU2.getTranspose(); mInverseMassMatrixTranslation.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixTranslation = massMatrix.getInverse(); } @@ -513,7 +508,7 @@ void HingeJoint::solvePositionConstraint(const ConstraintSolverData& constraintS mC2CrossA1.dot(I2C2CrossA1); const Matrix2x2 matrixKRotation(el11, el12, el21, el22); mInverseMassMatrixRotation.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixRotation = matrixKRotation.getInverse(); } diff --git a/src/constraint/HingeJoint.h b/src/constraint/HingeJoint.h index 662c7e5c..c553755d 100644 --- a/src/constraint/HingeJoint.h +++ b/src/constraint/HingeJoint.h @@ -82,7 +82,7 @@ struct HingeJointInfo : public JointInfo { HingeJointInfo(RigidBody* rigidBody1, RigidBody* rigidBody2, const Vector3& initAnchorPointWorldSpace, const Vector3& initRotationAxisWorld) - : JointInfo(rigidBody1, rigidBody2, HINGEJOINT), + : JointInfo(rigidBody1, rigidBody2, JointType::HINGEJOINT), anchorPointWorldSpace(initAnchorPointWorldSpace), rotationAxisWorld(initRotationAxisWorld), isLimitEnabled(false), isMotorEnabled(false), minAngleLimit(-1), maxAngleLimit(1), @@ -101,7 +101,7 @@ struct HingeJointInfo : public JointInfo { const Vector3& initAnchorPointWorldSpace, const Vector3& initRotationAxisWorld, decimal initMinAngleLimit, decimal initMaxAngleLimit) - : JointInfo(rigidBody1, rigidBody2, HINGEJOINT), + : JointInfo(rigidBody1, rigidBody2, JointType::HINGEJOINT), anchorPointWorldSpace(initAnchorPointWorldSpace), rotationAxisWorld(initRotationAxisWorld), isLimitEnabled(true), isMotorEnabled(false), minAngleLimit(initMinAngleLimit), @@ -124,7 +124,7 @@ struct HingeJointInfo : public JointInfo { const Vector3& initRotationAxisWorld, decimal initMinAngleLimit, decimal initMaxAngleLimit, decimal initMotorSpeed, decimal initMaxMotorTorque) - : JointInfo(rigidBody1, rigidBody2, HINGEJOINT), + : JointInfo(rigidBody1, rigidBody2, JointType::HINGEJOINT), anchorPointWorldSpace(initAnchorPointWorldSpace), rotationAxisWorld(initRotationAxisWorld), isLimitEnabled(true), isMotorEnabled(false), minAngleLimit(initMinAngleLimit), @@ -250,12 +250,6 @@ class HingeJoint : public Joint { // -------------------- Methods -------------------- // - /// Private copy-constructor - HingeJoint(const HingeJoint& constraint); - - /// Private assignment operator - HingeJoint& operator=(const HingeJoint& constraint); - /// Reset the limits void resetLimits(); @@ -274,19 +268,19 @@ class HingeJoint : public Joint { const Quaternion& orientationBody2); /// Return the number of bytes used by the joint - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; /// Initialize before solving the constraint - virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData); + virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData) override; /// Warm start the constraint (apply the previous impulse at the beginning of the step) - virtual void warmstart(const ConstraintSolverData& constraintSolverData); + virtual void warmstart(const ConstraintSolverData& constraintSolverData) override; /// Solve the velocity constraint - virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData); + virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) override; /// Solve the position constraint (for position error correction) - virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData); + virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData) override; public : @@ -296,7 +290,13 @@ class HingeJoint : public Joint { HingeJoint(const HingeJointInfo& jointInfo); /// Destructor - virtual ~HingeJoint(); + virtual ~HingeJoint() override = default; + + /// Deleted copy-constructor + HingeJoint(const HingeJoint& constraint) = delete; + + /// Deleted assignment operator + HingeJoint& operator=(const HingeJoint& constraint) = delete; /// Return true if the limits or the joint are enabled bool isLimitEnabled() const; diff --git a/src/constraint/Joint.cpp b/src/constraint/Joint.cpp index 22f40932..2c0695ab 100644 --- a/src/constraint/Joint.cpp +++ b/src/constraint/Joint.cpp @@ -34,11 +34,6 @@ Joint::Joint(const JointInfo& jointInfo) mPositionCorrectionTechnique(jointInfo.positionCorrectionTechnique), mIsCollisionEnabled(jointInfo.isCollisionEnabled), mIsAlreadyInIsland(false) { - assert(mBody1 != NULL); - assert(mBody2 != NULL); -} - -// Destructor -Joint::~Joint() { - + assert(mBody1 != nullptr); + assert(mBody2 != nullptr); } diff --git a/src/constraint/Joint.h b/src/constraint/Joint.h index b5ec520d..ead08a53 100644 --- a/src/constraint/Joint.h +++ b/src/constraint/Joint.h @@ -35,7 +35,7 @@ namespace reactphysics3d { /// Enumeration for the type of a constraint -enum JointType {BALLSOCKETJOINT, SLIDERJOINT, HINGEJOINT, FIXEDJOINT}; +enum class JointType {BALLSOCKETJOINT, SLIDERJOINT, HINGEJOINT, FIXEDJOINT}; // Class declarations struct ConstraintSolverData; @@ -94,19 +94,19 @@ struct JointInfo { /// Constructor JointInfo(JointType constraintType) - : body1(NULL), body2(NULL), type(constraintType), - positionCorrectionTechnique(NON_LINEAR_GAUSS_SEIDEL), + : body1(nullptr), body2(nullptr), type(constraintType), + positionCorrectionTechnique(JointsPositionCorrectionTechnique::NON_LINEAR_GAUSS_SEIDEL), isCollisionEnabled(true) {} /// Constructor JointInfo(RigidBody* rigidBody1, RigidBody* rigidBody2, JointType constraintType) : body1(rigidBody1), body2(rigidBody2), type(constraintType), - positionCorrectionTechnique(NON_LINEAR_GAUSS_SEIDEL), + positionCorrectionTechnique(JointsPositionCorrectionTechnique::NON_LINEAR_GAUSS_SEIDEL), isCollisionEnabled(true) { } /// Destructor - virtual ~JointInfo() {} + virtual ~JointInfo() = default; }; @@ -146,12 +146,6 @@ class Joint { // -------------------- Methods -------------------- // - /// Private copy-constructor - Joint(const Joint& constraint); - - /// Private assignment operator - Joint& operator=(const Joint& constraint); - /// Return true if the joint has already been added into an island bool isAlreadyInIsland() const; @@ -178,7 +172,13 @@ class Joint { Joint(const JointInfo& jointInfo); /// Destructor - virtual ~Joint(); + virtual ~Joint() = default; + + /// Deleted copy-constructor + Joint(const Joint& constraint) = delete; + + /// Deleted assignment operator + Joint& operator=(const Joint& constraint) = delete; /// Return the reference to the body 1 RigidBody* getBody1() const; diff --git a/src/constraint/SliderJoint.cpp b/src/constraint/SliderJoint.cpp index 99a5c834..efe7cbff 100644 --- a/src/constraint/SliderJoint.cpp +++ b/src/constraint/SliderJoint.cpp @@ -29,7 +29,7 @@ using namespace reactphysics3d; // Static variables definition -const decimal SliderJoint::BETA = decimal(0.2); +constexpr decimal SliderJoint::BETA = decimal(0.2); // Constructor SliderJoint::SliderJoint(const SliderJointInfo& jointInfo) @@ -63,11 +63,6 @@ SliderJoint::SliderJoint(const SliderJointInfo& jointInfo) mSliderAxisBody1.normalize(); } -// Destructor -SliderJoint::~SliderJoint() { - -} - // Initialize before solving the constraint void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverData) { @@ -139,14 +134,14 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa mR2CrossN2.dot(I2R2CrossN2); Matrix2x2 matrixKTranslation(el11, el12, el21, el22); mInverseMassMatrixTranslationConstraint.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixTranslationConstraint = matrixKTranslation.getInverse(); } // Compute the bias "b" of the translation constraint mBTranslation.setToZero(); decimal biasFactor = (BETA / constraintSolverData.timeStep); - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mBTranslation.x = u.dot(mN1); mBTranslation.y = u.dot(mN2); mBTranslation *= biasFactor; @@ -155,13 +150,13 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa // Compute the inverse of the mass matrix K=JM^-1J^t for the 3 rotation // contraints (3x3 matrix) mInverseMassMatrixRotationConstraint = mI1 + mI2; - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixRotationConstraint = mInverseMassMatrixRotationConstraint.getInverse(); } // Compute the bias "b" of the rotation constraint mBRotation.setToZero(); - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { Quaternion currentOrientationDifference = orientationBody2 * orientationBody1.getInverse(); currentOrientationDifference.normalize(); const Quaternion qError = currentOrientationDifference * mInitOrientationDifferenceInv; @@ -180,13 +175,13 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa // Compute the bias "b" of the lower limit constraint mBLowerLimit = 0.0; - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mBLowerLimit = biasFactor * lowerLimitError; } // Compute the bias "b" of the upper limit constraint mBUpperLimit = 0.0; - if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) { + if (mPositionCorrectionTechnique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mBUpperLimit = biasFactor * upperLimitError; } } @@ -433,7 +428,7 @@ void SliderJoint::solvePositionConstraint(const ConstraintSolverData& constraint // If the error position correction technique is not the non-linear-gauss-seidel, we do // do not execute this method - if (mPositionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return; + if (mPositionCorrectionTechnique != JointsPositionCorrectionTechnique::NON_LINEAR_GAUSS_SEIDEL) return; // Get the bodies positions and orientations Vector3& x1 = constraintSolverData.positions[mIndexBody1]; @@ -497,7 +492,7 @@ void SliderJoint::solvePositionConstraint(const ConstraintSolverData& constraint mR2CrossN2.dot(I2R2CrossN2); Matrix2x2 matrixKTranslation(el11, el12, el21, el22); mInverseMassMatrixTranslationConstraint.setToZero(); - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixTranslationConstraint = matrixKTranslation.getInverse(); } @@ -540,7 +535,7 @@ void SliderJoint::solvePositionConstraint(const ConstraintSolverData& constraint // Compute the inverse of the mass matrix K=JM^-1J^t for the 3 rotation // contraints (3x3 matrix) mInverseMassMatrixRotationConstraint = mI1 + mI2; - if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) { + if (mBody1->getType() == BodyType::DYNAMIC || mBody2->getType() == BodyType::DYNAMIC) { mInverseMassMatrixRotationConstraint = mInverseMassMatrixRotationConstraint.getInverse(); } diff --git a/src/constraint/SliderJoint.h b/src/constraint/SliderJoint.h index c40526d4..e01a9ab4 100644 --- a/src/constraint/SliderJoint.h +++ b/src/constraint/SliderJoint.h @@ -77,7 +77,7 @@ struct SliderJointInfo : public JointInfo { SliderJointInfo(RigidBody* rigidBody1, RigidBody* rigidBody2, const Vector3& initAnchorPointWorldSpace, const Vector3& initSliderAxisWorldSpace) - : JointInfo(rigidBody1, rigidBody2, SLIDERJOINT), + : JointInfo(rigidBody1, rigidBody2, JointType::SLIDERJOINT), anchorPointWorldSpace(initAnchorPointWorldSpace), sliderAxisWorldSpace(initSliderAxisWorldSpace), isLimitEnabled(false), isMotorEnabled(false), minTranslationLimit(-1.0), @@ -96,7 +96,7 @@ struct SliderJointInfo : public JointInfo { const Vector3& initAnchorPointWorldSpace, const Vector3& initSliderAxisWorldSpace, decimal initMinTranslationLimit, decimal initMaxTranslationLimit) - : JointInfo(rigidBody1, rigidBody2, SLIDERJOINT), + : JointInfo(rigidBody1, rigidBody2, JointType::SLIDERJOINT), anchorPointWorldSpace(initAnchorPointWorldSpace), sliderAxisWorldSpace(initSliderAxisWorldSpace), isLimitEnabled(true), isMotorEnabled(false), @@ -120,7 +120,7 @@ struct SliderJointInfo : public JointInfo { const Vector3& initSliderAxisWorldSpace, decimal initMinTranslationLimit, decimal initMaxTranslationLimit, decimal initMotorSpeed, decimal initMaxMotorForce) - : JointInfo(rigidBody1, rigidBody2, SLIDERJOINT), + : JointInfo(rigidBody1, rigidBody2, JointType::SLIDERJOINT), anchorPointWorldSpace(initAnchorPointWorldSpace), sliderAxisWorldSpace(initSliderAxisWorldSpace), isLimitEnabled(true), isMotorEnabled(true), @@ -262,29 +262,23 @@ class SliderJoint : public Joint { // -------------------- Methods -------------------- // - /// Private copy-constructor - SliderJoint(const SliderJoint& constraint); - - /// Private assignment operator - SliderJoint& operator=(const SliderJoint& constraint); - /// Reset the limits void resetLimits(); /// Return the number of bytes used by the joint - virtual size_t getSizeInBytes() const; + virtual size_t getSizeInBytes() const override; /// Initialize before solving the constraint - virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData); + virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData) override; /// Warm start the constraint (apply the previous impulse at the beginning of the step) - virtual void warmstart(const ConstraintSolverData& constraintSolverData); + virtual void warmstart(const ConstraintSolverData& constraintSolverData) override; /// Solve the velocity constraint - virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData); + virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) override; /// Solve the position constraint (for position error correction) - virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData); + virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData) override; public : @@ -294,7 +288,13 @@ class SliderJoint : public Joint { SliderJoint(const SliderJointInfo& jointInfo); /// Destructor - virtual ~SliderJoint(); + virtual ~SliderJoint() override = default; + + /// Deleted copy-constructor + SliderJoint(const SliderJoint& constraint) = delete; + + /// Deleted assignment operator + SliderJoint& operator=(const SliderJoint& constraint) = delete; /// Return true if the limits or the joint are enabled bool isLimitEnabled() const; diff --git a/src/decimal.h b/src/decimal.h index 41cf2881..2c95e8b9 100644 --- a/src/decimal.h +++ b/src/decimal.h @@ -30,9 +30,9 @@ namespace reactphysics3d { #if defined(IS_DOUBLE_PRECISION_ENABLED) // If we are compiling for double precision - typedef double decimal; + using decimal = double; #else // If we are compiling for single precision - typedef float decimal; + using decimal = float; #endif } diff --git a/src/engine/CollisionWorld.cpp b/src/engine/CollisionWorld.cpp index ddc4a7b5..68e37625 100644 --- a/src/engine/CollisionWorld.cpp +++ b/src/engine/CollisionWorld.cpp @@ -34,7 +34,7 @@ using namespace std; // Constructor CollisionWorld::CollisionWorld() : mCollisionDetection(this, mMemoryAllocator), mCurrentBodyID(0), - mEventListener(NULL) { + mEventListener(nullptr) { } @@ -69,7 +69,7 @@ CollisionBody* CollisionWorld::createCollisionBody(const Transform& transform) { CollisionBody* collisionBody = new (mMemoryAllocator.allocate(sizeof(CollisionBody))) CollisionBody(transform, *this, bodyID); - assert(collisionBody != NULL); + assert(collisionBody != nullptr); // Add the collision body to the world mBodies.insert(collisionBody); @@ -208,7 +208,7 @@ void CollisionWorld::testCollision(const CollisionBody* body, std::set shapes1; // For each shape of the body - for (const ProxyShape* shape=body->getProxyShapesList(); shape != NULL; + for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { shapes1.insert(shape->mBroadPhaseID); } @@ -234,13 +234,13 @@ void CollisionWorld::testCollision(const CollisionBody* body1, // Create the sets of shapes std::set shapes1; - for (const ProxyShape* shape=body1->getProxyShapesList(); shape != NULL; + for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { shapes1.insert(shape->mBroadPhaseID); } std::set shapes2; - for (const ProxyShape* shape=body2->getProxyShapesList(); shape != NULL; + for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { shapes2.insert(shape->mBroadPhaseID); } diff --git a/src/engine/CollisionWorld.h b/src/engine/CollisionWorld.h index 91560935..77189e89 100644 --- a/src/engine/CollisionWorld.h +++ b/src/engine/CollisionWorld.h @@ -80,12 +80,6 @@ class CollisionWorld { // -------------------- Methods -------------------- // - /// Private copy-constructor - CollisionWorld(const CollisionWorld& world); - - /// Private assignment operator - CollisionWorld& operator=(const CollisionWorld& world); - /// Return the next available body ID bodyindex computeNextAvailableBodyID(); @@ -102,6 +96,12 @@ class CollisionWorld { /// Destructor virtual ~CollisionWorld(); + /// Deleted copy-constructor + CollisionWorld(const CollisionWorld& world) = delete; + + /// Deleted assignment operator + CollisionWorld& operator=(const CollisionWorld& world) = delete; + /// Return an iterator to the beginning of the bodies of the physics world std::set::iterator getBodiesBeginIterator(); diff --git a/src/engine/ConstraintSolver.cpp b/src/engine/ConstraintSolver.cpp index 64a9264e..547aea6e 100644 --- a/src/engine/ConstraintSolver.cpp +++ b/src/engine/ConstraintSolver.cpp @@ -36,17 +36,12 @@ ConstraintSolver::ConstraintSolver(const std::map& mapBodyToVe } -// Destructor -ConstraintSolver::~ConstraintSolver() { - -} - // Initialize the constraint solver for a given island void ConstraintSolver::initializeForIsland(decimal dt, Island* island) { PROFILE("ConstraintSolver::initializeForIsland()"); - assert(island != NULL); + assert(island != nullptr); assert(island->getNbBodies() > 0); assert(island->getNbJoints() > 0); @@ -76,7 +71,7 @@ void ConstraintSolver::solveVelocityConstraints(Island* island) { PROFILE("ConstraintSolver::solveVelocityConstraints()"); - assert(island != NULL); + assert(island != nullptr); assert(island->getNbJoints() > 0); // For each joint of the island @@ -93,7 +88,7 @@ void ConstraintSolver::solvePositionConstraints(Island* island) { PROFILE("ConstraintSolver::solvePositionConstraints()"); - assert(island != NULL); + assert(island != nullptr); assert(island->getNbJoints() > 0); // For each joint of the island diff --git a/src/engine/ConstraintSolver.h b/src/engine/ConstraintSolver.h index cd9e5292..b40cc983 100644 --- a/src/engine/ConstraintSolver.h +++ b/src/engine/ConstraintSolver.h @@ -69,8 +69,8 @@ struct ConstraintSolverData { /// Constructor ConstraintSolverData(const std::map& refMapBodyToConstrainedVelocityIndex) - :linearVelocities(NULL), angularVelocities(NULL), - positions(NULL), orientations(NULL), + :linearVelocities(nullptr), angularVelocities(nullptr), + positions(nullptr), orientations(nullptr), mapBodyToConstrainedVelocityIndex(refMapBodyToConstrainedVelocityIndex){ } @@ -173,7 +173,7 @@ class ConstraintSolver { ConstraintSolver(const std::map& mapBodyToVelocityIndex); /// Destructor - ~ConstraintSolver(); + ~ConstraintSolver() = default; /// Initialize the constraint solver for a given island void initializeForIsland(decimal dt, Island* island); @@ -202,6 +202,10 @@ class ConstraintSolver { // Set the constrained velocities arrays inline void ConstraintSolver::setConstrainedVelocitiesArrays(Vector3* constrainedLinearVelocities, Vector3* constrainedAngularVelocities) { + + assert(constrainedLinearVelocities != nullptr); + assert(constrainedAngularVelocities != nullptr); + mConstraintSolverData.linearVelocities = constrainedLinearVelocities; mConstraintSolverData.angularVelocities = constrainedAngularVelocities; } @@ -209,6 +213,10 @@ inline void ConstraintSolver::setConstrainedVelocitiesArrays(Vector3* constraine // Set the constrained positions/orientations arrays inline void ConstraintSolver::setConstrainedPositionsArrays(Vector3* constrainedPositions, Quaternion* constrainedOrientations) { + + assert(constrainedPositions != nullptr); + assert(constrainedOrientations != nullptr); + mConstraintSolverData.positions = constrainedPositions; mConstraintSolverData.orientations = constrainedOrientations; } diff --git a/src/engine/ContactSolver.cpp b/src/engine/ContactSolver.cpp index 076cf5e2..a11cc2e9 100644 --- a/src/engine/ContactSolver.cpp +++ b/src/engine/ContactSolver.cpp @@ -34,35 +34,30 @@ using namespace reactphysics3d; using namespace std; // Constants initialization -const decimal ContactSolver::BETA = decimal(0.2); -const decimal ContactSolver::BETA_SPLIT_IMPULSE = decimal(0.2); -const decimal ContactSolver::SLOP= decimal(0.01); +constexpr decimal ContactSolver::BETA = decimal(0.2); +constexpr decimal ContactSolver::BETA_SPLIT_IMPULSE = decimal(0.2); +constexpr decimal ContactSolver::SLOP= decimal(0.01); // Constructor ContactSolver::ContactSolver(const std::map& mapBodyToVelocityIndex) - :mSplitLinearVelocities(NULL), mSplitAngularVelocities(NULL), - mContactConstraints(NULL), mLinearVelocities(NULL), mAngularVelocities(NULL), + :mSplitLinearVelocities(nullptr), mSplitAngularVelocities(nullptr), + mContactConstraints(nullptr), mLinearVelocities(nullptr), mAngularVelocities(nullptr), mMapBodyToConstrainedVelocityIndex(mapBodyToVelocityIndex), mIsWarmStartingActive(true), mIsSplitImpulseActive(true), mIsSolveFrictionAtContactManifoldCenterActive(true) { } -// Destructor -ContactSolver::~ContactSolver() { - -} - // Initialize the constraint solver for a given island void ContactSolver::initializeForIsland(decimal dt, Island* island) { PROFILE("ContactSolver::initializeForIsland()"); - assert(island != NULL); + assert(island != nullptr); assert(island->getNbBodies() > 0); assert(island->getNbContactManifolds() > 0); - assert(mSplitLinearVelocities != NULL); - assert(mSplitAngularVelocities != NULL); + assert(mSplitLinearVelocities != nullptr); + assert(mSplitAngularVelocities != nullptr); // Set the current time step mTimeStep = dt; @@ -70,7 +65,7 @@ void ContactSolver::initializeForIsland(decimal dt, Island* island) { mNbContactManifolds = island->getNbContactManifolds(); mContactConstraints = new ContactManifoldSolver[mNbContactManifolds]; - assert(mContactConstraints != NULL); + assert(mContactConstraints != nullptr); // For each contact manifold of the island ContactManifold** contactManifolds = island->getContactManifold(); @@ -85,8 +80,8 @@ void ContactSolver::initializeForIsland(decimal dt, Island* island) { // Get the two bodies of the contact RigidBody* body1 = static_cast(externalManifold->getContactPoint(0)->getBody1()); RigidBody* body2 = static_cast(externalManifold->getContactPoint(0)->getBody2()); - assert(body1 != NULL); - assert(body2 != NULL); + assert(body1 != nullptr); + assert(body2 != nullptr); // Get the position of the two bodies const Vector3& x1 = body1->mCenterOfMassWorld; @@ -105,8 +100,8 @@ void ContactSolver::initializeForIsland(decimal dt, Island* island) { internalManifold.frictionCoefficient = computeMixedFrictionCoefficient(body1, body2); internalManifold.rollingResistanceFactor = computeMixedRollingResistance(body1, body2); internalManifold.externalContactManifold = externalManifold; - internalManifold.isBody1DynamicType = body1->getType() == DYNAMIC; - internalManifold.isBody2DynamicType = body2->getType() == DYNAMIC; + internalManifold.isBody1DynamicType = body1->getType() == BodyType::DYNAMIC; + internalManifold.isBody2DynamicType = body2->getType() == BodyType::DYNAMIC; // If we solve the friction constraints at the center of the contact manifold if (mIsSolveFrictionAtContactManifoldCenterActive) { @@ -906,8 +901,8 @@ void ContactSolver::computeFrictionVectors(const Vector3& deltaVelocity, // Clean up the constraint solver void ContactSolver::cleanup() { - if (mContactConstraints != NULL) { + if (mContactConstraints != nullptr) { delete[] mContactConstraints; - mContactConstraints = NULL; + mContactConstraints = nullptr; } } diff --git a/src/engine/ContactSolver.h b/src/engine/ContactSolver.h index 82b89892..ae2005f4 100644 --- a/src/engine/ContactSolver.h +++ b/src/engine/ContactSolver.h @@ -413,7 +413,7 @@ class ContactSolver { ContactSolver(const std::map& mapBodyToVelocityIndex); /// Destructor - virtual ~ContactSolver(); + ~ContactSolver() = default; /// Initialize the constraint solver for a given island void initializeForIsland(decimal dt, Island* island); @@ -453,6 +453,10 @@ class ContactSolver { // Set the split velocities arrays inline void ContactSolver::setSplitVelocitiesArrays(Vector3* splitLinearVelocities, Vector3* splitAngularVelocities) { + + assert(splitLinearVelocities != nullptr); + assert(splitAngularVelocities != nullptr); + mSplitLinearVelocities = splitLinearVelocities; mSplitAngularVelocities = splitAngularVelocities; } @@ -460,6 +464,10 @@ inline void ContactSolver::setSplitVelocitiesArrays(Vector3* splitLinearVelociti // Set the constrained velocities arrays inline void ContactSolver::setConstrainedVelocitiesArrays(Vector3* constrainedLinearVelocities, Vector3* constrainedAngularVelocities) { + + assert(constrainedLinearVelocities != nullptr); + assert(constrainedAngularVelocities != nullptr); + mLinearVelocities = constrainedLinearVelocities; mAngularVelocities = constrainedAngularVelocities; } diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index f0725eba..2f601edd 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -45,11 +45,11 @@ DynamicsWorld::DynamicsWorld(const Vector3 &gravity) mNbVelocitySolverIterations(DEFAULT_VELOCITY_SOLVER_NB_ITERATIONS), mNbPositionSolverIterations(DEFAULT_POSITION_SOLVER_NB_ITERATIONS), mIsSleepingEnabled(SPLEEPING_ENABLED), mGravity(gravity), - mIsGravityEnabled(true), mConstrainedLinearVelocities(NULL), - mConstrainedAngularVelocities(NULL), mSplitLinearVelocities(NULL), - mSplitAngularVelocities(NULL), mConstrainedPositions(NULL), - mConstrainedOrientations(NULL), mNbIslands(0), - mNbIslandsCapacity(0), mIslands(NULL), mNbBodiesCapacity(0), + mIsGravityEnabled(true), mConstrainedLinearVelocities(nullptr), + mConstrainedAngularVelocities(nullptr), mSplitLinearVelocities(nullptr), + mSplitAngularVelocities(nullptr), mConstrainedPositions(nullptr), + mConstrainedOrientations(nullptr), mNbIslands(0), + mNbIslandsCapacity(0), mIslands(nullptr), mNbBodiesCapacity(0), mSleepLinearVelocity(DEFAULT_SLEEP_LINEAR_VELOCITY), mSleepAngularVelocity(DEFAULT_SLEEP_ANGULAR_VELOCITY), mTimeBeforeSleep(DEFAULT_TIME_BEFORE_SLEEP) { @@ -128,7 +128,7 @@ void DynamicsWorld::update(decimal timeStep) { mTimeStep = timeStep; // Notify the event listener about the beginning of an internal tick - if (mEventListener != NULL) mEventListener->beginInternalTick(); + if (mEventListener != nullptr) mEventListener->beginInternalTick(); // Reset all the contact manifolds lists of each body resetContactManifoldListsOfBodies(); @@ -157,7 +157,7 @@ void DynamicsWorld::update(decimal timeStep) { if (mIsSleepingEnabled) updateSleepingBodies(); // Notify the event listener about the end of an internal tick - if (mEventListener != NULL) mEventListener->endInternalTick(); + if (mEventListener != nullptr) mEventListener->endInternalTick(); // Reset the external force and torque applied to the bodies resetBodiesForceAndTorque(); @@ -256,12 +256,12 @@ void DynamicsWorld::initVelocityArrays() { mConstrainedAngularVelocities = new Vector3[mNbBodiesCapacity]; mConstrainedPositions = new Vector3[mNbBodiesCapacity]; mConstrainedOrientations = new Quaternion[mNbBodiesCapacity]; - assert(mSplitLinearVelocities != NULL); - assert(mSplitAngularVelocities != NULL); - assert(mConstrainedLinearVelocities != NULL); - assert(mConstrainedAngularVelocities != NULL); - assert(mConstrainedPositions != NULL); - assert(mConstrainedOrientations != NULL); + assert(mSplitLinearVelocities != nullptr); + assert(mSplitAngularVelocities != nullptr); + assert(mConstrainedLinearVelocities != nullptr); + assert(mConstrainedAngularVelocities != nullptr); + assert(mConstrainedPositions != nullptr); + assert(mConstrainedOrientations != nullptr); } // Reset the velocities arrays @@ -448,7 +448,7 @@ RigidBody* DynamicsWorld::createRigidBody(const Transform& transform) { // Create the rigid body RigidBody* rigidBody = new (mMemoryAllocator.allocate(sizeof(RigidBody))) RigidBody(transform, *this, bodyID); - assert(rigidBody != NULL); + assert(rigidBody != nullptr); // Add the rigid body to the physics world mBodies.insert(rigidBody); @@ -472,7 +472,7 @@ void DynamicsWorld::destroyRigidBody(RigidBody* rigidBody) { // Destroy all the joints in which the rigid body to be destroyed is involved JointListElement* element; - for (element = rigidBody->mJointsList; element != NULL; element = element->next) { + for (element = rigidBody->mJointsList; element != nullptr; element = element->next) { destroyJoint(element->joint); } @@ -497,13 +497,13 @@ void DynamicsWorld::destroyRigidBody(RigidBody* rigidBody) { */ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) { - Joint* newJoint = NULL; + Joint* newJoint = nullptr; // Allocate memory to create the new joint switch(jointInfo.type) { // Ball-and-Socket joint - case BALLSOCKETJOINT: + case JointType::BALLSOCKETJOINT: { void* allocatedMemory = mMemoryAllocator.allocate(sizeof(BallAndSocketJoint)); const BallAndSocketJointInfo& info = static_cast( @@ -513,7 +513,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) { } // Slider joint - case SLIDERJOINT: + case JointType::SLIDERJOINT: { void* allocatedMemory = mMemoryAllocator.allocate(sizeof(SliderJoint)); const SliderJointInfo& info = static_cast(jointInfo); @@ -522,7 +522,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) { } // Hinge joint - case HINGEJOINT: + case JointType::HINGEJOINT: { void* allocatedMemory = mMemoryAllocator.allocate(sizeof(HingeJoint)); const HingeJointInfo& info = static_cast(jointInfo); @@ -531,7 +531,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) { } // Fixed joint - case FIXEDJOINT: + case JointType::FIXEDJOINT: { void* allocatedMemory = mMemoryAllocator.allocate(sizeof(FixedJoint)); const FixedJointInfo& info = static_cast(jointInfo); @@ -542,7 +542,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) { default: { assert(false); - return NULL; + return nullptr; } } @@ -569,7 +569,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) { */ void DynamicsWorld::destroyJoint(Joint* joint) { - assert(joint != NULL); + assert(joint != nullptr); // If the collision between the two bodies of the constraint was disabled if (!joint->isCollisionEnabled()) { @@ -601,7 +601,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) { // Add the joint to the list of joints of the two bodies involved in the joint void DynamicsWorld::addJointToBody(Joint* joint) { - assert(joint != NULL); + assert(joint != nullptr); // Add the joint at the beginning of the linked list of joints of the first body void* allocatedMemory1 = mMemoryAllocator.allocate(sizeof(JointListElement)); @@ -673,7 +673,7 @@ void DynamicsWorld::computeIslands() { if (body->mIsAlreadyInIsland) continue; // If the body is static, we go to the next body - if (body->getType() == STATIC) continue; + if (body->getType() == BodyType::STATIC) continue; // If the body is sleeping or inactive, we go to the next body if (body->isSleeping() || !body->isActive()) continue; @@ -706,11 +706,11 @@ void DynamicsWorld::computeIslands() { // If the current body is static, we do not want to perform the DFS // search across that body - if (bodyToVisit->getType() == STATIC) continue; + if (bodyToVisit->getType() == BodyType::STATIC) continue; // For each contact manifold in which the current body is involded ContactManifoldListElement* contactElement; - for (contactElement = bodyToVisit->mContactManifoldsList; contactElement != NULL; + for (contactElement = bodyToVisit->mContactManifoldsList; contactElement != nullptr; contactElement = contactElement->next) { ContactManifold* contactManifold = contactElement->contactManifold; @@ -740,7 +740,7 @@ void DynamicsWorld::computeIslands() { // For each joint in which the current body is involved JointListElement* jointElement; - for (jointElement = bodyToVisit->mJointsList; jointElement != NULL; + for (jointElement = bodyToVisit->mJointsList; jointElement != nullptr; jointElement = jointElement->next) { Joint* joint = jointElement->joint; @@ -771,7 +771,7 @@ void DynamicsWorld::computeIslands() { // can also be included in the other islands for (uint i=0; i < mIslands[mNbIslands]->mNbBodies; i++) { - if (mIslands[mNbIslands]->mBodies[i]->getType() == STATIC) { + if (mIslands[mNbIslands]->mBodies[i]->getType() == BodyType::STATIC) { mIslands[mNbIslands]->mBodies[i]->mIsAlreadyInIsland = false; } } @@ -803,7 +803,7 @@ void DynamicsWorld::updateSleepingBodies() { for (uint b=0; b < mIslands[i]->getNbBodies(); b++) { // Skip static bodies - if (bodies[b]->getType() == STATIC) continue; + if (bodies[b]->getType() == BodyType::STATIC) continue; // If the body is velocity is large enough to stay awake if (bodies[b]->getLinearVelocity().lengthSquare() > sleepLinearVelocitySquare || @@ -916,7 +916,7 @@ void DynamicsWorld::testCollision(const CollisionBody* body, std::set shapes1; // For each shape of the body - for (const ProxyShape* shape=body->getProxyShapesList(); shape != NULL; + for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { shapes1.insert(shape->mBroadPhaseID); } @@ -941,13 +941,13 @@ void DynamicsWorld::testCollision(const CollisionBody* body1, // Create the sets of shapes std::set shapes1; - for (const ProxyShape* shape=body1->getProxyShapesList(); shape != NULL; + for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { shapes1.insert(shape->mBroadPhaseID); } std::set shapes2; - for (const ProxyShape* shape=body2->getProxyShapesList(); shape != NULL; + for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { shapes2.insert(shape->mBroadPhaseID); } diff --git a/src/engine/DynamicsWorld.h b/src/engine/DynamicsWorld.h index 11e49124..7dc715c9 100644 --- a/src/engine/DynamicsWorld.h +++ b/src/engine/DynamicsWorld.h @@ -127,12 +127,6 @@ class DynamicsWorld : public CollisionWorld { // -------------------- Methods -------------------- // - /// Private copy-constructor - DynamicsWorld(const DynamicsWorld& world); - - /// Private assignment operator - DynamicsWorld& operator=(const DynamicsWorld& world); - /// Integrate the positions and orientations of rigid bodies. void integrateRigidBodiesPositions(); @@ -184,7 +178,13 @@ class DynamicsWorld : public CollisionWorld { DynamicsWorld(const Vector3& mGravity); /// Destructor - virtual ~DynamicsWorld(); + virtual ~DynamicsWorld() override; + + /// Deleted copy-constructor + DynamicsWorld(const DynamicsWorld& world) = delete; + + /// Deleted assignment operator + DynamicsWorld& operator=(const DynamicsWorld& world) = delete; /// Update the physics simulation void update(decimal timeStep); @@ -277,25 +277,25 @@ class DynamicsWorld : public CollisionWorld { /// Test and report collisions between a given shape and all the others /// shapes of the world virtual void testCollision(const ProxyShape* shape, - CollisionCallback* callback); + CollisionCallback* callback) override; /// Test and report collisions between two given shapes virtual void testCollision(const ProxyShape* shape1, const ProxyShape* shape2, - CollisionCallback* callback); + CollisionCallback* callback) override; /// Test and report collisions between a body and all /// the others bodies of the world virtual void testCollision(const CollisionBody* body, - CollisionCallback* callback); + CollisionCallback* callback) override; /// Test and report collisions between two bodies virtual void testCollision(const CollisionBody* body1, const CollisionBody* body2, - CollisionCallback* callback); + CollisionCallback* callback) override; /// Test and report collisions between all shapes of the world - virtual void testCollision(CollisionCallback* callback); + virtual void testCollision(CollisionCallback* callback) override; /// Return the list of all contacts of the world std::vector getContactsList() const; @@ -348,7 +348,7 @@ inline void DynamicsWorld::setNbIterationsPositionSolver(uint nbIterations) { */ inline void DynamicsWorld::setContactsPositionCorrectionTechnique( ContactsPositionCorrectionTechnique technique) { - if (technique == BAUMGARTE_CONTACTS) { + if (technique == ContactsPositionCorrectionTechnique::BAUMGARTE_CONTACTS) { mContactSolver.setIsSplitImpulseActive(false); } else { @@ -362,7 +362,7 @@ inline void DynamicsWorld::setContactsPositionCorrectionTechnique( */ inline void DynamicsWorld::setJointsPositionCorrectionTechnique( JointsPositionCorrectionTechnique technique) { - if (technique == BAUMGARTE_JOINTS) { + if (technique == JointsPositionCorrectionTechnique::BAUMGARTE_JOINTS) { mConstraintSolver.setIsNonLinearGaussSeidelPositionCorrectionActive(false); } else { @@ -512,7 +512,7 @@ inline void DynamicsWorld::setTimeBeforeSleep(decimal timeBeforeSleep) { } // Set an event listener object to receive events callbacks. -/// If you use NULL as an argument, the events callbacks will be disabled. +/// If you use "nullptr" as an argument, the events callbacks will be disabled. /** * @param eventListener Pointer to the event listener object that will receive * event callbacks during the simulation diff --git a/src/engine/EventListener.h b/src/engine/EventListener.h index 4df79259..562e8ac7 100644 --- a/src/engine/EventListener.h +++ b/src/engine/EventListener.h @@ -44,16 +44,16 @@ class EventListener { public : /// Constructor - EventListener() {} + EventListener() = default; /// Destructor - virtual ~EventListener() {} + virtual ~EventListener() = default; /// Called when a new contact point is found between two bodies that were separated before /** * @param contact Information about the contact */ - virtual void beginContact(const ContactPointInfo& contact) {}; + virtual void beginContact(const ContactPointInfo& contact) {} /// Called when a new contact point is found between two bodies /** diff --git a/src/engine/Impulse.h b/src/engine/Impulse.h index 8c2bef33..89e36429 100644 --- a/src/engine/Impulse.h +++ b/src/engine/Impulse.h @@ -41,9 +41,6 @@ struct Impulse { // -------------------- Methods -------------------- // - /// Private assignment operator - Impulse& operator=(const Impulse& impulse); - public: // -------------------- Attributes -------------------- // @@ -78,8 +75,11 @@ struct Impulse { angularImpulseBody1(impulse.angularImpulseBody1), linearImpulseBody2(impulse.linearImpulseBody2), angularImpulseBody2(impulse.angularImpulseBody2) { -; + } + + /// Deleted assignment operator + Impulse& operator=(const Impulse& impulse) = delete; }; } diff --git a/src/engine/Island.cpp b/src/engine/Island.cpp index 57a7f43f..41560bde 100644 --- a/src/engine/Island.cpp +++ b/src/engine/Island.cpp @@ -31,7 +31,7 @@ using namespace reactphysics3d; // Constructor Island::Island(uint nbMaxBodies, uint nbMaxContactManifolds, uint nbMaxJoints, MemoryAllocator& memoryAllocator) - : mBodies(NULL), mContactManifolds(NULL), mJoints(NULL), mNbBodies(0), + : mBodies(nullptr), mContactManifolds(nullptr), mJoints(nullptr), mNbBodies(0), mNbContactManifolds(0), mNbJoints(0), mMemoryAllocator(memoryAllocator) { // Allocate memory for the arrays diff --git a/src/engine/Island.h b/src/engine/Island.h index 6be38d5e..1b086939 100644 --- a/src/engine/Island.h +++ b/src/engine/Island.h @@ -75,14 +75,6 @@ class Island { /// Number of bytes allocated for the joints array size_t mNbAllocatedBytesJoints; - // -------------------- Methods -------------------- // - - /// Private assignment operator - Island& operator=(const Island& island); - - /// Private copy-constructor - Island(const Island& island); - public: // -------------------- Methods -------------------- // @@ -94,6 +86,12 @@ class Island { /// Destructor ~Island(); + /// Deleted assignment operator + Island& operator=(const Island& island) = delete; + + /// Deleted copy-constructor + Island(const Island& island) = delete; + /// Add a body into the island void addBody(RigidBody* body); diff --git a/src/engine/Material.cpp b/src/engine/Material.cpp index 4dc99647..f0484c96 100644 --- a/src/engine/Material.cpp +++ b/src/engine/Material.cpp @@ -42,8 +42,3 @@ Material::Material(const Material& material) mRollingResistance(material.mRollingResistance), mBounciness(material.mBounciness) { } - -// Destructor -Material::~Material() { - -} diff --git a/src/engine/Material.h b/src/engine/Material.h index c820cb93..ca5fd532 100644 --- a/src/engine/Material.h +++ b/src/engine/Material.h @@ -64,7 +64,7 @@ class Material { Material(const Material& material); /// Destructor - ~Material(); + ~Material() = default; /// Return the bounciness decimal getBounciness() const; diff --git a/src/engine/OverlappingPair.cpp b/src/engine/OverlappingPair.cpp index 9c4814b5..7efca599 100644 --- a/src/engine/OverlappingPair.cpp +++ b/src/engine/OverlappingPair.cpp @@ -35,9 +35,4 @@ OverlappingPair::OverlappingPair(ProxyShape* shape1, ProxyShape* shape2, : mContactManifoldSet(shape1, shape2, memoryAllocator, nbMaxContactManifolds), mCachedSeparatingAxis(0.0, 1.0, 0.0) { -} - -// Destructor -OverlappingPair::~OverlappingPair() { - -} +} diff --git a/src/engine/OverlappingPair.h b/src/engine/OverlappingPair.h index d230afe2..7995b0d2 100644 --- a/src/engine/OverlappingPair.h +++ b/src/engine/OverlappingPair.h @@ -35,7 +35,7 @@ namespace reactphysics3d { // Type for the overlapping pair ID -typedef std::pair overlappingpairid; +using overlappingpairid = std::pair; // Class OverlappingPair /** @@ -56,14 +56,6 @@ class OverlappingPair { /// Cached previous separating axis Vector3 mCachedSeparatingAxis; - - // -------------------- Methods -------------------- // - - /// Private copy-constructor - OverlappingPair(const OverlappingPair& pair); - - /// Private assignment operator - OverlappingPair& operator=(const OverlappingPair& pair); public: @@ -74,7 +66,13 @@ class OverlappingPair { int nbMaxContactManifolds, MemoryAllocator& memoryAllocator); /// Destructor - ~OverlappingPair(); + ~OverlappingPair() = default; + + /// Deleted copy-constructor + OverlappingPair(const OverlappingPair& pair) = delete; + + /// Deleted assignment operator + OverlappingPair& operator=(const OverlappingPair& pair) = delete; /// Return the pointer to first proxy collision shape ProxyShape* getShape1() const; diff --git a/src/engine/Profiler.cpp b/src/engine/Profiler.cpp index f9cc8fea..9437dca0 100644 --- a/src/engine/Profiler.cpp +++ b/src/engine/Profiler.cpp @@ -31,7 +31,7 @@ using namespace reactphysics3d; // Initialization of static variables -ProfileNode Profiler::mRootNode("Root", NULL); +ProfileNode Profiler::mRootNode("Root", nullptr); ProfileNode* Profiler::mCurrentNode = &Profiler::mRootNode; long double Profiler::mProfilingStartTime = Timer::getCurrentSystemTime() * 1000.0; uint Profiler::mFrameCounter = 0; @@ -39,8 +39,8 @@ uint Profiler::mFrameCounter = 0; // Constructor ProfileNode::ProfileNode(const char* name, ProfileNode* parentNode) :mName(name), mNbTotalCalls(0), mStartingTime(0), mTotalTime(0), - mRecursionCounter(0), mParentNode(parentNode), mChildNode(NULL), - mSiblingNode(NULL) { + mRecursionCounter(0), mParentNode(parentNode), mChildNode(nullptr), + mSiblingNode(nullptr) { reset(); } @@ -56,7 +56,7 @@ ProfileNode* ProfileNode::findSubNode(const char* name) { // Try to find the node among the child nodes ProfileNode* child = mChildNode; - while (child != NULL) { + while (child != nullptr) { if (child->mName == name) { return child; } @@ -110,12 +110,12 @@ void ProfileNode::reset() { mTotalTime = 0.0; // Reset the child node - if (mChildNode != NULL) { + if (mChildNode != nullptr) { mChildNode->reset(); } // Reset the sibling node - if (mSiblingNode != NULL) { + if (mSiblingNode != nullptr) { mSiblingNode->reset(); } } @@ -123,9 +123,9 @@ void ProfileNode::reset() { // Destroy the node void ProfileNode::destroy() { delete mChildNode; - mChildNode = NULL; + mChildNode = nullptr; delete mSiblingNode; - mSiblingNode = NULL; + mSiblingNode = nullptr; } // Constructor @@ -138,12 +138,12 @@ ProfileNodeIterator::ProfileNodeIterator(ProfileNode* startingNode) // Enter a given child node void ProfileNodeIterator::enterChild(int index) { mCurrentChildNode = mCurrentParentNode->getChildNode(); - while ((mCurrentChildNode != NULL) && (index != 0)) { + while ((mCurrentChildNode != nullptr) && (index != 0)) { index--; mCurrentChildNode = mCurrentChildNode->getSiblingNode(); } - if (mCurrentChildNode != NULL) { + if (mCurrentChildNode != nullptr) { mCurrentParentNode = mCurrentChildNode; mCurrentChildNode = mCurrentParentNode->getChildNode(); } @@ -151,7 +151,7 @@ void ProfileNodeIterator::enterChild(int index) { // Enter a given parent node void ProfileNodeIterator::enterParent() { - if (mCurrentParentNode->getParentNode() != NULL) { + if (mCurrentParentNode->getParentNode() != nullptr) { mCurrentParentNode = mCurrentParentNode->getParentNode(); } mCurrentChildNode = mCurrentParentNode->getChildNode(); diff --git a/src/engine/Profiler.h b/src/engine/Profiler.h index 7a42ae1c..818d6cc8 100644 --- a/src/engine/Profiler.h +++ b/src/engine/Profiler.h @@ -269,12 +269,12 @@ class ProfileSample { // Return true if we are at the root of the profiler tree inline bool ProfileNodeIterator::isRoot() { - return (mCurrentParentNode->getParentNode() == NULL); + return (mCurrentParentNode->getParentNode() == nullptr); } // Return true if we are at the end of a branch of the profiler tree inline bool ProfileNodeIterator::isEnd() { - return (mCurrentChildNode == NULL); + return (mCurrentChildNode == nullptr); } // Return the name of the current node diff --git a/src/engine/Timer.cpp b/src/engine/Timer.cpp index 243138fc..7d50dd79 100644 --- a/src/engine/Timer.cpp +++ b/src/engine/Timer.cpp @@ -34,11 +34,6 @@ Timer::Timer(double timeStep) : mTimeStep(timeStep), mIsRunning(false) { assert(timeStep > 0.0); } -// Destructor -Timer::~Timer() { - -} - // Return the current time of the system in seconds long double Timer::getCurrentSystemTime() { @@ -51,7 +46,7 @@ long double Timer::getCurrentSystemTime() { #else // Initialize the lastUpdateTime with the current time in seconds timeval timeValue; - gettimeofday(&timeValue, NULL); + gettimeofday(&timeValue, nullptr); return (timeValue.tv_sec + (timeValue.tv_usec / 1000000.0)); #endif } diff --git a/src/engine/Timer.h b/src/engine/Timer.h index ec673b67..83fc0b0a 100644 --- a/src/engine/Timer.h +++ b/src/engine/Timer.h @@ -71,14 +71,6 @@ class Timer { /// True if the timer is running bool mIsRunning; - // -------------------- Methods -------------------- // - - /// Private copy-constructor - Timer(const Timer& timer); - - /// Private assignment operator - Timer& operator=(const Timer& timer); - public : // -------------------- Methods -------------------- // @@ -87,7 +79,13 @@ class Timer { Timer(double timeStep); /// Destructor - virtual ~Timer(); + ~Timer() = default; + + /// Deleted copy-constructor + Timer(const Timer& timer) = delete; + + /// Deleted assignment operator + Timer& operator=(const Timer& timer) = delete; /// Return the timestep of the physics engine double getTimeStep() const; diff --git a/src/mathematics/Matrix2x2.cpp b/src/mathematics/Matrix2x2.cpp index 30fdc1a8..c501c1db 100644 --- a/src/mathematics/Matrix2x2.cpp +++ b/src/mathematics/Matrix2x2.cpp @@ -47,11 +47,6 @@ Matrix2x2::Matrix2x2(decimal a1, decimal a2, decimal b1, decimal b2) { setAllValues(a1, a2, b1, b2); } -// Destructor -Matrix2x2::~Matrix2x2() { - -} - // Copy-constructor Matrix2x2::Matrix2x2(const Matrix2x2& matrix) { setAllValues(matrix.mRows[0][0], matrix.mRows[0][1], diff --git a/src/mathematics/Matrix2x2.h b/src/mathematics/Matrix2x2.h index 9e9a6e4d..ee31b07a 100644 --- a/src/mathematics/Matrix2x2.h +++ b/src/mathematics/Matrix2x2.h @@ -60,7 +60,7 @@ class Matrix2x2 { Matrix2x2(decimal a1, decimal a2, decimal b1, decimal b2); /// Destructor - ~Matrix2x2(); + ~Matrix2x2() = default; /// Copy-constructor Matrix2x2(const Matrix2x2& matrix); diff --git a/src/mathematics/Matrix3x3.cpp b/src/mathematics/Matrix3x3.cpp index 3cd03509..a5491ed4 100644 --- a/src/mathematics/Matrix3x3.cpp +++ b/src/mathematics/Matrix3x3.cpp @@ -49,11 +49,6 @@ Matrix3x3::Matrix3x3(decimal a1, decimal a2, decimal a3, setAllValues(a1, a2, a3, b1, b2, b3, c1, c2, c3); } -// Destructor -Matrix3x3::~Matrix3x3() { - -} - // Copy-constructor Matrix3x3::Matrix3x3(const Matrix3x3& matrix) { setAllValues(matrix.mRows[0][0], matrix.mRows[0][1], matrix.mRows[0][2], diff --git a/src/mathematics/Matrix3x3.h b/src/mathematics/Matrix3x3.h index d06957cf..dfa23085 100644 --- a/src/mathematics/Matrix3x3.h +++ b/src/mathematics/Matrix3x3.h @@ -63,7 +63,7 @@ class Matrix3x3 { decimal c1, decimal c2, decimal c3); /// Destructor - virtual ~Matrix3x3(); + ~Matrix3x3() = default; /// Copy-constructor Matrix3x3(const Matrix3x3& matrix); diff --git a/src/mathematics/Quaternion.cpp b/src/mathematics/Quaternion.cpp index 3236a1b7..0b2587f5 100644 --- a/src/mathematics/Quaternion.cpp +++ b/src/mathematics/Quaternion.cpp @@ -128,11 +128,6 @@ Quaternion::Quaternion(const Matrix3x3& matrix) { } } -// Destructor -Quaternion::~Quaternion() { - -} - // Compute the rotation angle (in radians) and the rotation axis /// This method is used to get the rotation angle (in radian) and the unit /// rotation axis of an orientation quaternion. diff --git a/src/mathematics/Quaternion.h b/src/mathematics/Quaternion.h index c1bb584d..360cf229 100644 --- a/src/mathematics/Quaternion.h +++ b/src/mathematics/Quaternion.h @@ -82,7 +82,7 @@ struct Quaternion { Quaternion(const Matrix3x3& matrix); /// Destructor - ~Quaternion(); + ~Quaternion() = default; /// Set all the values void setAllValues(decimal newX, decimal newY, decimal newZ, decimal newW); diff --git a/src/mathematics/Ray.h b/src/mathematics/Ray.h index 10f182b0..938e8960 100644 --- a/src/mathematics/Ray.h +++ b/src/mathematics/Ray.h @@ -67,9 +67,7 @@ struct Ray { } /// Destructor - ~Ray() { - - } + ~Ray() = default; /// Overloaded assignment operator Ray& operator=(const Ray& ray) { diff --git a/src/mathematics/Transform.cpp b/src/mathematics/Transform.cpp index 4a77d84c..4bc91253 100644 --- a/src/mathematics/Transform.cpp +++ b/src/mathematics/Transform.cpp @@ -51,8 +51,3 @@ Transform::Transform(const Transform& transform) : mPosition(transform.mPosition), mOrientation(transform.mOrientation) { } - -// Destructor -Transform::~Transform() { - -} diff --git a/src/mathematics/Transform.h b/src/mathematics/Transform.h index 35d1862c..a93734cd 100644 --- a/src/mathematics/Transform.h +++ b/src/mathematics/Transform.h @@ -65,7 +65,7 @@ class Transform { Transform(const Vector3& position, const Quaternion& orientation); /// Destructor - ~Transform(); + ~Transform() = default; /// Copy-constructor Transform(const Transform& transform); diff --git a/src/mathematics/Vector2.cpp b/src/mathematics/Vector2.cpp index 55926bfd..2f225636 100644 --- a/src/mathematics/Vector2.cpp +++ b/src/mathematics/Vector2.cpp @@ -45,11 +45,6 @@ Vector2::Vector2(const Vector2& vector) : x(vector.x), y(vector.y) { } -// Destructor -Vector2::~Vector2() { - -} - // Return the corresponding unit vector Vector2 Vector2::getUnit() const { decimal lengthVector = length(); diff --git a/src/mathematics/Vector2.h b/src/mathematics/Vector2.h index 6e30363b..4b0e32f1 100644 --- a/src/mathematics/Vector2.h +++ b/src/mathematics/Vector2.h @@ -64,7 +64,7 @@ struct Vector2 { Vector2(const Vector2& vector); /// Destructor - ~Vector2(); + ~Vector2() = default; /// Set all the values of the vector void setAllValues(decimal newX, decimal newY); diff --git a/src/mathematics/Vector3.cpp b/src/mathematics/Vector3.cpp index f356705a..ed29a37f 100644 --- a/src/mathematics/Vector3.cpp +++ b/src/mathematics/Vector3.cpp @@ -46,11 +46,6 @@ Vector3::Vector3(const Vector3& vector) : x(vector.x), y(vector.y), z(vector.z) } -// Destructor -Vector3::~Vector3() { - -} - // Return the corresponding unit vector Vector3 Vector3::getUnit() const { decimal lengthVector = length(); diff --git a/src/mathematics/Vector3.h b/src/mathematics/Vector3.h index 0936f4ef..4f30391d 100644 --- a/src/mathematics/Vector3.h +++ b/src/mathematics/Vector3.h @@ -67,7 +67,7 @@ struct Vector3 { Vector3(const Vector3& vector); /// Destructor - ~Vector3(); + ~Vector3() = default; /// Set all the values of the vector void setAllValues(decimal newX, decimal newY, decimal newZ); diff --git a/src/memory/MemoryAllocator.cpp b/src/memory/MemoryAllocator.cpp index 6a9c69ab..46c47e14 100644 --- a/src/memory/MemoryAllocator.cpp +++ b/src/memory/MemoryAllocator.cpp @@ -99,7 +99,7 @@ MemoryAllocator::~MemoryAllocator() { void* MemoryAllocator::allocate(size_t size) { // We cannot allocate zero bytes - if (size == 0) return NULL; + if (size == 0) return nullptr; #ifndef NDEBUG mNbTimesAllocateMethodCalled++; @@ -117,7 +117,7 @@ void* MemoryAllocator::allocate(size_t size) { assert(indexHeap >= 0 && indexHeap < NB_HEAPS); // If there still are free memory units in the corresponding heap - if (mFreeMemoryUnits[indexHeap] != NULL) { + if (mFreeMemoryUnits[indexHeap] != nullptr) { // Return a pointer to the memory unit MemoryUnit* unit = mFreeMemoryUnits[indexHeap]; @@ -142,7 +142,7 @@ void* MemoryAllocator::allocate(size_t size) { // memory units MemoryBlock* newBlock = mMemoryBlocks + mNbCurrentMemoryBlocks; newBlock->memoryUnits = (MemoryUnit*) malloc(BLOCK_SIZE); - assert(newBlock->memoryUnits != NULL); + assert(newBlock->memoryUnits != nullptr); size_t unitSize = mUnitSizes[indexHeap]; uint nbUnits = BLOCK_SIZE / unitSize; assert(nbUnits * unitSize <= BLOCK_SIZE); @@ -152,7 +152,7 @@ void* MemoryAllocator::allocate(size_t size) { unit->nextUnit = nextUnit; } MemoryUnit* lastUnit = (MemoryUnit*) ((size_t)newBlock->memoryUnits + unitSize*(nbUnits-1)); - lastUnit->nextUnit = NULL; + lastUnit->nextUnit = nullptr; // Add the new allocated block into the list of free memory units in the heap mFreeMemoryUnits[indexHeap] = newBlock->memoryUnits->nextUnit; diff --git a/test/TestSuite.cpp b/test/TestSuite.cpp index 52a7d83a..dd4f42fc 100644 --- a/test/TestSuite.cpp +++ b/test/TestSuite.cpp @@ -61,10 +61,10 @@ long TestSuite::getNbFailedTests() const { // Add a unit test in the test suite void TestSuite::addTest(Test* test) { - if (test == NULL) { - throw std::invalid_argument("Error : You cannot add a NULL test in the test suite."); + if (test == nullptr) { + throw std::invalid_argument("Error : You cannot add a nullptr test in the test suite."); } - else if (mOutputStream != NULL && test->getOutputStream() == NULL) { + else if (mOutputStream != nullptr && test->getOutputStream() == nullptr) { test->setOutputStream(mOutputStream); } @@ -80,7 +80,7 @@ void TestSuite::addTestSuite(const TestSuite& testSuite) { // Add each test of the test suite to the current one for (size_t i =0; i < testSuite.mTests.size(); i++) { - assert(testSuite.mTests[i] != NULL); + assert(testSuite.mTests[i] != nullptr); addTest(testSuite.mTests[i]); } } @@ -93,7 +93,7 @@ void TestSuite::run() { // Run all the tests for (size_t i=0; i < mTests.size(); i++) { - assert(mTests[i] != NULL); + assert(mTests[i] != nullptr); mTests[i]->run(); } } @@ -108,7 +108,7 @@ void TestSuite::reset() { // Display the tests report and return the number of failed tests long TestSuite::report() const { - if (mOutputStream != NULL) { + if (mOutputStream != nullptr) { long nbFailedTests = 0; *mOutputStream << "Test Suite \"" << mName << "\"\n"; @@ -118,7 +118,7 @@ long TestSuite::report() const { } *mOutputStream << "=" << std::endl; for (i=0; i < mTests.size(); i++) { - assert(mTests[i] != NULL); + assert(mTests[i] != nullptr); nbFailedTests += mTests[i]->report(); } for (i=0; i < 70; i++) { @@ -139,6 +139,6 @@ void TestSuite::clear() { for (size_t i=0; i mHitNodes; // Called when the AABB of a leaf node is hit by a ray - virtual decimal raycastBroadPhaseShape(int32 nodeId, const Ray& ray) { + virtual decimal raycastBroadPhaseShape(int32 nodeId, const Ray& ray) override { mHitNodes.push_back(nodeId); return 1.0; } diff --git a/test/tests/collision/TestRaycast.h b/test/tests/collision/TestRaycast.h index e6f85f74..7295a8d9 100644 --- a/test/tests/collision/TestRaycast.h +++ b/test/tests/collision/TestRaycast.h @@ -60,10 +60,10 @@ class WorldRaycastCallback : public RaycastCallback { WorldRaycastCallback() { isHit = false; - shapeToTest = NULL; + shapeToTest = nullptr; } - virtual decimal notifyRaycastHit(const RaycastInfo& info) { + virtual decimal notifyRaycastHit(const RaycastInfo& info) override { if (shapeToTest->getBody()->getID() == info.body->getID()) { raycastInfo.body = info.body; @@ -79,9 +79,9 @@ class WorldRaycastCallback : public RaycastCallback { } void reset() { - raycastInfo.body = NULL; + raycastInfo.body = nullptr; raycastInfo.hitFraction = decimal(0.0); - raycastInfo.proxyShape = NULL; + raycastInfo.proxyShape = nullptr; raycastInfo.worldNormal.setToZero(); raycastInfo.worldPoint.setToZero(); isHit = false; @@ -288,13 +288,13 @@ class TestRaycast : public Test { mConcaveMeshIndices.push_back(1); mConcaveMeshIndices.push_back(4); mConcaveMeshIndices.push_back(5); mConcaveMeshIndices.push_back(5); mConcaveMeshIndices.push_back(7); mConcaveMeshIndices.push_back(6); mConcaveMeshIndices.push_back(4); mConcaveMeshIndices.push_back(7); mConcaveMeshIndices.push_back(5); - TriangleVertexArray::VertexDataType vertexType = sizeof(decimal) == 4 ? TriangleVertexArray::VERTEX_FLOAT_TYPE : - TriangleVertexArray::VERTEX_DOUBLE_TYPE; + TriangleVertexArray::VertexDataType vertexType = sizeof(decimal) == 4 ? TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE : + TriangleVertexArray::VertexDataType::VERTEX_DOUBLE_TYPE; mConcaveMeshVertexArray = new TriangleVertexArray(8, &(mConcaveMeshVertices[0]), sizeof(Vector3), 12, &(mConcaveMeshIndices[0]), sizeof(uint), vertexType, - TriangleVertexArray::INDEX_INTEGER_TYPE); + TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); // Add the triangle vertex array of the subpart to the triangle mesh @@ -305,7 +305,7 @@ class TestRaycast : public Test { // Heightfield shape (plane height field at height=4) for (int i=0; i<100; i++) mHeightFieldData[i] = 4; - mHeightFieldShape = new HeightFieldShape(10, 10, 0, 4, mHeightFieldData, HeightFieldShape::HEIGHT_FLOAT_TYPE); + mHeightFieldShape = new HeightFieldShape(10, 10, 0, 4, mHeightFieldData, HeightFieldShape::HeightDataType::HEIGHT_FLOAT_TYPE); mHeightFieldProxyShape = mHeightFieldBody->addCollisionShape(mHeightFieldShape, mShapeTransform); // Assign proxy shapes to the different categories @@ -1032,7 +1032,7 @@ class TestRaycast : public Test { // CollisionWorld::raycast() mCallback.reset(); - mTriangleShape->setRaycastTestType(FRONT); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::FRONT); mWorld->raycast(ray, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mTriangleBody); @@ -1046,7 +1046,7 @@ class TestRaycast : public Test { test(approxEqual(mCallback.raycastInfo.worldNormal.z, hitNormal.z, epsilon)); mCallback.reset(); - mTriangleShape->setRaycastTestType(BACK); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::BACK); mWorld->raycast(rayBackward, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mTriangleBody); @@ -1060,7 +1060,7 @@ class TestRaycast : public Test { test(approxEqual(mCallback.raycastInfo.worldNormal.z, -hitNormal.z, epsilon)); mCallback.reset(); - mTriangleShape->setRaycastTestType(FRONT_AND_BACK); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::FRONT_AND_BACK); mWorld->raycast(ray, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mTriangleBody); @@ -1074,7 +1074,7 @@ class TestRaycast : public Test { test(approxEqual(mCallback.raycastInfo.worldNormal.z, hitNormal.z, epsilon)); mCallback.reset(); - mTriangleShape->setRaycastTestType(FRONT_AND_BACK); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::FRONT_AND_BACK); mWorld->raycast(rayBackward, &mCallback); test(mCallback.isHit); test(mCallback.raycastInfo.body == mTriangleBody); @@ -1087,7 +1087,7 @@ class TestRaycast : public Test { test(approxEqual(mCallback.raycastInfo.worldNormal.y, -hitNormal.y, epsilon)); test(approxEqual(mCallback.raycastInfo.worldNormal.z, -hitNormal.z, epsilon)); - mTriangleShape->setRaycastTestType(FRONT); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::FRONT); // Correct category filter mask mCallback.reset(); @@ -1157,7 +1157,7 @@ class TestRaycast : public Test { test(!mCallback.isHit); // Test backward ray against front triangles (not hit should occur) - mTriangleShape->setRaycastTestType(FRONT); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::FRONT); test(!mTriangleBody->raycast(ray4Back, raycastInfo3)); test(!mTriangleProxyShape->raycast(ray4Back, raycastInfo3)); @@ -1178,7 +1178,7 @@ class TestRaycast : public Test { test(!mCallback.isHit); // Test front ray against back triangles (not hit should occur) - mTriangleShape->setRaycastTestType(BACK); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::BACK); test(!mTriangleBody->raycast(ray4, raycastInfo3)); test(!mTriangleProxyShape->raycast(ray4, raycastInfo3)); @@ -1201,7 +1201,7 @@ class TestRaycast : public Test { // ----- Test raycast hits ----- // // Test front ray against front triangles - mTriangleShape->setRaycastTestType(FRONT); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::FRONT); test(mTriangleBody->raycast(ray4, raycastInfo3)); test(mTriangleProxyShape->raycast(ray4, raycastInfo3)); @@ -1229,7 +1229,7 @@ class TestRaycast : public Test { mWorld->raycast(Ray(ray6.point1, ray6.point2, decimal(0.8)), &mCallback); // Test back ray against back triangles - mTriangleShape->setRaycastTestType(BACK); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::BACK); test(mTriangleBody->raycast(ray4Back, raycastInfo3)); test(mTriangleProxyShape->raycast(ray4Back, raycastInfo3)); @@ -1257,7 +1257,7 @@ class TestRaycast : public Test { mWorld->raycast(Ray(ray6Back.point1, ray6Back.point2, decimal(0.8)), &mCallback); // Test front ray against front-back triangles - mTriangleShape->setRaycastTestType(FRONT_AND_BACK); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::FRONT_AND_BACK); test(mTriangleBody->raycast(ray4, raycastInfo3)); test(mTriangleProxyShape->raycast(ray4, raycastInfo3)); @@ -1285,7 +1285,7 @@ class TestRaycast : public Test { mWorld->raycast(Ray(ray6.point1, ray6.point2, decimal(0.8)), &mCallback); // Test back ray against front-back triangles - mTriangleShape->setRaycastTestType(FRONT_AND_BACK); + mTriangleShape->setRaycastTestType(TriangleRaycastSide::FRONT_AND_BACK); test(mTriangleBody->raycast(ray4Back, raycastInfo3)); test(mTriangleProxyShape->raycast(ray4Back, raycastInfo3)); diff --git a/testbed/common/Box.cpp b/testbed/common/Box.cpp index 907f496a..549b86bb 100644 --- a/testbed/common/Box.cpp +++ b/testbed/common/Box.cpp @@ -27,7 +27,7 @@ #include "Box.h" // Macros -#define MEMBER_OFFSET(s,m) ((char *)NULL + (offsetof(s,m))) +#define MEMBER_OFFSET(s,m) ((char *)nullptr + (offsetof(s,m))) // Initialize static variables openglframework::VertexBufferObject Box::mVBOVertices(GL_ARRAY_BUFFER); @@ -257,12 +257,12 @@ void Box::render(openglframework::Shader& shader, GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false); glEnableVertexAttribArray(vertexPositionLoc); - glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, NULL); + glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr); mVBONormals.bind(); if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc); - if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, NULL); + if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr); // Draw the geometry of the box glDrawArrays(GL_TRIANGLES, 0, 36); @@ -321,7 +321,7 @@ void Box::resetTransform(const rp3d::Transform& transform) { // Reset the velocity of the rigid body rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != NULL) { + if (rigidBody != nullptr) { rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); } diff --git a/testbed/common/Box.h b/testbed/common/Box.h index 44682c1c..56f8daf5 100644 --- a/testbed/common/Box.h +++ b/testbed/common/Box.h @@ -92,7 +92,7 @@ class Box : public openglframework::Object3D, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/common/Capsule.cpp b/testbed/common/Capsule.cpp index a953fcfc..7b83f6b3 100644 --- a/testbed/common/Capsule.cpp +++ b/testbed/common/Capsule.cpp @@ -183,16 +183,16 @@ void Capsule::render(openglframework::Shader& shader, GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false); glEnableVertexAttribArray(vertexPositionLoc); - glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); mVBONormals.bind(); - if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc); // For each part of the mesh for (unsigned int i=0; i(mBody); - if (rigidBody != NULL) { + if (rigidBody != nullptr) { rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); } diff --git a/testbed/common/Capsule.h b/testbed/common/Capsule.h index eaae3482..ee380914 100644 --- a/testbed/common/Capsule.h +++ b/testbed/common/Capsule.h @@ -101,7 +101,7 @@ class Capsule : public openglframework::Mesh, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/common/ConcaveMesh.cpp b/testbed/common/ConcaveMesh.cpp index 26a27920..68f7a56e 100644 --- a/testbed/common/ConcaveMesh.cpp +++ b/testbed/common/ConcaveMesh.cpp @@ -53,8 +53,8 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, rp3d::TriangleVertexArray* vertexArray = new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3), getNbFaces(i), &(mIndices[i][0]), sizeof(int), - rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE, - rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE); + rp3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, + rp3d::TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); // Add the triangle vertex array of the subpart to the triangle mesh mPhysicsTriangleMesh.addSubpart(vertexArray); @@ -110,8 +110,8 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, float mass, rp3d::TriangleVertexArray* vertexArray = new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3), getNbFaces(i), &(mIndices[i][0]), sizeof(int), - rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE, - rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE); + rp3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, + rp3d::TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); // Add the triangle vertex array of the subpart to the triangle mesh mPhysicsTriangleMesh.addSubpart(vertexArray); @@ -196,16 +196,16 @@ void ConcaveMesh::render(openglframework::Shader& shader, GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false); glEnableVertexAttribArray(vertexPositionLoc); - glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); mVBONormals.bind(); - if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc); // For each part of the mesh for (unsigned int i=0; i(mBody); - if (rigidBody != NULL) { + if (rigidBody != nullptr) { rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); } diff --git a/testbed/common/ConcaveMesh.h b/testbed/common/ConcaveMesh.h index 354a1a3b..087c030c 100644 --- a/testbed/common/ConcaveMesh.h +++ b/testbed/common/ConcaveMesh.h @@ -94,7 +94,7 @@ class ConcaveMesh : public openglframework::Mesh, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/common/Cone.cpp b/testbed/common/Cone.cpp index ca8d9ee8..1a971922 100644 --- a/testbed/common/Cone.cpp +++ b/testbed/common/Cone.cpp @@ -180,16 +180,16 @@ void Cone::render(openglframework::Shader& shader, GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false); glEnableVertexAttribArray(vertexPositionLoc); - glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); mVBONormals.bind(); - if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc); // For each part of the mesh for (unsigned int i=0; i(mBody); - if (rigidBody != NULL) { + if (rigidBody != nullptr) { rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); } diff --git a/testbed/common/Cone.h b/testbed/common/Cone.h index 4ce19c8d..e886c66b 100644 --- a/testbed/common/Cone.h +++ b/testbed/common/Cone.h @@ -100,7 +100,7 @@ class Cone : public openglframework::Mesh, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/common/ConvexMesh.cpp b/testbed/common/ConvexMesh.cpp index 2c6d4368..1ded48a2 100644 --- a/testbed/common/ConvexMesh.cpp +++ b/testbed/common/ConvexMesh.cpp @@ -51,8 +51,8 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, mPhysicsTriangleVertexArray = new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3), getNbFaces(0), &(mIndices[0][0]), sizeof(int), - rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE, - rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE); + rp3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, + rp3d::TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); // Create the collision shape for the rigid body (convex mesh shape) and // do not forget to delete it at the end @@ -101,8 +101,8 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass, mPhysicsTriangleVertexArray = new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3), getNbFaces(0), &(mIndices[0][0]), sizeof(int), - rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE, - rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE); + rp3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, + rp3d::TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); // Create the collision shape for the rigid body (convex mesh shape) and do // not forget to delete it at the end @@ -177,16 +177,16 @@ void ConvexMesh::render(openglframework::Shader& shader, GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false); glEnableVertexAttribArray(vertexPositionLoc); - glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); mVBONormals.bind(); - if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc); // For each part of the mesh for (unsigned int i=0; i(mBody); - if (rigidBody != NULL) { + if (rigidBody != nullptr) { rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); } diff --git a/testbed/common/ConvexMesh.h b/testbed/common/ConvexMesh.h index 50b4fb4a..842d187f 100644 --- a/testbed/common/ConvexMesh.h +++ b/testbed/common/ConvexMesh.h @@ -93,7 +93,7 @@ class ConvexMesh : public openglframework::Mesh, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/common/Cylinder.cpp b/testbed/common/Cylinder.cpp index 188cdd57..f791317b 100644 --- a/testbed/common/Cylinder.cpp +++ b/testbed/common/Cylinder.cpp @@ -181,16 +181,16 @@ void Cylinder::render(openglframework::Shader& shader, GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false); glEnableVertexAttribArray(vertexPositionLoc); - glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); mVBONormals.bind(); - if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); + if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr); if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc); // For each part of the mesh for (unsigned int i=0; i(mBody); - if (rigidBody != NULL) { + if (rigidBody != nullptr) { rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); } diff --git a/testbed/common/Cylinder.h b/testbed/common/Cylinder.h index eeea6d5f..2e75084c 100644 --- a/testbed/common/Cylinder.h +++ b/testbed/common/Cylinder.h @@ -100,7 +100,7 @@ class Cylinder : public openglframework::Mesh, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/common/Dumbbell.h b/testbed/common/Dumbbell.h index 6b68c1aa..7982819d 100644 --- a/testbed/common/Dumbbell.h +++ b/testbed/common/Dumbbell.h @@ -101,7 +101,7 @@ class Dumbbell : public openglframework::Mesh, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/common/HeightField.cpp b/testbed/common/HeightField.cpp index e230c365..f65123ee 100644 --- a/testbed/common/HeightField.cpp +++ b/testbed/common/HeightField.cpp @@ -49,7 +49,7 @@ HeightField::HeightField(const openglframework::Vector3 &position, // Create the collision shape for the rigid body (convex mesh shape) and // do not forget to delete it at the end mHeightFieldShape = new rp3d::HeightFieldShape(NB_POINTS_WIDTH, NB_POINTS_LENGTH, mMinHeight, mMaxHeight, - mHeightData, rp3d::HeightFieldShape::HEIGHT_FLOAT_TYPE); + mHeightData, rp3d::HeightFieldShape::HeightDataType::HEIGHT_FLOAT_TYPE); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); @@ -92,7 +92,7 @@ HeightField::HeightField(const openglframework::Vector3 &position, float mass, // Create the collision shape for the rigid body (convex mesh shape) and // do not forget to delete it at the end mHeightFieldShape = new rp3d::HeightFieldShape(NB_POINTS_WIDTH, NB_POINTS_LENGTH, mMinHeight, mMaxHeight, - mHeightData, rp3d::HeightFieldShape::HEIGHT_FLOAT_TYPE); + mHeightData, rp3d::HeightFieldShape::HeightDataType::HEIGHT_FLOAT_TYPE); // Initial position and orientation of the rigid body rp3d::Vector3 initPosition(position.x, position.y, position.z); diff --git a/testbed/common/HeightField.h b/testbed/common/HeightField.h index 0b2665f9..bf1cb148 100644 --- a/testbed/common/HeightField.h +++ b/testbed/common/HeightField.h @@ -107,7 +107,7 @@ class HeightField : public openglframework::Mesh, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/common/Sphere.h b/testbed/common/Sphere.h index f51d4074..70270026 100644 --- a/testbed/common/Sphere.h +++ b/testbed/common/Sphere.h @@ -97,7 +97,7 @@ class Sphere : public openglframework::Mesh, public PhysicsObject { void resetTransform(const rp3d::Transform& transform); /// Update the transform matrix of the object - virtual void updateTransform(float interpolationFactor); + virtual void updateTransform(float interpolationFactor) override; /// Set the scaling of the object void setScaling(const openglframework::Vector3& scaling); diff --git a/testbed/scenes/collisionshapes/CollisionShapesScene.cpp b/testbed/scenes/collisionshapes/CollisionShapesScene.cpp index e18feea9..5078cd14 100644 --- a/testbed/scenes/collisionshapes/CollisionShapesScene.cpp +++ b/testbed/scenes/collisionshapes/CollisionShapesScene.cpp @@ -242,7 +242,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name) mFloor->setSleepingColor(mGreyColorDemo); // The floor must be a static rigid body - mFloor->getRigidBody()->setType(rp3d::STATIC); + mFloor->getRigidBody()->setType(rp3d::BodyType::STATIC); // Change the material properties of the rigid body rp3d::Material& material = mFloor->getRigidBody()->getMaterial(); diff --git a/testbed/scenes/collisionshapes/CollisionShapesScene.h b/testbed/scenes/collisionshapes/CollisionShapesScene.h index 9a61f93e..93d14051 100644 --- a/testbed/scenes/collisionshapes/CollisionShapesScene.h +++ b/testbed/scenes/collisionshapes/CollisionShapesScene.h @@ -106,24 +106,24 @@ class CollisionShapesScene : public SceneDemo { CollisionShapesScene(const std::string& name); /// Destructor - virtual ~CollisionShapesScene(); + virtual ~CollisionShapesScene() override; /// Update the physics world (take a simulation step) /// Can be called several times per frame - virtual void updatePhysics(); + virtual void updatePhysics() override; /// Take a step for the simulation - virtual void update(); + virtual void update() override; /// Render the scene in a single pass virtual void renderSinglePass(openglframework::Shader& shader, - const openglframework::Matrix4& worldToCameraMatrix); + const openglframework::Matrix4& worldToCameraMatrix) override; /// Reset the scene - virtual void reset(); + virtual void reset() override; /// Return all the contact points of the scene - virtual std::vector getContactPoints() const; + virtual std::vector getContactPoints() const override; }; // Return all the contact points of the scene diff --git a/testbed/scenes/concavemesh/ConcaveMeshScene.cpp b/testbed/scenes/concavemesh/ConcaveMeshScene.cpp index 424c9190..41234f3f 100644 --- a/testbed/scenes/concavemesh/ConcaveMeshScene.cpp +++ b/testbed/scenes/concavemesh/ConcaveMeshScene.cpp @@ -80,7 +80,7 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name) mConcaveMesh = new ConcaveMesh(position, mass, mDynamicsWorld, meshFolderPath + "city.obj"); // Set the mesh as beeing static - mConcaveMesh->getRigidBody()->setType(rp3d::STATIC); + mConcaveMesh->getRigidBody()->setType(rp3d::BodyType::STATIC); // Set the box color mConcaveMesh->setColor(mGreyColorDemo); diff --git a/testbed/scenes/concavemesh/ConcaveMeshScene.h b/testbed/scenes/concavemesh/ConcaveMeshScene.h index 9871526d..5943fe6c 100644 --- a/testbed/scenes/concavemesh/ConcaveMeshScene.h +++ b/testbed/scenes/concavemesh/ConcaveMeshScene.h @@ -66,24 +66,24 @@ class ConcaveMeshScene : public SceneDemo { ConcaveMeshScene(const std::string& name); /// Destructor - virtual ~ConcaveMeshScene(); + virtual ~ConcaveMeshScene() override; /// Update the physics world (take a simulation step) /// Can be called several times per frame - virtual void updatePhysics(); + virtual void updatePhysics() override; /// Update the scene (take a simulation step) - virtual void update(); + virtual void update() override; /// Render the scene in a single pass virtual void renderSinglePass(openglframework::Shader& shader, - const openglframework::Matrix4& worldToCameraMatrix); + const openglframework::Matrix4& worldToCameraMatrix) override; /// Reset the scene - virtual void reset(); + virtual void reset() override; /// Return all the contact points of the scene - virtual std::vector getContactPoints() const; + virtual std::vector getContactPoints() const override; }; // Return all the contact points of the scene diff --git a/testbed/scenes/cubes/CubesScene.cpp b/testbed/scenes/cubes/CubesScene.cpp index 8125a8d5..f9c8ad77 100644 --- a/testbed/scenes/cubes/CubesScene.cpp +++ b/testbed/scenes/cubes/CubesScene.cpp @@ -79,7 +79,7 @@ CubesScene::CubesScene(const std::string& name) mFloor->setSleepingColor(mGreyColorDemo); // The floor must be a static rigid body - mFloor->getRigidBody()->setType(rp3d::STATIC); + mFloor->getRigidBody()->setType(rp3d::BodyType::STATIC); // Change the material properties of the floor rigid body rp3d::Material& material = mFloor->getRigidBody()->getMaterial(); diff --git a/testbed/scenes/cubes/CubesScene.h b/testbed/scenes/cubes/CubesScene.h index fcc6fb25..a07c74d2 100644 --- a/testbed/scenes/cubes/CubesScene.h +++ b/testbed/scenes/cubes/CubesScene.h @@ -66,24 +66,24 @@ class CubesScene : public SceneDemo { CubesScene(const std::string& name); /// Destructor - virtual ~CubesScene(); + virtual ~CubesScene() override; /// Update the physics world (take a simulation step) /// Can be called several times per frame - virtual void updatePhysics(); + virtual void updatePhysics() override; /// Update the scene (take a simulation step) - virtual void update(); + virtual void update() override; /// Render the scene in a single pass virtual void renderSinglePass(openglframework::Shader& shader, - const openglframework::Matrix4& worldToCameraMatrix); + const openglframework::Matrix4& worldToCameraMatrix) override; /// Reset the scene - virtual void reset(); + virtual void reset() override; /// Return all the contact points of the scene - virtual std::vector getContactPoints() const; + virtual std::vector getContactPoints() const override; }; // Return all the contact points of the scene diff --git a/testbed/scenes/heightfield/HeightFieldScene.cpp b/testbed/scenes/heightfield/HeightFieldScene.cpp index 8779fa9c..3395ac17 100644 --- a/testbed/scenes/heightfield/HeightFieldScene.cpp +++ b/testbed/scenes/heightfield/HeightFieldScene.cpp @@ -75,7 +75,7 @@ HeightFieldScene::HeightFieldScene(const std::string& name) : SceneDemo(name, SC mHeightField = new HeightField(position, mass, mDynamicsWorld); // Set the mesh as beeing static - mHeightField->getRigidBody()->setType(rp3d::STATIC); + mHeightField->getRigidBody()->setType(rp3d::BodyType::STATIC); // Set the color mHeightField->setColor(mGreyColorDemo); diff --git a/testbed/scenes/heightfield/HeightFieldScene.h b/testbed/scenes/heightfield/HeightFieldScene.h index 36749ef6..7eb9527d 100644 --- a/testbed/scenes/heightfield/HeightFieldScene.h +++ b/testbed/scenes/heightfield/HeightFieldScene.h @@ -63,24 +63,24 @@ class HeightFieldScene : public SceneDemo { HeightFieldScene(const std::string& name); /// Destructor - virtual ~HeightFieldScene(); + virtual ~HeightFieldScene() override; /// Update the physics world (take a simulation step) /// Can be called several times per frame - virtual void updatePhysics(); + virtual void updatePhysics() override; /// Update the scene (take a simulation step) - virtual void update(); + virtual void update() override; /// Render the scene in a single pass virtual void renderSinglePass(openglframework::Shader& shader, - const openglframework::Matrix4& worldToCameraMatrix); + const openglframework::Matrix4& worldToCameraMatrix) override ; /// Reset the scene - virtual void reset(); + virtual void reset() override ; /// Return all the contact points of the scene - virtual std::vector getContactPoints() const; + virtual std::vector getContactPoints() const override ; }; // Return all the contact points of the scene diff --git a/testbed/scenes/joints/JointsScene.cpp b/testbed/scenes/joints/JointsScene.cpp index 9927613f..b1891627 100644 --- a/testbed/scenes/joints/JointsScene.cpp +++ b/testbed/scenes/joints/JointsScene.cpp @@ -271,7 +271,7 @@ void JointsScene::createBallAndSocketJoints() { // The fist box cannot move (static body) if (i == 0) { - mBallAndSocketJointChainBoxes[i]->getRigidBody()->setType(rp3d::STATIC); + mBallAndSocketJointChainBoxes[i]->getRigidBody()->setType(rp3d::BodyType::STATIC); } // Add some angular velocity damping @@ -319,7 +319,7 @@ void JointsScene::createSliderJoint() { mSliderJointBottomBox->setSleepingColor(mRedColorDemo); // The fist box cannot move - mSliderJointBottomBox->getRigidBody()->setType(rp3d::STATIC); + mSliderJointBottomBox->getRigidBody()->setType(rp3d::BodyType::STATIC); // Change the material properties of the rigid body rp3d::Material& material1 = mSliderJointBottomBox->getRigidBody()->getMaterial(); @@ -473,7 +473,7 @@ void JointsScene::createFloor() { mFloor->setSleepingColor(mGreyColorDemo); // The floor must be a static rigid body - mFloor->getRigidBody()->setType(rp3d::STATIC); + mFloor->getRigidBody()->setType(rp3d::BodyType::STATIC); // Change the material properties of the rigid body rp3d::Material& material = mFloor->getRigidBody()->getMaterial(); diff --git a/testbed/scenes/joints/JointsScene.h b/testbed/scenes/joints/JointsScene.h index 4a573957..a9474393 100644 --- a/testbed/scenes/joints/JointsScene.h +++ b/testbed/scenes/joints/JointsScene.h @@ -120,24 +120,24 @@ class JointsScene : public SceneDemo { JointsScene(const std::string& name); /// Destructor - virtual ~JointsScene(); + virtual ~JointsScene() override ; /// Update the physics world (take a simulation step) /// Can be called several times per frame - virtual void updatePhysics(); + virtual void updatePhysics() override; /// Take a step for the simulation - virtual void update(); + virtual void update() override; /// Render the scene in a single pass virtual void renderSinglePass(openglframework::Shader& shader, - const openglframework::Matrix4& worldToCameraMatrix); + const openglframework::Matrix4& worldToCameraMatrix) override; /// Reset the scene - virtual void reset(); + virtual void reset() override; /// Return all the contact points of the scene - virtual std::vector getContactPoints() const; + virtual std::vector getContactPoints() const override; }; // Return all the contact points of the scene diff --git a/testbed/scenes/raycast/RaycastScene.h b/testbed/scenes/raycast/RaycastScene.h index 583d2d36..56ebb565 100644 --- a/testbed/scenes/raycast/RaycastScene.h +++ b/testbed/scenes/raycast/RaycastScene.h @@ -83,7 +83,7 @@ class RaycastManager : public rp3d::RaycastCallback { } - virtual rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo) { + virtual rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo) override { rp3d::Vector3 hitPos = raycastInfo.worldPoint; openglframework::Vector3 position(hitPos.x, hitPos.y, hitPos.z); mHitPoints.push_back(ContactPoint(position)); @@ -176,21 +176,21 @@ class RaycastScene : public SceneDemo { RaycastScene(const std::string& name); /// Destructor - virtual ~RaycastScene(); + virtual ~RaycastScene() override; /// Update the physics world (take a simulation step) /// Can be called several times per frame - virtual void updatePhysics(); + virtual void updatePhysics() override; /// Take a step for the simulation - virtual void update(); + virtual void update() override; /// Render the scene in a single pass virtual void renderSinglePass(openglframework::Shader& shader, - const openglframework::Matrix4& worldToCameraMatrix); + const openglframework::Matrix4& worldToCameraMatrix) override; /// Reset the scene - virtual void reset(); + virtual void reset() override; /// Change the body to raycast void changeBody(); @@ -199,16 +199,16 @@ class RaycastScene : public SceneDemo { void showHideNormals(); /// Called when a keyboard event occurs - virtual bool keyboardEvent(int key, int scancode, int action, int mods); + virtual bool keyboardEvent(int key, int scancode, int action, int mods) override; /// Enabled/Disable the shadow mapping - void virtual setIsShadowMappingEnabled(bool isShadowMappingEnabled); + virtual void setIsShadowMappingEnabled(bool isShadowMappingEnabled) override; /// Display/Hide the contact points - void virtual setIsContactPointsDisplayed(bool display); + virtual void setIsContactPointsDisplayed(bool display) override; /// Return all the contact points of the scene - virtual std::vector getContactPoints() const; + virtual std::vector getContactPoints() const override; }; // Display or not the surface normals at hit points diff --git a/testbed/src/SceneDemo.h b/testbed/src/SceneDemo.h index e6e12e45..c64c8a9b 100644 --- a/testbed/src/SceneDemo.h +++ b/testbed/src/SceneDemo.h @@ -120,20 +120,20 @@ class SceneDemo : public Scene { SceneDemo(const std::string& name, float sceneRadius, bool isShadowMappingEnabled = true); /// Destructor - virtual ~SceneDemo(); + virtual ~SceneDemo() override; /// Update the scene - virtual void update(); + virtual void update() override; /// Render the scene (possibly in multiple passes for shadow mapping) - virtual void render(); + virtual void render() override; /// Render the scene in a single pass virtual void renderSinglePass(openglframework::Shader& shader, - const openglframework::Matrix4& worldToCameraMatrix)=0; + const openglframework::Matrix4& worldToCameraMatrix)=0 ; /// Enabled/Disable the shadow mapping - void virtual setIsShadowMappingEnabled(bool isShadowMappingEnabled); + virtual void setIsShadowMappingEnabled(bool isShadowMappingEnabled) override; /// Return all the contact points of the scene std::vector computeContactPointsOfWorld(const rp3d::DynamicsWorld* world) const; diff --git a/testbed/src/TestbedApplication.h b/testbed/src/TestbedApplication.h index d9554e42..dcff0598 100644 --- a/testbed/src/TestbedApplication.h +++ b/testbed/src/TestbedApplication.h @@ -173,25 +173,25 @@ class TestbedApplication : public Screen { TestbedApplication(bool isFullscreen); /// Destructor - virtual ~TestbedApplication(); + virtual ~TestbedApplication() override; /// Render the content of the application - virtual void drawContents(); + virtual void drawContents() override; /// Window resize event handler - virtual bool resizeEvent(const Vector2i& size); + virtual bool resizeEvent(const Vector2i& size) override; /// Default keyboard event handler - virtual bool keyboardEvent(int key, int scancode, int action, int modifiers); + virtual bool keyboardEvent(int key, int scancode, int action, int modifiers) override; /// Handle a mouse button event (default implementation: propagate to children) - virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers); + virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) override; /// Handle a mouse motion event (default implementation: propagate to children) - virtual bool mouseMotionEvent(const Vector2i &p, const Vector2i &rel, int button, int modifiers); + virtual bool mouseMotionEvent(const Vector2i &p, const Vector2i &rel, int button, int modifiers) override; /// Handle a mouse scroll event (default implementation: propagate to children) - virtual bool scrollEvent(const Vector2i &p, const Vector2f &rel); + virtual bool scrollEvent(const Vector2i &p, const Vector2f &rel) override; /// Initialize the application void init(); diff --git a/testbed/src/Timer.h b/testbed/src/Timer.h index bc1d17e6..cddc7ca5 100644 --- a/testbed/src/Timer.h +++ b/testbed/src/Timer.h @@ -80,7 +80,7 @@ class Timer { Timer(); /// Destructor - virtual ~Timer(); + ~Timer(); /// Return the current time of the physics engine long double getPhysicsTime() const;