diff --git a/src/body/Body.cpp b/src/body/Body.cpp index 0ce9d0be..0077b7fe 100644 --- a/src/body/Body.cpp +++ b/src/body/Body.cpp @@ -26,6 +26,7 @@ // Libraries #include "Body.h" #include "collision/shapes/CollisionShape.h" +#include "utils/Logger.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; @@ -43,3 +44,52 @@ Body::Body(bodyindex id) #endif } + +// Set whether or not the body is active +/** + * @param isActive True if you want to activate the body + */ +void Body::setIsActive(bool isActive) { + mIsActive = isActive; + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set isActive=" + + (mIsActive ? "true" : "false")); +} + +// Set the variable to know whether or not the body is sleeping +void Body::setIsSleeping(bool isSleeping) { + + if (isSleeping) { + mSleepTime = decimal(0.0); + } + else { + if (mIsSleeping) { + mSleepTime = decimal(0.0); + } + } + + if (mIsSleeping != isSleeping) { + + mIsSleeping = isSleeping; + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set isSleeping=" + + (mIsSleeping ? "true" : "false")); + } +} + +// Set whether or not the body is allowed to go to sleep +/** + * @param isAllowedToSleep True if the body is allowed to sleep + */ +void Body::setIsAllowedToSleep(bool isAllowedToSleep) { + mIsAllowedToSleep = isAllowedToSleep; + + if (!mIsAllowedToSleep) setIsSleeping(false); + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set isAllowedToSleep=" + + (mIsAllowedToSleep ? "true" : "false")); +} + diff --git a/src/body/Body.h b/src/body/Body.h index 337b9df1..adc657f7 100644 --- a/src/body/Body.h +++ b/src/body/Body.h @@ -27,14 +27,15 @@ #define REACTPHYSICS3D_BODY_H // Libraries -#include #include #include "configuration.h" -#include "utils/Logger.h" /// Namespace reactphysics3d namespace reactphysics3d { +// Declarations +class Logger; + // TODO : Make this class abstract // Class Body /** @@ -164,20 +165,6 @@ inline bool Body::isAllowedToSleep() const { return mIsAllowedToSleep; } -// Set whether or not the body is allowed to go to sleep -/** - * @param isAllowedToSleep True if the body is allowed to sleep - */ -inline void Body::setIsAllowedToSleep(bool isAllowedToSleep) { - mIsAllowedToSleep = isAllowedToSleep; - - if (!mIsAllowedToSleep) setIsSleeping(false); - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set isAllowedToSleep=" + - (mIsAllowedToSleep ? "true" : "false")); -} - // Return whether or not the body is sleeping /** * @return True if the body is currently sleeping and false otherwise @@ -194,40 +181,6 @@ inline bool Body::isActive() const { return mIsActive; } -// Set whether or not the body is active -/** - * @param isActive True if you want to activate the body - */ -inline void Body::setIsActive(bool isActive) { - mIsActive = isActive; - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set isActive=" + - (mIsActive ? "true" : "false")); -} - -// Set the variable to know whether or not the body is sleeping -inline void Body::setIsSleeping(bool isSleeping) { - - if (isSleeping) { - mSleepTime = decimal(0.0); - } - else { - if (mIsSleeping) { - mSleepTime = decimal(0.0); - } - } - - if (mIsSleeping != isSleeping) { - - mIsSleeping = isSleeping; - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set isSleeping=" + - (mIsSleeping ? "true" : "false")); - } -} - // Return a pointer to the user data attached to this body /** * @return A pointer to the user data you have attached to the body diff --git a/src/body/CollisionBody.cpp b/src/body/CollisionBody.cpp index 307b953a..b22b3151 100644 --- a/src/body/CollisionBody.cpp +++ b/src/body/CollisionBody.cpp @@ -27,6 +27,8 @@ #include "CollisionBody.h" #include "engine/CollisionWorld.h" #include "collision/ContactManifold.h" +#include "collision/RaycastInfo.h" +#include "utils/Logger.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; @@ -390,3 +392,49 @@ AABB CollisionBody::getAABB() const { return bodyAABB; } + +// Set the current position and orientation +/** + * @param transform The transformation of the body that transforms the local-space + * of the body into world-space + */ +void CollisionBody::setTransform(const Transform& transform) { + + // Update the transform of the body + mTransform = transform; + + // Update the broad-phase state of the body + updateBroadPhaseState(); + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set transform=" + mTransform.to_string()); +} + + +// Set the type of the body +/// The type of the body can either STATIC, KINEMATIC or DYNAMIC as described bellow: +/// STATIC : A static body has infinite mass, zero velocity but the position can be +/// changed manually. A static body does not collide with other static or kinematic bodies. +/// KINEMATIC : A kinematic body has infinite mass, the velocity can be changed manually and its +/// position is computed by the physics engine. A kinematic body does not collide with +/// other static or kinematic bodies. +/// 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. +/** + * @param type The type of the body (STATIC, KINEMATIC, DYNAMIC) + */ +void CollisionBody::setType(BodyType type) { + mType = type; + + if (mType == BodyType::STATIC) { + + // Update the broad-phase state of the body + updateBroadPhaseState(); + } + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set type=" + + (mType == BodyType::STATIC ? "Static" : (mType == BodyType::DYNAMIC ? "Dynamic" : "Kinematic"))); +} + diff --git a/src/body/CollisionBody.h b/src/body/CollisionBody.h index e98b9a7d..9eaebb21 100644 --- a/src/body/CollisionBody.h +++ b/src/body/CollisionBody.h @@ -27,24 +27,23 @@ #define REACTPHYSICS3D_COLLISION_BODY_H // Libraries -#include #include #include "Body.h" -#include "mathematics/Transform.h" #include "collision/shapes/AABB.h" -#include "collision/shapes/CollisionShape.h" -#include "collision/RaycastInfo.h" -#include "memory/PoolAllocator.h" +#include "mathematics/Transform.h" #include "configuration.h" -#include "utils/Profiler.h" /// Namespace reactphysics3d namespace reactphysics3d { -// Class declarations +// Declarations struct ContactManifoldListElement; class ProxyShape; class CollisionWorld; +class CollisionShape; +struct RaycastInfo; +class PoolAllocator; +class Profiler; /// Enumeration for the type of a body /// STATIC : A static body has infinite mass, zero velocity but the position can be @@ -210,33 +209,6 @@ inline BodyType CollisionBody::getType() const { return mType; } -// Set the type of the body -/// The type of the body can either STATIC, KINEMATIC or DYNAMIC as described bellow: -/// STATIC : A static body has infinite mass, zero velocity but the position can be -/// changed manually. A static body does not collide with other static or kinematic bodies. -/// KINEMATIC : A kinematic body has infinite mass, the velocity can be changed manually and its -/// position is computed by the physics engine. A kinematic body does not collide with -/// other static or kinematic bodies. -/// 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. -/** - * @param type The type of the body (STATIC, KINEMATIC, DYNAMIC) - */ -inline void CollisionBody::setType(BodyType type) { - mType = type; - - if (mType == BodyType::STATIC) { - - // Update the broad-phase state of the body - updateBroadPhaseState(); - } - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set type=" + - (mType == BodyType::STATIC ? "Static" : (mType == BodyType::DYNAMIC ? "Dynamic" : "Kinematic"))); -} - // Return the current position and orientation /** * @return The current transformation of the body that transforms the local-space @@ -246,23 +218,6 @@ inline const Transform& CollisionBody::getTransform() const { return mTransform; } -// Set the current position and orientation -/** - * @param transform The transformation of the body that transforms the local-space - * of the body into world-space - */ -inline void CollisionBody::setTransform(const Transform& transform) { - - // Update the transform of the body - mTransform = transform; - - // Update the broad-phase state of the body - updateBroadPhaseState(); - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set transform=" + mTransform.to_string()); -} - // Return the first element of the linked list of contact manifolds involving this body /** * @return A pointer to the first element of the linked-list with the contact diff --git a/src/body/RigidBody.cpp b/src/body/RigidBody.cpp index 4a05010b..a5e93513 100644 --- a/src/body/RigidBody.cpp +++ b/src/body/RigidBody.cpp @@ -28,6 +28,7 @@ #include "constraint/Joint.h" #include "collision/shapes/CollisionShape.h" #include "engine/DynamicsWorld.h" +#include "utils/Profiler.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; @@ -334,6 +335,55 @@ void RigidBody::removeCollisionShape(const ProxyShape* proxyShape) { recomputeMassInformation(); } +// Set the variable to know if the gravity is applied to this rigid body +/** + * @param isEnabled True if you want the gravity to be applied to this body + */ +void RigidBody::enableGravity(bool isEnabled) { + mIsGravityEnabled = isEnabled; + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set isGravityEnabled=" + + (mIsGravityEnabled ? "true" : "false")); +} + +// Set the linear damping factor. This is the ratio of the linear velocity +// that the body will lose every at seconds of simulation. +/** + * @param linearDamping The linear damping factor of this body + */ +void RigidBody::setLinearDamping(decimal linearDamping) { + assert(linearDamping >= decimal(0.0)); + mLinearDamping = linearDamping; + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set linearDamping=" + std::to_string(mLinearDamping)); +} + +// Set the angular damping factor. This is the ratio of the angular velocity +// that the body will lose at every seconds of simulation. +/** + * @param angularDamping The angular damping factor of this body + */ +void RigidBody::setAngularDamping(decimal angularDamping) { + assert(angularDamping >= decimal(0.0)); + mAngularDamping = angularDamping; + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set angularDamping=" + std::to_string(mAngularDamping)); +} + +// Set a new material for this rigid body +/** + * @param material The material you want to set to the body + */ +void RigidBody::setMaterial(const Material& material) { + mMaterial = material; + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, + "Body " + std::to_string(mID) + ": Set Material" + mMaterial.to_string()); +} + // Set the linear velocity of the rigid body. /** * @param linearVelocity Linear velocity vector of the body diff --git a/src/body/RigidBody.h b/src/body/RigidBody.h index ad794513..1a756636 100644 --- a/src/body/RigidBody.h +++ b/src/body/RigidBody.h @@ -31,7 +31,6 @@ #include "CollisionBody.h" #include "engine/Material.h" #include "mathematics/mathematics.h" -#include "memory/MemoryManager.h" /// Namespace reactphysics3d namespace reactphysics3d { @@ -40,6 +39,7 @@ namespace reactphysics3d { struct JointListElement; class Joint; class DynamicsWorld; +class MemoryManager; // Class RigidBody /** @@ -319,18 +319,6 @@ inline bool RigidBody::isGravityEnabled() const { return mIsGravityEnabled; } -// Set the variable to know if the gravity is applied to this rigid body -/** - * @param isEnabled True if you want the gravity to be applied to this body - */ -inline void RigidBody::enableGravity(bool isEnabled) { - mIsGravityEnabled = isEnabled; - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set isGravityEnabled=" + - (mIsGravityEnabled ? "true" : "false")); -} - // Return a reference to the material properties of the rigid body /** * @return A reference to the material of the body @@ -339,17 +327,6 @@ inline Material& RigidBody::getMaterial() { return mMaterial; } -// Set a new material for this rigid body -/** - * @param material The material you want to set to the body - */ -inline void RigidBody::setMaterial(const Material& material) { - mMaterial = material; - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set Material" + mMaterial.to_string()); -} - // Return the linear velocity damping factor /** * @return The linear damping factor of this body @@ -358,19 +335,6 @@ inline decimal RigidBody::getLinearDamping() const { return mLinearDamping; } -// Set the linear damping factor. This is the ratio of the linear velocity -// that the body will lose every at seconds of simulation. -/** - * @param linearDamping The linear damping factor of this body - */ -inline void RigidBody::setLinearDamping(decimal linearDamping) { - assert(linearDamping >= decimal(0.0)); - mLinearDamping = linearDamping; - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set linearDamping=" + std::to_string(mLinearDamping)); -} - // Return the angular velocity damping factor /** * @return The angular damping factor of this body @@ -379,19 +343,6 @@ inline decimal RigidBody::getAngularDamping() const { return mAngularDamping; } -// Set the angular damping factor. This is the ratio of the angular velocity -// that the body will lose at every seconds of simulation. -/** - * @param angularDamping The angular damping factor of this body - */ -inline void RigidBody::setAngularDamping(decimal angularDamping) { - assert(angularDamping >= decimal(0.0)); - mAngularDamping = angularDamping; - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body, - "Body " + std::to_string(mID) + ": Set angularDamping=" + std::to_string(mAngularDamping)); -} - // Return the first element of the linked list of joints involving this body /** * @return The first element of the linked-list of all the joints involving this body diff --git a/src/collision/CollisionCallback.cpp b/src/collision/CollisionCallback.cpp index 1702e40a..30a4b7e6 100644 --- a/src/collision/CollisionCallback.cpp +++ b/src/collision/CollisionCallback.cpp @@ -28,6 +28,7 @@ #include "engine/OverlappingPair.h" #include "memory/MemoryAllocator.h" #include "collision/ContactManifold.h" +#include "memory/MemoryManager.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; diff --git a/src/collision/CollisionCallback.h b/src/collision/CollisionCallback.h index 57ae0f04..0811a6a3 100644 --- a/src/collision/CollisionCallback.h +++ b/src/collision/CollisionCallback.h @@ -26,13 +26,16 @@ #ifndef REACTPHYSICS3D_COLLISION_CALLBACK_H #define REACTPHYSICS3D_COLLISION_CALLBACK_H -// Libraries -#include "collision/ContactManifold.h" - /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations class OverlappingPair; +class ContactManifold; +struct ContactManifoldListElement; +class CollisionBody; +class ProxyShape; +class MemoryManager; // Class CollisionCallback /** diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index f56672ca..09cd69d2 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -35,10 +35,13 @@ #include "collision/CollisionCallback.h" #include "collision/MiddlePhaseTriangleCallback.h" #include "collision/OverlapCallback.h" +#include "collision/NarrowPhaseInfo.h" +#include "collision/ContactManifold.h" +#include "collision/ContactManifoldInfo.h" +#include "utils/Profiler.h" +#include "engine/EventListener.h" +#include "collision/RaycastInfo.h" #include -#include -#include -#include // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; @@ -376,6 +379,20 @@ void CollisionDetection::addAllContactManifoldsToBodies() { } } +// Ray casting method +void CollisionDetection::raycast(RaycastCallback* raycastCallback, + const Ray& ray, + unsigned short raycastWithCategoryMaskBits) const { + + RP3D_PROFILE("CollisionDetection::raycast()", mProfiler); + + RaycastTest rayCastTest(raycastCallback); + + // Ask the broad-phase algorithm to call the testRaycastAgainstShape() + // callback method for each proxy shape hit by the ray in the broad-phase + mBroadPhaseAlgorithm.raycast(ray, rayCastTest, raycastWithCategoryMaskBits); +} + // Add a contact manifold to the linked list of contact manifolds of the two bodies involved // in the corresponding contact void CollisionDetection::addContactManifoldToBody(OverlappingPair* pair) { diff --git a/src/collision/CollisionDetection.h b/src/collision/CollisionDetection.h index ecfa766d..2640c71c 100644 --- a/src/collision/CollisionDetection.h +++ b/src/collision/CollisionDetection.h @@ -29,23 +29,24 @@ // Libraries #include "body/CollisionBody.h" #include "broadphase/BroadPhaseAlgorithm.h" +#include "collision/shapes/CollisionShape.h" #include "engine/OverlappingPair.h" -#include "engine/EventListener.h" -#include "narrowphase/DefaultCollisionDispatch.h" -#include "memory/MemoryManager.h" -#include "constraint/ContactPoint.h" +#include "collision/narrowphase/DefaultCollisionDispatch.h" #include "containers/Map.h" #include "containers/Set.h" -#include /// ReactPhysics3D namespace namespace reactphysics3d { // Declarations -class BroadPhaseAlgorithm; class CollisionWorld; class CollisionCallback; class OverlapCallback; +class RaycastCallback; +class ContactPoint; +class MemoryManager; +class EventListener; +class CollisionDispatch; // Class CollisionDetection /** @@ -84,10 +85,6 @@ class CollisionDetection { /// Broad-phase algorithm BroadPhaseAlgorithm mBroadPhaseAlgorithm; - /// Narrow-phase GJK algorithm - // TODO : Delete this - GJKAlgorithm mNarrowPhaseGJKAlgorithm; - /// Set of pair of bodies that cannot collide between each other Set mNoCollisionPairs; @@ -309,20 +306,6 @@ inline NarrowPhaseAlgorithm* CollisionDetection::selectNarrowPhaseAlgorithm(cons return mCollisionMatrix[shape1Index][shape2Index]; } -// Ray casting method -inline void CollisionDetection::raycast(RaycastCallback* raycastCallback, - const Ray& ray, - unsigned short raycastWithCategoryMaskBits) const { - - RP3D_PROFILE("CollisionDetection::raycast()", mProfiler); - - RaycastTest rayCastTest(raycastCallback); - - // Ask the broad-phase algorithm to call the testRaycastAgainstShape() - // callback method for each proxy shape hit by the ray in the broad-phase - mBroadPhaseAlgorithm.raycast(ray, rayCastTest, raycastWithCategoryMaskBits); -} - // Return a pointer to the world inline CollisionWorld* CollisionDetection::getWorld() { return mWorld; diff --git a/src/collision/ContactManifold.cpp b/src/collision/ContactManifold.cpp index 06374734..65c13402 100644 --- a/src/collision/ContactManifold.cpp +++ b/src/collision/ContactManifold.cpp @@ -24,8 +24,9 @@ ********************************************************************************/ // Libraries -#include #include "ContactManifold.h" +#include "constraint/ContactPoint.h" +#include "collision/ContactManifoldInfo.h" using namespace reactphysics3d; @@ -98,6 +99,25 @@ void ContactManifold::removeContactPoint(ContactPoint* contactPoint) { assert(mNbContactPoints >= 0); } +// Return the largest depth of all the contact points +decimal ContactManifold::getLargestContactDepth() const { + decimal largestDepth = 0.0f; + + assert(mNbContactPoints > 0); + + ContactPoint* contactPoint = mContactPoints; + while(contactPoint != nullptr){ + decimal depth = contactPoint->getPenetrationDepth(); + if (depth > largestDepth) { + largestDepth = depth; + } + + contactPoint = contactPoint->getNext(); + } + + return largestDepth; +} + // Add a contact point void ContactManifold::addContactPoint(const ContactPointInfo* contactPointInfo) { @@ -117,6 +137,20 @@ void ContactManifold::addContactPoint(const ContactPointInfo* contactPointInfo) mNbContactPoints++; } +// Set to true to make the manifold obsolete +void ContactManifold::setIsObsolete(bool isObsolete, bool setContactPoints) { + mIsObsolete = isObsolete; + + if (setContactPoints) { + ContactPoint* contactPoint = mContactPoints; + while (contactPoint != nullptr) { + contactPoint->setIsObsolete(isObsolete); + + contactPoint = contactPoint->getNext(); + } + } +} + // Clear the obsolete contact points void ContactManifold::clearObsoleteContactPoints() { diff --git a/src/collision/ContactManifold.h b/src/collision/ContactManifold.h index ab0afe5f..cfe9af9b 100644 --- a/src/collision/ContactManifold.h +++ b/src/collision/ContactManifold.h @@ -27,17 +27,18 @@ #define REACTPHYSICS3D_CONTACT_MANIFOLD_H // Libraries -#include "body/CollisionBody.h" #include "collision/ProxyShape.h" -#include "constraint/ContactPoint.h" -#include "collision/ContactManifoldInfo.h" -#include "memory/PoolAllocator.h" /// ReactPhysics3D namespace namespace reactphysics3d { // Class declarations class ContactManifold; +class ContactManifoldInfo; +struct ContactPointInfo; +class CollisionBody; +class ContactPoint; +class PoolAllocator; // Structure ContactManifoldListElement /** @@ -353,25 +354,6 @@ inline bool ContactManifold::isAlreadyInIsland() const { return mIsAlreadyInIsland; } -// Return the largest depth of all the contact points -inline decimal ContactManifold::getLargestContactDepth() const { - decimal largestDepth = 0.0f; - - assert(mNbContactPoints > 0); - - ContactPoint* contactPoint = mContactPoints; - while(contactPoint != nullptr){ - decimal depth = contactPoint->getPenetrationDepth(); - if (depth > largestDepth) { - largestDepth = depth; - } - - contactPoint = contactPoint->getNext(); - } - - return largestDepth; -} - // Return a pointer to the previous element in the linked-list inline ContactManifold* ContactManifold::getPrevious() const { return mPrevious; @@ -397,20 +379,6 @@ inline bool ContactManifold::getIsObsolete() const { return mIsObsolete; } -// Set to true to make the manifold obsolete -inline void ContactManifold::setIsObsolete(bool isObsolete, bool setContactPoints) { - mIsObsolete = isObsolete; - - if (setContactPoints) { - ContactPoint* contactPoint = mContactPoints; - while (contactPoint != nullptr) { - contactPoint->setIsObsolete(isObsolete); - - contactPoint = contactPoint->getNext(); - } - } -} - } #endif diff --git a/src/collision/ContactManifoldInfo.cpp b/src/collision/ContactManifoldInfo.cpp index e1ca749d..e856b16b 100644 --- a/src/collision/ContactManifoldInfo.cpp +++ b/src/collision/ContactManifoldInfo.cpp @@ -25,6 +25,7 @@ // Libraries #include "ContactManifoldInfo.h" +#include "collision/ContactPointInfo.h" using namespace reactphysics3d; diff --git a/src/collision/ContactManifoldInfo.h b/src/collision/ContactManifoldInfo.h index b2687da5..5af35828 100644 --- a/src/collision/ContactManifoldInfo.h +++ b/src/collision/ContactManifoldInfo.h @@ -27,12 +27,16 @@ #define REACTPHYSICS3D_CONTACT_MANIFOLD_INFO_H // Libraries -#include "collision/ContactPointInfo.h" -#include "memory/MemoryAllocator.h" +#include "configuration.h" /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class MemoryAllocator; +struct ContactPointInfo; +class Transform; + // Constants const int8 MAX_CONTACT_POINTS_IN_MANIFOLD = 4; // Maximum number of contacts in the manifold diff --git a/src/collision/ContactManifoldSet.cpp b/src/collision/ContactManifoldSet.cpp index c60f01f6..4997a915 100644 --- a/src/collision/ContactManifoldSet.cpp +++ b/src/collision/ContactManifoldSet.cpp @@ -25,6 +25,10 @@ // Libraries #include "ContactManifoldSet.h" +#include "constraint/ContactPoint.h" +#include "collision/ContactManifoldInfo.h" +#include "ProxyShape.h" +#include "collision/ContactManifold.h" using namespace reactphysics3d; @@ -65,6 +69,34 @@ void ContactManifoldSet::addContactManifold(const ContactManifoldInfo* contactMa } } +// Return the total number of contact points in the set of manifolds +int ContactManifoldSet::getTotalNbContactPoints() const { + int nbPoints = 0; + + ContactManifold* manifold = mManifolds; + while (manifold != nullptr) { + nbPoints += manifold->getNbContactPoints(); + + manifold = manifold->getNext(); + } + + return nbPoints; +} + +// Return the maximum number of contact manifolds allowed between to collision shapes +int ContactManifoldSet::computeNbMaxContactManifolds(const CollisionShape* shape1, const CollisionShape* shape2) { + + // If both shapes are convex + if (shape1->isConvex() && shape2->isConvex()) { + return mWorldSettings.nbMaxContactManifoldsConvexShape; + + } // If there is at least one concave shape + else { + return mWorldSettings.nbMaxContactManifoldsConcaveShape; + } +} + + // Update a previous similar manifold with a new one void ContactManifoldSet::updateManifoldWithNewOne(ContactManifold* oldManifold, const ContactManifoldInfo* newManifold) { diff --git a/src/collision/ContactManifoldSet.h b/src/collision/ContactManifoldSet.h index 4c6e0b85..540dc501 100644 --- a/src/collision/ContactManifoldSet.h +++ b/src/collision/ContactManifoldSet.h @@ -26,11 +26,16 @@ #ifndef REACTPHYSICS3D_CONTACT_MANIFOLD_SET_H #define REACTPHYSICS3D_CONTACT_MANIFOLD_SET_H -// Libraries -#include "ContactManifold.h" - namespace reactphysics3d { +// Declarations +class ContactManifold; +class ContactManifoldInfo; +class ProxyShape; +class MemoryAllocator; +struct WorldSettings; +class CollisionShape; + // Constants const int MAX_MANIFOLDS_IN_CONTACT_MANIFOLD_SET = 3; // Maximum number of contact manifolds in the set const int CONTACT_CUBEMAP_FACE_NB_SUBDIVISIONS = 3; // N Number for the N x N subdivisions of the cubemap @@ -151,33 +156,6 @@ inline ContactManifold* ContactManifoldSet::getContactManifolds() const { return mManifolds; } -// Return the total number of contact points in the set of manifolds -inline int ContactManifoldSet::getTotalNbContactPoints() const { - int nbPoints = 0; - - ContactManifold* manifold = mManifolds; - while (manifold != nullptr) { - nbPoints += manifold->getNbContactPoints(); - - manifold = manifold->getNext(); - } - - return nbPoints; -} - -// Return the maximum number of contact manifolds allowed between to collision shapes -inline int ContactManifoldSet::computeNbMaxContactManifolds(const CollisionShape* shape1, const CollisionShape* shape2) { - - // If both shapes are convex - if (shape1->isConvex() && shape2->isConvex()) { - return mWorldSettings.nbMaxContactManifoldsConvexShape; - - } // If there is at least one concave shape - else { - return mWorldSettings.nbMaxContactManifoldsConcaveShape; - } -} - } #endif diff --git a/src/collision/ContactPointInfo.h b/src/collision/ContactPointInfo.h index 6fbf9834..3d56d8ae 100644 --- a/src/collision/ContactPointInfo.h +++ b/src/collision/ContactPointInfo.h @@ -27,13 +27,15 @@ #define REACTPHYSICS3D_CONTACT_POINT_INFO_H // Libraries -#include "body/CollisionBody.h" #include "mathematics/mathematics.h" #include "configuration.h" /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class CollisionBody; + // Structure ContactPointInfo /** * This structure contains informations about a collision contact diff --git a/src/collision/MiddlePhaseTriangleCallback.cpp b/src/collision/MiddlePhaseTriangleCallback.cpp index a53271a4..3ac8b7ef 100644 --- a/src/collision/MiddlePhaseTriangleCallback.cpp +++ b/src/collision/MiddlePhaseTriangleCallback.cpp @@ -25,6 +25,9 @@ // Libraries #include "collision/MiddlePhaseTriangleCallback.h" +#include "engine/OverlappingPair.h" +#include "collision/NarrowPhaseInfo.h" +#include "collision/shapes/TriangleShape.h" using namespace reactphysics3d; diff --git a/src/collision/MiddlePhaseTriangleCallback.h b/src/collision/MiddlePhaseTriangleCallback.h index b4798a2c..9cd9b593 100644 --- a/src/collision/MiddlePhaseTriangleCallback.h +++ b/src/collision/MiddlePhaseTriangleCallback.h @@ -26,13 +26,24 @@ #ifndef REACTPHYSICS3D_MIDDLE_PHASE_TRIANGLE_CALLBACK_H #define REACTPHYSICS3D_MIDDLE_PHASE_TRIANGLE_CALLBACK_H -// Libraries +#include "configuration.h" #include "collision/shapes/ConcaveShape.h" -#include "collision/narrowphase/NarrowPhaseAlgorithm.h" /// Namespace ReactPhysics3D namespace reactphysics3d { +// Libraries + +// Declarations +class ConcaveShape; +class OverlappingPair; +class NarrowPhaseAlgorithm; +class ProxyShape; +class MemoryAllocator; +class Profiler; +struct NarrowPhaseInfo; +struct Vector3; + // Class ConvexVsTriangleCallback /** * This class is used to report a collision between the triangle diff --git a/src/collision/NarrowPhaseInfo.cpp b/src/collision/NarrowPhaseInfo.cpp index 2c7a226c..608ee90f 100644 --- a/src/collision/NarrowPhaseInfo.cpp +++ b/src/collision/NarrowPhaseInfo.cpp @@ -24,7 +24,6 @@ ********************************************************************************/ // Libraries -#include #include "NarrowPhaseInfo.h" #include "ContactPointInfo.h" #include "collision/shapes/TriangleShape.h" diff --git a/src/collision/NarrowPhaseInfo.h b/src/collision/NarrowPhaseInfo.h index f9ea1ac9..f4af08e6 100644 --- a/src/collision/NarrowPhaseInfo.h +++ b/src/collision/NarrowPhaseInfo.h @@ -27,14 +27,16 @@ #define REACTPHYSICS3D_NARROW_PHASE_INFO_H // Libraries -#include "shapes/CollisionShape.h" -#include "collision/ContactManifoldInfo.h" #include "engine/OverlappingPair.h" /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class CollisionShape; struct LastFrameCollisionInfo; +class ContactManifoldInfo; +struct ContactPointInfo; // Class NarrowPhaseInfo /** diff --git a/src/collision/OverlapCallback.h b/src/collision/OverlapCallback.h index bbba73d1..d435bd63 100644 --- a/src/collision/OverlapCallback.h +++ b/src/collision/OverlapCallback.h @@ -26,12 +26,12 @@ #ifndef REACTPHYSICS3D_OVERLAP_CALLBACK_H #define REACTPHYSICS3D_OVERLAP_CALLBACK_H -// Libraries -#include "body/CollisionBody.h" - /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class CollisionBody; + // Class OverlapCallback /** * This class can be used to register a callback for collision overlap queries. diff --git a/src/collision/PolyhedronMesh.cpp b/src/collision/PolyhedronMesh.cpp index 64db474e..92474c3e 100644 --- a/src/collision/PolyhedronMesh.cpp +++ b/src/collision/PolyhedronMesh.cpp @@ -26,6 +26,7 @@ // Libraries #include "PolyhedronMesh.h" #include "memory/MemoryManager.h" +#include "collision/PolygonVertexArray.h" using namespace reactphysics3d; diff --git a/src/collision/PolyhedronMesh.h b/src/collision/PolyhedronMesh.h index 8720a8db..07da6f46 100644 --- a/src/collision/PolyhedronMesh.h +++ b/src/collision/PolyhedronMesh.h @@ -29,11 +29,13 @@ // Libraries #include "mathematics/mathematics.h" #include "HalfEdgeStructure.h" -#include "collision/PolygonVertexArray.h" -#include "memory/DefaultAllocator.h" namespace reactphysics3d { +// Declarations +class DefaultAllocator; +class PolygonVertexArray; + // Class PolyhedronMesh /** * This class describes a polyhedron mesh made of faces and vertices. diff --git a/src/collision/ProxyShape.cpp b/src/collision/ProxyShape.cpp index c9d38fbe..ae0e46dc 100644 --- a/src/collision/ProxyShape.cpp +++ b/src/collision/ProxyShape.cpp @@ -25,6 +25,9 @@ // Libraries #include "ProxyShape.h" +#include "utils/Logger.h" +#include "collision/RaycastInfo.h" +#include "memory/MemoryManager.h" using namespace reactphysics3d; @@ -57,6 +60,45 @@ bool ProxyShape::testPointInside(const Vector3& worldPoint) { return mCollisionShape->testPointInside(localPoint, this); } +// Set the collision category bits +/** + * @param collisionCategoryBits The collision category bits mask of the proxy shape + */ +void ProxyShape::setCollisionCategoryBits(unsigned short collisionCategoryBits) { + mCollisionCategoryBits = collisionCategoryBits; + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape, + "ProxyShape " + std::to_string(mBroadPhaseID) + ": Set collisionCategoryBits=" + + std::to_string(mCollisionCategoryBits)); +} + +// Set the collision bits mask +/** + * @param collideWithMaskBits The bits mask that specifies with which collision category this shape will collide + */ +void ProxyShape::setCollideWithMaskBits(unsigned short collideWithMaskBits) { + mCollideWithMaskBits = collideWithMaskBits; + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape, + "ProxyShape " + std::to_string(mBroadPhaseID) + ": Set collideWithMaskBits=" + + std::to_string(mCollideWithMaskBits)); +} + +// Set the local to parent body transform +void ProxyShape::setLocalToBodyTransform(const Transform& transform) { + + mLocalToBodyTransform = transform; + + mBody->setIsSleeping(false); + + // Notify the body that the proxy shape has to be updated in the broad-phase + mBody->updateProxyShapeInBroadPhase(this, true); + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape, + "ProxyShape " + std::to_string(mBroadPhaseID) + ": Set localToBodyTransform=" + + mLocalToBodyTransform.to_string()); +} + // Raycast method with feedback information /** * @param ray Ray to use for the raycasting diff --git a/src/collision/ProxyShape.h b/src/collision/ProxyShape.h index 9e4ea298..85960fcb 100644 --- a/src/collision/ProxyShape.h +++ b/src/collision/ProxyShape.h @@ -28,11 +28,13 @@ // Libraries #include "body/CollisionBody.h" -#include "shapes/CollisionShape.h" -#include "memory/MemoryManager.h" +#include "collision/shapes/CollisionShape.h" namespace reactphysics3d { +// Declarations +class MemoryManager; + // Class ProxyShape /** * The CollisionShape instances are supposed to be unique for memory optimization. For instance, @@ -265,21 +267,6 @@ inline const Transform& ProxyShape::getLocalToBodyTransform() const { return mLocalToBodyTransform; } -// Set the local to parent body transform -inline void ProxyShape::setLocalToBodyTransform(const Transform& transform) { - - mLocalToBodyTransform = transform; - - mBody->setIsSleeping(false); - - // Notify the body that the proxy shape has to be updated in the broad-phase - mBody->updateProxyShapeInBroadPhase(this, true); - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape, - "ProxyShape " + std::to_string(mBroadPhaseID) + ": Set localToBodyTransform=" + - mLocalToBodyTransform.to_string()); -} - // Return the local to world transform /** * @return The transformation that transforms the local-space of the collision @@ -323,18 +310,6 @@ inline unsigned short ProxyShape::getCollisionCategoryBits() const { return mCollisionCategoryBits; } -// Set the collision category bits -/** - * @param collisionCategoryBits The collision category bits mask of the proxy shape - */ -inline void ProxyShape::setCollisionCategoryBits(unsigned short collisionCategoryBits) { - mCollisionCategoryBits = collisionCategoryBits; - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape, - "ProxyShape " + std::to_string(mBroadPhaseID) + ": Set collisionCategoryBits=" + - std::to_string(mCollisionCategoryBits)); -} - // Return the collision bits mask /** * @return The bits mask that specifies with which collision category this shape will collide @@ -343,18 +318,6 @@ inline unsigned short ProxyShape::getCollideWithMaskBits() const { return mCollideWithMaskBits; } -// Set the collision bits mask -/** - * @param collideWithMaskBits The bits mask that specifies with which collision category this shape will collide - */ -inline void ProxyShape::setCollideWithMaskBits(unsigned short collideWithMaskBits) { - mCollideWithMaskBits = collideWithMaskBits; - - RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape, - "ProxyShape " + std::to_string(mBroadPhaseID) + ": Set collideWithMaskBits=" + - std::to_string(mCollideWithMaskBits)); -} - // Return the broad-phase id inline int ProxyShape::getBroadPhaseId() const { return mBroadPhaseID; diff --git a/src/collision/RaycastInfo.h b/src/collision/RaycastInfo.h index 06510e04..1e838331 100644 --- a/src/collision/RaycastInfo.h +++ b/src/collision/RaycastInfo.h @@ -28,7 +28,6 @@ // Libraries #include "mathematics/Vector3.h" -#include "mathematics/Ray.h" /// ReactPhysics3D namespace namespace reactphysics3d { @@ -37,6 +36,7 @@ namespace reactphysics3d { class CollisionBody; class ProxyShape; class CollisionShape; +struct Ray; // Structure RaycastInfo /** diff --git a/src/collision/TriangleMesh.cpp b/src/collision/TriangleMesh.cpp index 3fdc48c5..071558d6 100644 --- a/src/collision/TriangleMesh.cpp +++ b/src/collision/TriangleMesh.cpp @@ -25,5 +25,12 @@ // Libraries #include "TriangleMesh.h" +#include "memory/MemoryManager.h" using namespace reactphysics3d; + +// Constructor +TriangleMesh::TriangleMesh() + : mTriangleArrays(MemoryManager::getBaseAllocator()) { + +} diff --git a/src/collision/TriangleMesh.h b/src/collision/TriangleMesh.h index 69196d22..673a7b52 100644 --- a/src/collision/TriangleMesh.h +++ b/src/collision/TriangleMesh.h @@ -28,12 +28,14 @@ // Libraries #include -#include "TriangleVertexArray.h" -#include "memory/MemoryManager.h" #include "containers/List.h" namespace reactphysics3d { +// Declarations +class TriangleVertexArray; +class MemoryManager; + // Class TriangleMesh /** * This class represents a mesh made of triangles. A TriangleMesh contains @@ -52,9 +54,7 @@ class TriangleMesh { public: /// Constructor - TriangleMesh() : mTriangleArrays(MemoryManager::getBaseAllocator()) { - - } + TriangleMesh(); /// Destructor ~TriangleMesh() = default; diff --git a/src/collision/TriangleVertexArray.h b/src/collision/TriangleVertexArray.h index 4fe2fe07..7bc37593 100644 --- a/src/collision/TriangleVertexArray.h +++ b/src/collision/TriangleVertexArray.h @@ -31,6 +31,7 @@ namespace reactphysics3d { +// Declarations struct Vector3; // Class TriangleVertexArray diff --git a/src/collision/broadphase/BroadPhaseAlgorithm.cpp b/src/collision/broadphase/BroadPhaseAlgorithm.cpp index 0d722a0a..47a96130 100644 --- a/src/collision/broadphase/BroadPhaseAlgorithm.cpp +++ b/src/collision/broadphase/BroadPhaseAlgorithm.cpp @@ -27,6 +27,8 @@ #include "BroadPhaseAlgorithm.h" #include "collision/CollisionDetection.h" #include "utils/Profiler.h" +#include "collision/RaycastInfo.h" +#include "memory/MemoryManager.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; @@ -96,6 +98,31 @@ void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) { mNbMovedShapes++; } +// Return true if the two broad-phase collision shapes are overlapping +bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1, + const ProxyShape* shape2) const { + + if (shape1->getBroadPhaseId() == -1 || shape2->getBroadPhaseId() == -1) return false; + + // Get the two AABBs of the collision shapes + const AABB& aabb1 = mDynamicAABBTree.getFatAABB(shape1->getBroadPhaseId()); + const AABB& aabb2 = mDynamicAABBTree.getFatAABB(shape2->getBroadPhaseId()); + + // Check if the two AABBs are overlapping + return aabb1.testCollision(aabb2); +} + +// Ray casting method +void BroadPhaseAlgorithm::raycast(const Ray& ray, RaycastTest& raycastTest, + unsigned short raycastWithCategoryMaskBits) const { + + RP3D_PROFILE("BroadPhaseAlgorithm::raycast()", mProfiler); + + BroadPhaseRaycastCallback broadPhaseRaycastCallback(mDynamicAABBTree, raycastWithCategoryMaskBits, raycastTest); + + mDynamicAABBTree.raycast(ray, broadPhaseRaycastCallback); +} + // Remove a collision shape from the array of shapes that have moved in the last simulation step // and that need to be tested again for broad-phase overlapping. void BroadPhaseAlgorithm::removeMovedCollisionShape(int broadPhaseID) { diff --git a/src/collision/broadphase/BroadPhaseAlgorithm.h b/src/collision/broadphase/BroadPhaseAlgorithm.h index 4e8360b9..7096fe01 100644 --- a/src/collision/broadphase/BroadPhaseAlgorithm.h +++ b/src/collision/broadphase/BroadPhaseAlgorithm.h @@ -27,10 +27,7 @@ #define REACTPHYSICS3D_BROAD_PHASE_ALGORITHM_H // Libraries -#include "body/CollisionBody.h" -#include "collision/ProxyShape.h" #include "DynamicAABBTree.h" -#include "utils/Profiler.h" #include "containers/LinkedList.h" /// Namespace ReactPhysics3D @@ -39,6 +36,10 @@ namespace reactphysics3d { // Declarations class CollisionDetection; class BroadPhaseAlgorithm; +class CollisionBody; +class ProxyShape; +class MemoryManager; +class Profiler; // Structure BroadPhasePair /** @@ -242,36 +243,11 @@ inline bool BroadPhasePair::smallerThan(const BroadPhasePair& pair1, const Broad return false; } -// Return true if the two broad-phase collision shapes are overlapping -inline bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1, - const ProxyShape* shape2) const { - - if (shape1->getBroadPhaseId() == -1 || shape2->getBroadPhaseId() == -1) return false; - - // Get the two AABBs of the collision shapes - const AABB& aabb1 = mDynamicAABBTree.getFatAABB(shape1->getBroadPhaseId()); - const AABB& aabb2 = mDynamicAABBTree.getFatAABB(shape2->getBroadPhaseId()); - - // Check if the two AABBs are overlapping - return aabb1.testCollision(aabb2); -} - // Return the fat AABB of a given broad-phase shape inline const AABB& BroadPhaseAlgorithm::getFatAABB(int broadPhaseId) const { return mDynamicAABBTree.getFatAABB(broadPhaseId); } -// Ray casting method -inline void BroadPhaseAlgorithm::raycast(const Ray& ray, RaycastTest& raycastTest, - unsigned short raycastWithCategoryMaskBits) const { - - RP3D_PROFILE("BroadPhaseAlgorithm::raycast()", mProfiler); - - BroadPhaseRaycastCallback broadPhaseRaycastCallback(mDynamicAABBTree, raycastWithCategoryMaskBits, raycastTest); - - mDynamicAABBTree.raycast(ray, broadPhaseRaycastCallback); -} - // Return the proxy shape corresponding to the broad-phase node id in parameter inline ProxyShape* BroadPhaseAlgorithm::getProxyShapeForBroadPhaseId(int broadPhaseId) const { return static_cast(mDynamicAABBTree.getNodeDataPointer(broadPhaseId)); diff --git a/src/collision/broadphase/DynamicAABBTree.h b/src/collision/broadphase/DynamicAABBTree.h index 936595a5..54cfab03 100644 --- a/src/collision/broadphase/DynamicAABBTree.h +++ b/src/collision/broadphase/DynamicAABBTree.h @@ -29,8 +29,6 @@ // Libraries #include "configuration.h" #include "collision/shapes/AABB.h" -#include "body/CollisionBody.h" -#include "memory/MemoryAllocator.h" /// Namespace ReactPhysics3D namespace reactphysics3d { @@ -39,7 +37,12 @@ namespace reactphysics3d { class BroadPhaseAlgorithm; class BroadPhaseRaycastTestCallback; class DynamicAABBTreeOverlapCallback; +class CollisionBody; struct RaycastTest; +class AABB; +class Profiler; +class MemoryAllocator; + // Structure TreeNode /** diff --git a/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp b/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp index dce9b04b..63170f55 100755 --- a/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp +++ b/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp @@ -26,6 +26,7 @@ // Libraries #include "CapsuleVsCapsuleAlgorithm.h" #include "collision/shapes/CapsuleShape.h" +#include "collision/NarrowPhaseInfo.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; diff --git a/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.h b/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.h index b122ca14..181ddf25 100644 --- a/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.h +++ b/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.h @@ -27,14 +27,15 @@ #define REACTPHYSICS3D_CAPSULE_VS_CAPSULE_ALGORITHM_H // Libraries -#include "body/Body.h" -#include "constraint/ContactPoint.h" #include "NarrowPhaseAlgorithm.h" - /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class Body; +class ContactPoint; + // Class CapsuleVsCapsuleAlgorithm /** * This class is used to compute the narrow-phase collision detection diff --git a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp index 33a381f0..fcf39148 100644 --- a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp @@ -29,6 +29,8 @@ #include "GJK/GJKAlgorithm.h" #include "collision/shapes/CapsuleShape.h" #include "collision/shapes/ConvexPolyhedronShape.h" +#include "collision/NarrowPhaseInfo.h" +#include "collision/ContactPointInfo.h" #include // We want to use the ReactPhysics3D namespace diff --git a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.h b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.h index 58bb14fb..ca0aaf26 100644 --- a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.h +++ b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.h @@ -27,14 +27,15 @@ #define REACTPHYSICS3D_CAPSULE_VS_CONVEX_POLYHEDRON_ALGORITHM_H // Libraries -#include "body/Body.h" -#include "constraint/ContactPoint.h" #include "NarrowPhaseAlgorithm.h" - /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class ContactPoint; +class Body; + // Class CapsuleVsConvexPolyhedronAlgorithm /** * This class is used to compute the narrow-phase collision detection diff --git a/src/collision/narrowphase/CollisionDispatch.h b/src/collision/narrowphase/CollisionDispatch.h index d8351d6a..a1bb022c 100644 --- a/src/collision/narrowphase/CollisionDispatch.h +++ b/src/collision/narrowphase/CollisionDispatch.h @@ -27,10 +27,13 @@ #define REACTPHYSICS3D_COLLISION_DISPATCH_H // Libraries -#include "NarrowPhaseAlgorithm.h" namespace reactphysics3d { +// Declarations +class NarrowPhaseAlgorithm; +class Profiler; + // Class CollisionDispatch /** * This is the abstract base class for dispatching the narrow-phase diff --git a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp index 375814cd..3928cb5d 100644 --- a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp @@ -27,6 +27,7 @@ #include "ConvexPolyhedronVsConvexPolyhedronAlgorithm.h" #include "GJK/GJKAlgorithm.h" #include "SAT/SATAlgorithm.h" +#include "collision/NarrowPhaseInfo.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; diff --git a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h index ddd10585..a60bfa9a 100644 --- a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h +++ b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h @@ -27,14 +27,15 @@ #define REACTPHYSICS3D_CONVEX_POLYHEDRON_VS_CONVEX_POLYHEDRON_ALGORITHM_H // Libraries -#include "body/Body.h" -#include "constraint/ContactPoint.h" #include "NarrowPhaseAlgorithm.h" - /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class Body; +class ContactPoint; + // Class ConvexPolyhedronVsConvexPolyhedronAlgorithm /** * This class is used to compute the narrow-phase collision detection diff --git a/src/collision/narrowphase/DefaultCollisionDispatch.h b/src/collision/narrowphase/DefaultCollisionDispatch.h index fe22b4a9..55aed901 100644 --- a/src/collision/narrowphase/DefaultCollisionDispatch.h +++ b/src/collision/narrowphase/DefaultCollisionDispatch.h @@ -34,7 +34,6 @@ #include "CapsuleVsCapsuleAlgorithm.h" #include "CapsuleVsConvexPolyhedronAlgorithm.h" #include "ConvexPolyhedronVsConvexPolyhedronAlgorithm.h" -#include "GJK/GJKAlgorithm.h" namespace reactphysics3d { diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp index a7d647ae..f01db2be 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp @@ -30,9 +30,8 @@ #include "collision/shapes/TriangleShape.h" #include "configuration.h" #include "utils/Profiler.h" -#include -#include -#include +#include "collision/NarrowPhaseInfo.h" +#include "collision/narrowphase/GJK/VoronoiSimplex.h" #include // We want to use the ReactPhysics3D namespace diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.h b/src/collision/narrowphase/GJK/GJKAlgorithm.h index ac9cd652..5743e036 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.h +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.h @@ -27,14 +27,18 @@ #define REACTPHYSICS3D_GJK_ALGORITHM_H // Libraries -#include "collision/ContactManifoldInfo.h" -#include "collision/NarrowPhaseInfo.h" -#include "collision/shapes/ConvexShape.h" -#include "VoronoiSimplex.h" +#include "decimal.h" /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class ContactManifoldInfo; +struct NarrowPhaseInfo; +class ConvexShape; +class Profiler; +class VoronoiSimplex; + // Constants constexpr decimal REL_ERROR = decimal(1.0e-3); constexpr decimal REL_ERROR_SQUARE = REL_ERROR * REL_ERROR; diff --git a/src/collision/narrowphase/GJK/VoronoiSimplex.cpp b/src/collision/narrowphase/GJK/VoronoiSimplex.cpp index 590182ac..edf4c741 100644 --- a/src/collision/narrowphase/GJK/VoronoiSimplex.cpp +++ b/src/collision/narrowphase/GJK/VoronoiSimplex.cpp @@ -25,7 +25,7 @@ // Libraries #include "VoronoiSimplex.h" -#include +#include "mathematics/Vector2.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; diff --git a/src/collision/narrowphase/GJK/VoronoiSimplex.h b/src/collision/narrowphase/GJK/VoronoiSimplex.h index 47f1b2c2..e4b1bd86 100644 --- a/src/collision/narrowphase/GJK/VoronoiSimplex.h +++ b/src/collision/narrowphase/GJK/VoronoiSimplex.h @@ -27,7 +27,7 @@ #define REACTPHYSICS3D_VORONOI_SIMPLEX_H // Libraries -#include "mathematics/mathematics.h" +#include "mathematics/Vector3.h" /// ReactPhysics3D namespace namespace reactphysics3d { diff --git a/src/collision/narrowphase/NarrowPhaseAlgorithm.h b/src/collision/narrowphase/NarrowPhaseAlgorithm.h index 3088d874..7675c1c4 100644 --- a/src/collision/narrowphase/NarrowPhaseAlgorithm.h +++ b/src/collision/narrowphase/NarrowPhaseAlgorithm.h @@ -27,16 +27,19 @@ #define REACTPHYSICS3D_NARROW_PHASE_ALGORITHM_H // Libraries -#include "body/Body.h" -#include "collision/ContactManifoldInfo.h" -#include "memory/PoolAllocator.h" -#include "engine/OverlappingPair.h" -#include "collision/NarrowPhaseInfo.h" /// Namespace ReactPhysics3D namespace reactphysics3d { class CollisionDetection; +class Body; +class ContactManifoldInfo; +class PoolAllocator; +class OverlappingPair; +struct NarrowPhaseInfo; +struct ContactPointInfo; +class Profiler; +class MemoryAllocator; // Class NarrowPhaseCallback /** diff --git a/src/collision/narrowphase/SAT/SATAlgorithm.cpp b/src/collision/narrowphase/SAT/SATAlgorithm.cpp index c4b0fbbe..8fbb76f7 100644 --- a/src/collision/narrowphase/SAT/SATAlgorithm.cpp +++ b/src/collision/narrowphase/SAT/SATAlgorithm.cpp @@ -31,11 +31,9 @@ #include "collision/shapes/SphereShape.h" #include "engine/OverlappingPair.h" #include "collision/shapes/TriangleShape.h" +#include "collision/NarrowPhaseInfo.h" #include "configuration.h" #include "utils/Profiler.h" -#include -#include -#include #include // We want to use the ReactPhysics3D namespace diff --git a/src/collision/narrowphase/SAT/SATAlgorithm.h b/src/collision/narrowphase/SAT/SATAlgorithm.h index 0402067f..9c8e2d21 100644 --- a/src/collision/narrowphase/SAT/SATAlgorithm.h +++ b/src/collision/narrowphase/SAT/SATAlgorithm.h @@ -27,16 +27,20 @@ #define REACTPHYSICS3D_SAT_ALGORITHM_H // Libraries -#include "collision/ContactManifoldInfo.h" -#include "collision/NarrowPhaseInfo.h" -#include "collision/shapes/ConvexPolyhedronShape.h" - +#include "decimal.h" +#include "collision/HalfEdgeStructure.h" /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations class CapsuleShape; class SphereShape; +class ContactManifoldInfo; +struct NarrowPhaseInfo; +class ConvexPolyhedronShape; +class MemoryAllocator; +class Profiler; // Class SATAlgorithm class SATAlgorithm { diff --git a/src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp b/src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp index fa5d68b9..4c1c0f9f 100755 --- a/src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp @@ -27,6 +27,7 @@ #include "SphereVsCapsuleAlgorithm.h" #include "collision/shapes/SphereShape.h" #include "collision/shapes/CapsuleShape.h" +#include "collision/NarrowPhaseInfo.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; diff --git a/src/collision/narrowphase/SphereVsCapsuleAlgorithm.h b/src/collision/narrowphase/SphereVsCapsuleAlgorithm.h index c7c4b39e..9d81cc2e 100644 --- a/src/collision/narrowphase/SphereVsCapsuleAlgorithm.h +++ b/src/collision/narrowphase/SphereVsCapsuleAlgorithm.h @@ -27,14 +27,16 @@ #define REACTPHYSICS3D_SPHERE_VS_CAPSULE_ALGORITHM_H // Libraries -#include "body/Body.h" -#include "constraint/ContactPoint.h" #include "NarrowPhaseAlgorithm.h" /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class Body; +class ContactPoint; + // Class SphereVsCapsuleAlgorithm /** * This class is used to compute the narrow-phase collision detection diff --git a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp index 8d4f562c..6fdc4eed 100644 --- a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp @@ -27,6 +27,7 @@ #include "SphereVsConvexPolyhedronAlgorithm.h" #include "GJK/GJKAlgorithm.h" #include "SAT/SATAlgorithm.h" +#include "collision/NarrowPhaseInfo.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; diff --git a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.h b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.h index 1929f43c..f105b967 100644 --- a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.h +++ b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.h @@ -27,14 +27,15 @@ #define REACTPHYSICS3D_SPHERE_VS_CONVEX_POLYHEDRON_ALGORITHM_H // Libraries -#include "body/Body.h" -#include "constraint/ContactPoint.h" #include "NarrowPhaseAlgorithm.h" - /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class ContactPoint; +class Body; + // Class SphereVsConvexPolyhedronAlgorithm /** * This class is used to compute the narrow-phase collision detection diff --git a/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp b/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp index 8103380e..4028c4bc 100755 --- a/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp @@ -26,6 +26,7 @@ // Libraries #include "SphereVsSphereAlgorithm.h" #include "collision/shapes/SphereShape.h" +#include "collision/NarrowPhaseInfo.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; diff --git a/src/collision/narrowphase/SphereVsSphereAlgorithm.h b/src/collision/narrowphase/SphereVsSphereAlgorithm.h index 142053c4..2cf04951 100644 --- a/src/collision/narrowphase/SphereVsSphereAlgorithm.h +++ b/src/collision/narrowphase/SphereVsSphereAlgorithm.h @@ -27,14 +27,15 @@ #define REACTPHYSICS3D_SPHERE_VS_SPHERE_ALGORITHM_H // Libraries -#include "body/Body.h" -#include "constraint/ContactPoint.h" #include "NarrowPhaseAlgorithm.h" - /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class ContactPoint; +class Body; + // Class SphereVsSphereAlgorithm /** * This class is used to compute the narrow-phase collision detection diff --git a/src/collision/shapes/BoxShape.cpp b/src/collision/shapes/BoxShape.cpp index 109b736a..7271650c 100644 --- a/src/collision/shapes/BoxShape.cpp +++ b/src/collision/shapes/BoxShape.cpp @@ -28,6 +28,7 @@ #include "collision/ProxyShape.h" #include "configuration.h" #include "memory/MemoryManager.h" +#include "collision/RaycastInfo.h" #include using namespace reactphysics3d; diff --git a/src/collision/shapes/BoxShape.h b/src/collision/shapes/BoxShape.h index 8148d184..fdaf7c27 100644 --- a/src/collision/shapes/BoxShape.h +++ b/src/collision/shapes/BoxShape.h @@ -27,15 +27,16 @@ #define REACTPHYSICS3D_BOX_SHAPE_H // Libraries -#include #include "ConvexPolyhedronShape.h" -#include "body/CollisionBody.h" #include "mathematics/mathematics.h" -#include "memory/DefaultAllocator.h" /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class CollisionBody; +class DefaultAllocator; + // Class BoxShape /** * This class represents a 3D box shape. Those axis are unit length. diff --git a/src/collision/shapes/CapsuleShape.cpp b/src/collision/shapes/CapsuleShape.cpp index 3f89d090..85415b05 100644 --- a/src/collision/shapes/CapsuleShape.cpp +++ b/src/collision/shapes/CapsuleShape.cpp @@ -27,6 +27,7 @@ #include "CapsuleShape.h" #include "collision/ProxyShape.h" #include "configuration.h" +#include "collision/RaycastInfo.h" #include using namespace reactphysics3d; diff --git a/src/collision/shapes/CapsuleShape.h b/src/collision/shapes/CapsuleShape.h index c595da77..bcf882d8 100644 --- a/src/collision/shapes/CapsuleShape.h +++ b/src/collision/shapes/CapsuleShape.h @@ -28,12 +28,14 @@ // Libraries #include "ConvexShape.h" -#include "body/CollisionBody.h" #include "mathematics/mathematics.h" // ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class CollisionBody; + // Class CapsuleShape /** * This class represents a capsule collision shape that is defined around the Y axis. diff --git a/src/collision/shapes/CollisionShape.h b/src/collision/shapes/CollisionShape.h index 990ef33f..d79765cd 100644 --- a/src/collision/shapes/CollisionShape.h +++ b/src/collision/shapes/CollisionShape.h @@ -28,17 +28,20 @@ // Libraries #include -#include -#include "mathematics/Vector3.h" -#include "mathematics/Matrix3x3.h" -#include "mathematics/Ray.h" -#include "AABB.h" -#include "collision/RaycastInfo.h" -#include "memory/PoolAllocator.h" -#include "utils/Profiler.h" +#include "configuration.h" /// ReactPhysics3D namespace namespace reactphysics3d { + +// Declarations +class Profiler; +class PoolAllocator; +class AABB; +class Transform; +struct Ray; +struct RaycastInfo; +struct Vector3; +class Matrix3x3; /// Type of collision shapes enum class CollisionShapeType {SPHERE, CAPSULE, CONVEX_POLYHEDRON, CONCAVE_SHAPE}; diff --git a/src/collision/shapes/ConcaveMeshShape.cpp b/src/collision/shapes/ConcaveMeshShape.cpp index 21677154..3779b355 100644 --- a/src/collision/shapes/ConcaveMeshShape.cpp +++ b/src/collision/shapes/ConcaveMeshShape.cpp @@ -26,6 +26,10 @@ // Libraries #include "ConcaveMeshShape.h" #include "memory/MemoryManager.h" +#include "collision/RaycastInfo.h" +#include "collision/TriangleMesh.h" +#include "utils/Profiler.h" +#include "collision/TriangleVertexArray.h" using namespace reactphysics3d; diff --git a/src/collision/shapes/ConcaveMeshShape.h b/src/collision/shapes/ConcaveMeshShape.h index e8ad78e5..5fea50f2 100644 --- a/src/collision/shapes/ConcaveMeshShape.h +++ b/src/collision/shapes/ConcaveMeshShape.h @@ -29,14 +29,15 @@ // Libraries #include "ConcaveShape.h" #include "collision/broadphase/DynamicAABBTree.h" -#include "collision/TriangleMesh.h" -#include "collision/shapes/TriangleShape.h" #include "containers/List.h" -#include "utils/Profiler.h" namespace reactphysics3d { +// Declarations class ConcaveMeshShape; +class Profiler; +class TriangleShape; +class TriangleMesh; // class ConvexTriangleAABBOverlapCallback class ConvexTriangleAABBOverlapCallback : public DynamicAABBTreeOverlapCallback { diff --git a/src/collision/shapes/ConvexMeshShape.cpp b/src/collision/shapes/ConvexMeshShape.cpp index 01cb9dc6..1072c279 100644 --- a/src/collision/shapes/ConvexMeshShape.cpp +++ b/src/collision/shapes/ConvexMeshShape.cpp @@ -24,9 +24,10 @@ ********************************************************************************/ // Libraries -#include #include "configuration.h" #include "ConvexMeshShape.h" +#include "engine/CollisionWorld.h" +#include "collision/RaycastInfo.h" using namespace reactphysics3d; diff --git a/src/collision/shapes/ConvexMeshShape.h b/src/collision/shapes/ConvexMeshShape.h index 5ce02b19..9cc667bd 100644 --- a/src/collision/shapes/ConvexMeshShape.h +++ b/src/collision/shapes/ConvexMeshShape.h @@ -28,17 +28,16 @@ // Libraries #include "ConvexPolyhedronShape.h" -#include "engine/CollisionWorld.h" #include "mathematics/mathematics.h" - #include "collision/PolyhedronMesh.h" -#include "collision/narrowphase/GJK/GJKAlgorithm.h" /// ReactPhysics3D namespace namespace reactphysics3d { // Declaration class CollisionWorld; +class GJKAlgorithm; +class CollisionWorld; // Class ConvexMeshShape /** diff --git a/src/collision/shapes/ConvexShape.cpp b/src/collision/shapes/ConvexShape.cpp index 90c5356f..1ae9ccdf 100644 --- a/src/collision/shapes/ConvexShape.cpp +++ b/src/collision/shapes/ConvexShape.cpp @@ -25,7 +25,7 @@ // Libraries #include "ConvexShape.h" - +#include "mathematics/Vector3.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; diff --git a/src/collision/shapes/HeightFieldShape.cpp b/src/collision/shapes/HeightFieldShape.cpp index 37d73005..f3c2c328 100644 --- a/src/collision/shapes/HeightFieldShape.cpp +++ b/src/collision/shapes/HeightFieldShape.cpp @@ -25,6 +25,8 @@ // Libraries #include "HeightFieldShape.h" +#include "collision/RaycastInfo.h" +#include "utils/Profiler.h" using namespace reactphysics3d; diff --git a/src/collision/shapes/HeightFieldShape.h b/src/collision/shapes/HeightFieldShape.h index 8d4574d2..b3179794 100644 --- a/src/collision/shapes/HeightFieldShape.h +++ b/src/collision/shapes/HeightFieldShape.h @@ -28,12 +28,13 @@ // Libraries #include "ConcaveShape.h" -#include "collision/shapes/TriangleShape.h" -#include "utils/Profiler.h" +#include "collision/shapes/AABB.h" namespace reactphysics3d { class HeightFieldShape; +class Profiler; +class TriangleShape; // Class TriangleOverlapCallback /** diff --git a/src/collision/shapes/SphereShape.cpp b/src/collision/shapes/SphereShape.cpp index 3ad7afe7..0a225d11 100644 --- a/src/collision/shapes/SphereShape.cpp +++ b/src/collision/shapes/SphereShape.cpp @@ -27,6 +27,7 @@ #include "SphereShape.h" #include "collision/ProxyShape.h" #include "configuration.h" +#include "collision/RaycastInfo.h" #include using namespace reactphysics3d; @@ -40,6 +41,22 @@ SphereShape::SphereShape(decimal radius) assert(radius > decimal(0.0)); } +// Update the AABB of a body using its collision shape +/** + * @param[out] aabb The axis-aligned bounding box (AABB) of the collision shape + * computed in world-space coordinates + * @param transform Transform used to compute the AABB of the collision shape + */ +void SphereShape::computeAABB(AABB& aabb, const Transform& transform) const { + + // Get the local extents in x,y and z direction + Vector3 extents(mMargin, mMargin, mMargin); + + // Update the AABB with the new minimum and maximum coordinates + aabb.setMin(transform.getPosition() - extents); + aabb.setMax(transform.getPosition() + extents); +} + // Raycast method with feedback information bool SphereShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const { diff --git a/src/collision/shapes/SphereShape.h b/src/collision/shapes/SphereShape.h index baebf6e1..7b6f5b32 100644 --- a/src/collision/shapes/SphereShape.h +++ b/src/collision/shapes/SphereShape.h @@ -28,12 +28,14 @@ // Libraries #include "ConvexShape.h" -#include "body/CollisionBody.h" #include "mathematics/mathematics.h" // ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class CollisionBody; + // Class SphereShape /** * This class represents a sphere collision shape that is centered @@ -152,22 +154,6 @@ inline void SphereShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal ma 0.0, 0.0, diag); } -// Update the AABB of a body using its collision shape -/** - * @param[out] aabb The axis-aligned bounding box (AABB) of the collision shape - * computed in world-space coordinates - * @param transform Transform used to compute the AABB of the collision shape - */ -inline void SphereShape::computeAABB(AABB& aabb, const Transform& transform) const { - - // Get the local extents in x,y and z direction - Vector3 extents(mMargin, mMargin, mMargin); - - // Update the AABB with the new minimum and maximum coordinates - aabb.setMin(transform.getPosition() - extents); - aabb.setMax(transform.getPosition() + extents); -} - // Return true if a point is inside the collision shape inline bool SphereShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const { return (localPoint.lengthSquare() < mMargin * mMargin); diff --git a/src/collision/shapes/TriangleShape.cpp b/src/collision/shapes/TriangleShape.cpp index d3b7d753..a81ab348 100644 --- a/src/collision/shapes/TriangleShape.cpp +++ b/src/collision/shapes/TriangleShape.cpp @@ -27,6 +27,7 @@ #include "TriangleShape.h" #include "collision/ProxyShape.h" #include "mathematics/mathematics_functions.h" +#include "collision/RaycastInfo.h" #include "utils/Profiler.h" #include "configuration.h" #include @@ -208,6 +209,25 @@ Vector3 TriangleShape::computeSmoothLocalContactNormalForTriangle(const Vector3& return (u * mVerticesNormals[0] + v * mVerticesNormals[1] + w * mVerticesNormals[2]).getUnit(); } +// Update the AABB of a body using its collision shape +/** + * @param[out] aabb The axis-aligned bounding box (AABB) of the collision shape + * computed in world-space coordinates + * @param transform Transform used to compute the AABB of the collision shape + */ +void TriangleShape::computeAABB(AABB& aabb, const Transform& transform) const { + + const Vector3 worldPoint1 = transform * mPoints[0]; + const Vector3 worldPoint2 = transform * mPoints[1]; + const Vector3 worldPoint3 = transform * mPoints[2]; + + const Vector3 xAxis(worldPoint1.x, worldPoint2.x, worldPoint3.x); + const Vector3 yAxis(worldPoint1.y, worldPoint2.y, worldPoint3.y); + const Vector3 zAxis(worldPoint1.z, worldPoint2.z, worldPoint3.z); + aabb.setMin(Vector3(xAxis.getMinValue(), yAxis.getMinValue(), zAxis.getMinValue())); + aabb.setMax(Vector3(xAxis.getMaxValue(), yAxis.getMaxValue(), zAxis.getMaxValue())); +} + // Raycast method with feedback information /// This method use the line vs triangle raycasting technique described in /// Real-time Collision Detection by Christer Ericson. diff --git a/src/collision/shapes/TriangleShape.h b/src/collision/shapes/TriangleShape.h index 87ae5398..a4913572 100644 --- a/src/collision/shapes/TriangleShape.h +++ b/src/collision/shapes/TriangleShape.h @@ -221,25 +221,6 @@ inline void TriangleShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal tensor.setToZero(); } -// Update the AABB of a body using its collision shape -/** - * @param[out] aabb The axis-aligned bounding box (AABB) of the collision shape - * computed in world-space coordinates - * @param transform Transform used to compute the AABB of the collision shape - */ -inline void TriangleShape::computeAABB(AABB& aabb, const Transform& transform) const { - - const Vector3 worldPoint1 = transform * mPoints[0]; - const Vector3 worldPoint2 = transform * mPoints[1]; - const Vector3 worldPoint3 = transform * mPoints[2]; - - const Vector3 xAxis(worldPoint1.x, worldPoint2.x, worldPoint3.x); - const Vector3 yAxis(worldPoint1.y, worldPoint2.y, worldPoint3.y); - const Vector3 zAxis(worldPoint1.z, worldPoint2.z, worldPoint3.z); - aabb.setMin(Vector3(xAxis.getMinValue(), yAxis.getMinValue(), zAxis.getMinValue())); - aabb.setMax(Vector3(xAxis.getMaxValue(), yAxis.getMaxValue(), zAxis.getMaxValue())); -} - // Return true if a point is inside the collision shape inline bool TriangleShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const { return false; diff --git a/src/configuration.h b/src/configuration.h index aa8a0535..e1efaeb2 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include "decimal.h" diff --git a/src/constraint/ContactPoint.h b/src/constraint/ContactPoint.h index eec8c6a7..afe78cb7 100644 --- a/src/constraint/ContactPoint.h +++ b/src/constraint/ContactPoint.h @@ -27,14 +27,16 @@ #define REACTPHYSICS3D_CONTACT_POINT_H // Libraries -#include "body/CollisionBody.h" -#include "collision/ContactPointInfo.h" #include "configuration.h" #include "mathematics/mathematics.h" +#include "collision/ContactPointInfo.h" /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class CollisionBody; + struct NarrowPhaseInfo; // Class ContactPoint diff --git a/src/constraint/HingeJoint.cpp b/src/constraint/HingeJoint.cpp index bccd0cb1..8621df60 100644 --- a/src/constraint/HingeJoint.cpp +++ b/src/constraint/HingeJoint.cpp @@ -26,7 +26,6 @@ // Libraries #include "HingeJoint.h" #include "engine/ConstraintSolver.h" -#include using namespace reactphysics3d; diff --git a/src/constraint/SliderJoint.cpp b/src/constraint/SliderJoint.cpp index 839cc4dc..2c8f7f0f 100644 --- a/src/constraint/SliderJoint.cpp +++ b/src/constraint/SliderJoint.cpp @@ -25,6 +25,7 @@ // Libraries #include "SliderJoint.h" +#include "engine/ConstraintSolver.h" using namespace reactphysics3d; diff --git a/src/constraint/SliderJoint.h b/src/constraint/SliderJoint.h index e6ae05dd..bba97945 100644 --- a/src/constraint/SliderJoint.h +++ b/src/constraint/SliderJoint.h @@ -28,10 +28,14 @@ // Libraries #include "mathematics/mathematics.h" -#include "engine/ConstraintSolver.h" +#include "body/RigidBody.h" +#include "Joint.h" namespace reactphysics3d { +// Declarations +class ConstraintSolver; + // Structure SliderJointInfo /** * This structure is used to gather the information needed to create a slider diff --git a/src/engine/CollisionWorld.cpp b/src/engine/CollisionWorld.cpp index 04cf252f..988d2ad0 100644 --- a/src/engine/CollisionWorld.cpp +++ b/src/engine/CollisionWorld.cpp @@ -25,8 +25,8 @@ // Libraries #include "CollisionWorld.h" -#include -#include +#include "utils/Profiler.h" +#include "utils/Logger.h" // Namespaces using namespace reactphysics3d; diff --git a/src/engine/CollisionWorld.h b/src/engine/CollisionWorld.h index ad3549fe..acc9ad40 100644 --- a/src/engine/CollisionWorld.h +++ b/src/engine/CollisionWorld.h @@ -27,24 +27,24 @@ #define REACTPHYSICS3D_COLLISION_WORLD_H // Libraries -#include #include "mathematics/mathematics.h" #include "containers/List.h" -#include "utils/Profiler.h" -#include "utils/Logger.h" -#include "body/CollisionBody.h" -#include "collision/RaycastInfo.h" -#include "OverlappingPair.h" #include "collision/CollisionDetection.h" #include "constraint/Joint.h" -#include "constraint/ContactPoint.h" #include "memory/MemoryManager.h" -#include "EventListener.h" /// Namespace reactphysics3d namespace reactphysics3d { // Declarations +class Profiler; +class Logger; +class EventListener; +class Joint; +class ContactPoint; +class OverlappingPair; +class CollisionBody; +struct RaycastInfo; class CollisionCallback; class OverlapCallback; diff --git a/src/engine/ConstraintSolver.cpp b/src/engine/ConstraintSolver.cpp index f3b94396..d5db4db9 100644 --- a/src/engine/ConstraintSolver.cpp +++ b/src/engine/ConstraintSolver.cpp @@ -26,6 +26,7 @@ // Libraries #include "ConstraintSolver.h" #include "utils/Profiler.h" +#include "engine/Island.h" using namespace reactphysics3d; diff --git a/src/engine/ConstraintSolver.h b/src/engine/ConstraintSolver.h index 7c3994fc..4f406332 100644 --- a/src/engine/ConstraintSolver.h +++ b/src/engine/ConstraintSolver.h @@ -29,11 +29,14 @@ // Libraries #include "configuration.h" #include "mathematics/mathematics.h" -#include "constraint/Joint.h" -#include "Island.h" namespace reactphysics3d { +// Declarations +class Joint; +class Island; +class Profiler; + // Structure ConstraintSolverData /** * This structure contains data from the constraint solver that are used to solve diff --git a/src/engine/ContactSolver.cpp b/src/engine/ContactSolver.cpp index d9f6da25..b6b4bd2d 100644 --- a/src/engine/ContactSolver.cpp +++ b/src/engine/ContactSolver.cpp @@ -27,8 +27,10 @@ #include "ContactSolver.h" #include "DynamicsWorld.h" #include "body/RigidBody.h" +#include "constraint/ContactPoint.h" #include "utils/Profiler.h" -#include +#include "engine/Island.h" +#include "collision/ContactManifold.h" using namespace reactphysics3d; using namespace std; @@ -758,6 +760,30 @@ void ContactSolver::solve() { } } +// Compute the collision restitution factor from the restitution factor of each body +decimal ContactSolver::computeMixedRestitutionFactor(RigidBody* body1, + RigidBody* body2) const { + decimal restitution1 = body1->getMaterial().getBounciness(); + decimal restitution2 = body2->getMaterial().getBounciness(); + + // Return the largest restitution factor + return (restitution1 > restitution2) ? restitution1 : restitution2; +} + +// Compute the mixed friction coefficient from the friction coefficient of each body +decimal ContactSolver::computeMixedFrictionCoefficient(RigidBody *body1, + RigidBody *body2) const { + // Use the geometric mean to compute the mixed friction coefficient + return std::sqrt(body1->getMaterial().getFrictionCoefficient() * + body2->getMaterial().getFrictionCoefficient()); +} + +// Compute th mixed rolling resistance factor between two bodies +inline decimal ContactSolver::computeMixedRollingResistance(RigidBody* body1, + RigidBody* body2) const { + return decimal(0.5f) * (body1->getMaterial().getRollingResistance() + body2->getMaterial().getRollingResistance()); +} + // Store the computed impulses to use them to // warm start the solver at the next iteration void ContactSolver::storeImpulses() { diff --git a/src/engine/ContactSolver.h b/src/engine/ContactSolver.h index 38961709..b2b4dfac 100644 --- a/src/engine/ContactSolver.h +++ b/src/engine/ContactSolver.h @@ -27,15 +27,21 @@ #define REACTPHYSICS3D_CONTACT_SOLVER_H // Libraries -#include "constraint/ContactPoint.h" #include "configuration.h" -#include "constraint/Joint.h" -#include "collision/ContactManifold.h" -#include "Island.h" +#include "mathematics/Vector3.h" +#include "mathematics/Matrix3x3.h" /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class ContactPoint; +class Joint; +class ContactManifold; +class MemoryManager; +class Profiler; +class Island; +class RigidBody; // Class Contact Solver /** @@ -316,8 +322,8 @@ class ContactSolver { // -------------------- Methods -------------------- // /// Compute the collision restitution factor from the restitution factor of each body - decimal computeMixedRestitutionFactor(RigidBody *body1, - RigidBody *body2) const; + decimal computeMixedRestitutionFactor(RigidBody* body1, + RigidBody* body2) const; /// Compute the mixed friction coefficient from the friction coefficient of each body decimal computeMixedFrictionCoefficient(RigidBody* body1, @@ -412,30 +418,6 @@ inline void ContactSolver::setIsSplitImpulseActive(bool isActive) { mIsSplitImpulseActive = isActive; } -// Compute the collision restitution factor from the restitution factor of each body -inline decimal ContactSolver::computeMixedRestitutionFactor(RigidBody* body1, - RigidBody* body2) const { - decimal restitution1 = body1->getMaterial().getBounciness(); - decimal restitution2 = body2->getMaterial().getBounciness(); - - // Return the largest restitution factor - return (restitution1 > restitution2) ? restitution1 : restitution2; -} - -// Compute the mixed friction coefficient from the friction coefficient of each body -inline decimal ContactSolver::computeMixedFrictionCoefficient(RigidBody *body1, - RigidBody *body2) const { - // Use the geometric mean to compute the mixed friction coefficient - return std::sqrt(body1->getMaterial().getFrictionCoefficient() * - body2->getMaterial().getFrictionCoefficient()); -} - -// Compute th mixed rolling resistance factor between two bodies -inline decimal ContactSolver::computeMixedRollingResistance(RigidBody* body1, - RigidBody* body2) const { - return decimal(0.5f) * (body1->getMaterial().getRollingResistance() + body2->getMaterial().getRollingResistance()); -} - #ifdef IS_PROFILING_ACTIVE // Set the profiler diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index 8f06ca74..f1698563 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -29,7 +29,10 @@ #include "constraint/SliderJoint.h" #include "constraint/HingeJoint.h" #include "constraint/FixedJoint.h" -#include +#include "utils/Profiler.h" +#include "engine/EventListener.h" +#include "engine/Island.h" +#include "collision/ContactManifold.h" // Namespaces using namespace reactphysics3d; diff --git a/src/engine/DynamicsWorld.h b/src/engine/DynamicsWorld.h index 53ef8d9e..570fac45 100644 --- a/src/engine/DynamicsWorld.h +++ b/src/engine/DynamicsWorld.h @@ -28,16 +28,19 @@ // Libraries #include "CollisionWorld.h" -#include "collision/CollisionDetection.h" -#include "ContactSolver.h" #include "ConstraintSolver.h" -#include "body/RigidBody.h" -#include "Island.h" #include "configuration.h" +#include "utils/Logger.h" +#include "engine/ContactSolver.h" /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class CollisionDetection; +class Island; +class RigidBody; + // Class DynamicsWorld /** * This class represents a dynamics world. This class inherits from diff --git a/src/engine/Island.cpp b/src/engine/Island.cpp index 34b65540..af839fa2 100644 --- a/src/engine/Island.cpp +++ b/src/engine/Island.cpp @@ -25,6 +25,7 @@ // Libraries #include "Island.h" +#include "memory/MemoryManager.h" using namespace reactphysics3d; diff --git a/src/engine/Island.h b/src/engine/Island.h index ca1e6fdd..6eb63a88 100644 --- a/src/engine/Island.h +++ b/src/engine/Island.h @@ -27,13 +27,15 @@ #define REACTPHYSICS3D_ISLAND_H // Libraries -#include "memory/SingleFrameAllocator.h" -#include "body/RigidBody.h" #include "constraint/Joint.h" -#include "collision/ContactManifold.h" namespace reactphysics3d { +// Declarations +class RigidBody; +class SingleFrameAllocator; +class ContactManifold; + // Class Island /** * An island represent an isolated group of awake bodies that are connected with each other by diff --git a/src/engine/OverlappingPair.cpp b/src/engine/OverlappingPair.cpp index 882ed535..5803d802 100644 --- a/src/engine/OverlappingPair.cpp +++ b/src/engine/OverlappingPair.cpp @@ -29,10 +29,10 @@ #include "collision/ContactManifoldInfo.h" #include "collision/NarrowPhaseInfo.h" #include "containers/containers_common.h" +#include "collision/ContactPointInfo.h" using namespace reactphysics3d; - // Constructor OverlappingPair::OverlappingPair(ProxyShape* shape1, ProxyShape* shape2, MemoryAllocator& persistentMemoryAllocator, MemoryAllocator& temporaryMemoryAllocator, diff --git a/src/engine/OverlappingPair.h b/src/engine/OverlappingPair.h index a16ea84e..c4877072 100644 --- a/src/engine/OverlappingPair.h +++ b/src/engine/OverlappingPair.h @@ -29,7 +29,6 @@ // Libraries #include "collision/ContactManifoldSet.h" #include "collision/ProxyShape.h" -#include "collision/shapes/CollisionShape.h" #include "containers/Map.h" #include "containers/Pair.h" #include "containers/containers_common.h" @@ -37,6 +36,10 @@ /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +struct NarrowPhaseInfo; +class CollisionShape; + // Structure LastFrameCollisionInfo /** * This structure contains collision info about the last frame. diff --git a/src/engine/Timer.h b/src/engine/Timer.h index 83fc0b0a..c7f5d00c 100644 --- a/src/engine/Timer.h +++ b/src/engine/Timer.h @@ -27,8 +27,6 @@ #define REACTPHYSICS3D_TIMER_H // Libraries -#include -#include #include #include #include "configuration.h" diff --git a/src/mathematics/Matrix2x2.h b/src/mathematics/Matrix2x2.h index 0aeb3f5c..897456c3 100644 --- a/src/mathematics/Matrix2x2.h +++ b/src/mathematics/Matrix2x2.h @@ -28,7 +28,6 @@ // Libraries #include -#include #include "Vector2.h" /// ReactPhysics3D namespace diff --git a/src/mathematics/Matrix3x3.cpp b/src/mathematics/Matrix3x3.cpp index e86e63a1..a8284a15 100644 --- a/src/mathematics/Matrix3x3.cpp +++ b/src/mathematics/Matrix3x3.cpp @@ -24,7 +24,6 @@ ********************************************************************************/ // Libraries -#include #include "Matrix3x3.h" // Namespaces diff --git a/src/mathematics/Matrix3x3.h b/src/mathematics/Matrix3x3.h index fe2b053a..4c37689c 100644 --- a/src/mathematics/Matrix3x3.h +++ b/src/mathematics/Matrix3x3.h @@ -29,13 +29,11 @@ // Libraries #include -#include #include "Vector3.h" /// ReactPhysics3D namespace namespace reactphysics3d { - // Class Matrix3x3 /** * This class represents a 3x3 matrix. diff --git a/src/mathematics/Quaternion.cpp b/src/mathematics/Quaternion.cpp index 0e877612..5a585989 100644 --- a/src/mathematics/Quaternion.cpp +++ b/src/mathematics/Quaternion.cpp @@ -26,6 +26,7 @@ // Libraries #include "Quaternion.h" #include "Vector3.h" +#include "Matrix3x3.h" #include // Namespace diff --git a/src/mathematics/Quaternion.h b/src/mathematics/Quaternion.h index 70f5a729..e267aa56 100644 --- a/src/mathematics/Quaternion.h +++ b/src/mathematics/Quaternion.h @@ -27,14 +27,15 @@ #define REACTPHYSICS3D_QUATERNION_H // Libraries -#include -#include "Vector3.h" -#include "Matrix3x3.h" #include "decimal.h" +#include "Vector3.h" /// ReactPhysics3D namespace namespace reactphysics3d { +// Declarations +class Matrix3x3; + // Class Quaternion /** * This class represents a quaternion. We use the notation : diff --git a/src/mathematics/Transform.cpp b/src/mathematics/Transform.cpp index d5cf0399..5b7e56f1 100644 --- a/src/mathematics/Transform.cpp +++ b/src/mathematics/Transform.cpp @@ -25,7 +25,30 @@ // Libraries #include "Transform.h" +#include "Matrix3x3.h" // Namespaces using namespace reactphysics3d; + +// Set the transform from an OpenGL transform matrix +void Transform::setFromOpenGL(decimal* openglMatrix) { + Matrix3x3 matrix(openglMatrix[0], openglMatrix[4], openglMatrix[8], + openglMatrix[1], openglMatrix[5], openglMatrix[9], + openglMatrix[2], openglMatrix[6], openglMatrix[10]); + mOrientation = Quaternion(matrix); + mPosition.setAllValues(openglMatrix[12], openglMatrix[13], openglMatrix[14]); +} + +// Get the OpenGL matrix of the transform +void Transform::getOpenGLMatrix(decimal* openglMatrix) const { + const Matrix3x3& matrix = mOrientation.getMatrix(); + openglMatrix[0] = matrix[0][0]; openglMatrix[1] = matrix[1][0]; + openglMatrix[2] = matrix[2][0]; openglMatrix[3] = 0.0; + openglMatrix[4] = matrix[0][1]; openglMatrix[5] = matrix[1][1]; + openglMatrix[6] = matrix[2][1]; openglMatrix[7] = 0.0; + openglMatrix[8] = matrix[0][2]; openglMatrix[9] = matrix[1][2]; + openglMatrix[10] = matrix[2][2]; openglMatrix[11] = 0.0; + openglMatrix[12] = mPosition.x; openglMatrix[13] = mPosition.y; + openglMatrix[14] = mPosition.z; openglMatrix[15] = 1.0; +} diff --git a/src/mathematics/Transform.h b/src/mathematics/Transform.h index 91dd4cb1..14b0051b 100644 --- a/src/mathematics/Transform.h +++ b/src/mathematics/Transform.h @@ -27,7 +27,6 @@ #define REACTPHYSICS3D_TRANSFORM_H // Libraries -#include "Matrix3x3.h" #include "Vector3.h" #include "Quaternion.h" @@ -170,28 +169,6 @@ inline void Transform::setToIdentity() { mOrientation = Quaternion::identity(); } -// Set the transform from an OpenGL transform matrix -inline void Transform::setFromOpenGL(decimal* openglMatrix) { - Matrix3x3 matrix(openglMatrix[0], openglMatrix[4], openglMatrix[8], - openglMatrix[1], openglMatrix[5], openglMatrix[9], - openglMatrix[2], openglMatrix[6], openglMatrix[10]); - mOrientation = Quaternion(matrix); - mPosition.setAllValues(openglMatrix[12], openglMatrix[13], openglMatrix[14]); -} - -// Get the OpenGL matrix of the transform -inline void Transform::getOpenGLMatrix(decimal* openglMatrix) const { - const Matrix3x3& matrix = mOrientation.getMatrix(); - openglMatrix[0] = matrix[0][0]; openglMatrix[1] = matrix[1][0]; - openglMatrix[2] = matrix[2][0]; openglMatrix[3] = 0.0; - openglMatrix[4] = matrix[0][1]; openglMatrix[5] = matrix[1][1]; - openglMatrix[6] = matrix[2][1]; openglMatrix[7] = 0.0; - openglMatrix[8] = matrix[0][2]; openglMatrix[9] = matrix[1][2]; - openglMatrix[10] = matrix[2][2]; openglMatrix[11] = 0.0; - openglMatrix[12] = mPosition.x; openglMatrix[13] = mPosition.y; - openglMatrix[14] = mPosition.z; openglMatrix[15] = 1.0; -} - // Return the inverse of the transform inline Transform Transform::getInverse() const { const Quaternion& invQuaternion = mOrientation.getInverse(); diff --git a/src/mathematics/Vector2.h b/src/mathematics/Vector2.h index 9f66ef4b..f81c9ef5 100644 --- a/src/mathematics/Vector2.h +++ b/src/mathematics/Vector2.h @@ -27,9 +27,7 @@ #define REACTPHYSICS3D_VECTOR2_H // Libraries -#include #include -#include #include "mathematics_functions.h" #include "decimal.h" @@ -55,7 +53,7 @@ struct Vector2 { // -------------------- Methods -------------------- // - /// Constructor of the class Vector3D + /// Constructor of the struct Vector2 Vector2(); /// Constructor with arguments diff --git a/src/mathematics/Vector3.cpp b/src/mathematics/Vector3.cpp index 9a0cc082..7add07c7 100644 --- a/src/mathematics/Vector3.cpp +++ b/src/mathematics/Vector3.cpp @@ -25,7 +25,6 @@ // Libraries #include "Vector3.h" -#include // Namespaces using namespace reactphysics3d; diff --git a/src/mathematics/Vector3.h b/src/mathematics/Vector3.h index 27f5bcf6..6e207756 100644 --- a/src/mathematics/Vector3.h +++ b/src/mathematics/Vector3.h @@ -27,9 +27,7 @@ #define REACTPHYSICS3D_VECTOR3_H // Libraries -#include #include -#include #include "mathematics_functions.h" #include "decimal.h" @@ -37,7 +35,7 @@ /// ReactPhysics3D namespace namespace reactphysics3d { -// Class Vector3 +// Struct Vector3 /** * This class represents a 3D vector. */ @@ -58,7 +56,7 @@ struct Vector3 { // -------------------- Methods -------------------- // - /// Constructor of the class Vector3D + /// Constructor of the struct Vector3 Vector3(); /// Constructor with arguments @@ -172,7 +170,7 @@ struct Vector3 { friend Vector3 operator/(const Vector3& vector1, const Vector3& vector2); }; -// Constructor of the class Vector3D +// Constructor of the struct Vector3 inline Vector3::Vector3() : x(0.0), y(0.0), z(0.0) { } diff --git a/src/memory/DefaultAllocator.h b/src/memory/DefaultAllocator.h index ac4ddd04..82cd94d1 100644 --- a/src/memory/DefaultAllocator.h +++ b/src/memory/DefaultAllocator.h @@ -42,7 +42,7 @@ class DefaultAllocator : public MemoryAllocator { public: /// Destructor - virtual ~DefaultAllocator() = default; + virtual ~DefaultAllocator() override = default; /// Assignment operator DefaultAllocator& operator=(DefaultAllocator& allocator) = default; diff --git a/src/memory/MemoryManager.h b/src/memory/MemoryManager.h index 2787c067..f2eee140 100644 --- a/src/memory/MemoryManager.h +++ b/src/memory/MemoryManager.h @@ -27,7 +27,6 @@ #define REACTPHYSICS3D_MEMORY_MANAGER_H // Libraries -#include "memory/MemoryAllocator.h" #include "memory/DefaultAllocator.h" #include "memory/PoolAllocator.h" #include "memory/SingleFrameAllocator.h" @@ -35,6 +34,9 @@ /// Namespace ReactPhysics3D namespace reactphysics3d { +// Declarations +class MemoryAllocator; + // Class MemoryManager /** * The memory manager is used to store the different memory allocators that are used diff --git a/test/tests/collision/TestCollisionWorld.h b/test/tests/collision/TestCollisionWorld.h index b2e7e57f..7dcd1b64 100644 --- a/test/tests/collision/TestCollisionWorld.h +++ b/test/tests/collision/TestCollisionWorld.h @@ -29,6 +29,8 @@ // Libraries #include "reactphysics3d.h" #include "Test.h" +#include "constraint/ContactPoint.h" +#include "collision/ContactManifold.h" #include /// Reactphysics3D namespace diff --git a/test/tests/collision/TestDynamicAABBTree.h b/test/tests/collision/TestDynamicAABBTree.h index a117df57..ade79afb 100755 --- a/test/tests/collision/TestDynamicAABBTree.h +++ b/test/tests/collision/TestDynamicAABBTree.h @@ -30,6 +30,7 @@ #include "Test.h" #include "collision/broadphase/DynamicAABBTree.h" #include "memory/MemoryManager.h" +#include "utils/Profiler.h" /// Reactphysics3D namespace namespace reactphysics3d { diff --git a/test/tests/collision/TestPointInside.h b/test/tests/collision/TestPointInside.h index 6a7fe5b8..2046cf36 100644 --- a/test/tests/collision/TestPointInside.h +++ b/test/tests/collision/TestPointInside.h @@ -32,6 +32,8 @@ #include "collision/shapes/SphereShape.h" #include "collision/shapes/CapsuleShape.h" #include "collision/shapes/ConvexMeshShape.h" +#include "engine/CollisionWorld.h" +#include "collision/PolygonVertexArray.h" /// Reactphysics3D namespace namespace reactphysics3d { diff --git a/test/tests/collision/TestRaycast.h b/test/tests/collision/TestRaycast.h index 916997bf..75f82220 100644 --- a/test/tests/collision/TestRaycast.h +++ b/test/tests/collision/TestRaycast.h @@ -37,6 +37,9 @@ #include "collision/shapes/TriangleShape.h" #include "collision/shapes/ConcaveMeshShape.h" #include "collision/shapes/HeightFieldShape.h" +#include "collision/TriangleMesh.h" +#include "collision/TriangleVertexArray.h" +#include "collision/RaycastInfo.h" /// Reactphysics3D namespace namespace reactphysics3d { diff --git a/test/tests/mathematics/TestTransform.h b/test/tests/mathematics/TestTransform.h index 815e3d54..67fcfc94 100644 --- a/test/tests/mathematics/TestTransform.h +++ b/test/tests/mathematics/TestTransform.h @@ -29,6 +29,7 @@ // Libraries #include "Test.h" #include "mathematics/Transform.h" +#include "mathematics/Matrix3x3.h" /// Reactphysics3D namespace namespace reactphysics3d { diff --git a/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp b/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp index 3b4c7fc5..ea57959c 100755 --- a/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp +++ b/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp @@ -25,6 +25,8 @@ // Libraries #include "CollisionDetectionScene.h" +#include "constraint/ContactPoint.h" +#include "collision/ContactManifold.h" // Namespaces using namespace openglframework; @@ -310,3 +312,39 @@ bool CollisionDetectionScene::keyboardEvent(int key, int scancode, int action, i return false; } + +// This method will be called for each reported contact point +void ContactManager::notifyContact(const CollisionCallbackInfo& collisionCallbackInfo) { + + // For each contact manifold + rp3d::ContactManifoldListElement* manifoldElement = collisionCallbackInfo.contactManifoldElements; + while (manifoldElement != nullptr) { + + // Get the contact manifold + rp3d::ContactManifold* contactManifold = manifoldElement->getContactManifold(); + + // For each contact point + rp3d::ContactPoint* contactPoint = contactManifold->getContactPoints(); + while (contactPoint != nullptr) { + + // Contact normal + rp3d::Vector3 normal = contactPoint->getNormal(); + openglframework::Vector3 contactNormal(normal.x, normal.y, normal.z); + + rp3d::Vector3 point1 = contactPoint->getLocalPointOnShape1(); + point1 = collisionCallbackInfo.proxyShape1->getLocalToWorldTransform() * point1; + + openglframework::Vector3 position1(point1.x, point1.y, point1.z); + mContactPoints.push_back(ContactPoint(position1, contactNormal, openglframework::Color::red())); + + rp3d::Vector3 point2 = contactPoint->getLocalPointOnShape2(); + point2 = collisionCallbackInfo.proxyShape2->getLocalToWorldTransform() * point2; + openglframework::Vector3 position2(point2.x, point2.y, point2.z); + mContactPoints.push_back(ContactPoint(position2, contactNormal, openglframework::Color::blue())); + + contactPoint = contactPoint->getNext(); + } + + manifoldElement = manifoldElement->getNext(); + } +} diff --git a/testbed/scenes/collisiondetection/CollisionDetectionScene.h b/testbed/scenes/collisiondetection/CollisionDetectionScene.h index e60893df..2e134567 100644 --- a/testbed/scenes/collisiondetection/CollisionDetectionScene.h +++ b/testbed/scenes/collisiondetection/CollisionDetectionScene.h @@ -77,40 +77,7 @@ class ContactManager : public rp3d::CollisionCallback { } /// This method will be called for each reported contact point - virtual void notifyContact(const CollisionCallbackInfo& collisionCallbackInfo) override { - - // For each contact manifold - rp3d::ContactManifoldListElement* manifoldElement = collisionCallbackInfo.contactManifoldElements; - while (manifoldElement != nullptr) { - - // Get the contact manifold - rp3d::ContactManifold* contactManifold = manifoldElement->getContactManifold(); - - // For each contact point - rp3d::ContactPoint* contactPoint = contactManifold->getContactPoints(); - while (contactPoint != nullptr) { - - // Contact normal - rp3d::Vector3 normal = contactPoint->getNormal(); - openglframework::Vector3 contactNormal(normal.x, normal.y, normal.z); - - rp3d::Vector3 point1 = contactPoint->getLocalPointOnShape1(); - point1 = collisionCallbackInfo.proxyShape1->getLocalToWorldTransform() * point1; - - openglframework::Vector3 position1(point1.x, point1.y, point1.z); - mContactPoints.push_back(ContactPoint(position1, contactNormal, openglframework::Color::red())); - - rp3d::Vector3 point2 = contactPoint->getLocalPointOnShape2(); - point2 = collisionCallbackInfo.proxyShape2->getLocalToWorldTransform() * point2; - openglframework::Vector3 position2(point2.x, point2.y, point2.z); - mContactPoints.push_back(ContactPoint(position2, contactNormal, openglframework::Color::blue())); - - contactPoint = contactPoint->getNext(); - } - - manifoldElement = manifoldElement->getNext(); - } - } + virtual void notifyContact(const CollisionCallbackInfo& collisionCallbackInfo) override; void resetPoints() { diff --git a/testbed/src/SceneDemo.cpp b/testbed/src/SceneDemo.cpp index cb9d8eb0..97d0779e 100644 --- a/testbed/src/SceneDemo.cpp +++ b/testbed/src/SceneDemo.cpp @@ -27,6 +27,8 @@ #include "SceneDemo.h" #include #include "AABB.h" +#include "constraint/ContactPoint.h" +#include "collision/ContactManifold.h" using namespace openglframework;