From c5873dbc6bd176b527beb29951823b72067ec013 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sat, 1 Feb 2020 13:41:30 +0100 Subject: [PATCH] The Material is now part of the Collider instead of the RigidBody, fixes compilation errors with Logger and Profiler. --- CHANGELOG.md | 4 + src/body/RigidBody.cpp | 15 +--- src/body/RigidBody.h | 18 ---- src/collision/Collider.cpp | 6 +- src/collision/Collider.h | 46 ++++++++-- src/engine/Material.h | 2 +- src/engine/PhysicsCommon.cpp | 88 ++++++++++++++++++- src/engine/PhysicsCommon.h | 25 +++++- src/engine/PhysicsWorld.cpp | 40 +-------- src/engine/PhysicsWorld.h | 6 -- src/memory/HeapAllocator.cpp | 7 +- src/systems/ContactSolverSystem.cpp | 33 ++++--- src/systems/ContactSolverSystem.h | 16 ++-- src/utils/Logger.cpp | 18 ++-- src/utils/Logger.h | 30 +++++-- src/utils/Profiler.h | 15 ++-- test/tests/collision/TestDynamicAABBTree.h | 28 ------ testbed/common/Box.h | 10 ++- testbed/common/Capsule.h | 13 ++- testbed/common/ConcaveMesh.h | 14 ++- testbed/common/ConvexMesh.h | 13 ++- testbed/common/Dumbbell.h | 29 +++++- testbed/common/HeightField.h | 13 ++- testbed/common/Sphere.h | 11 ++- .../collisionshapes/CollisionShapesScene.cpp | 22 +++-- .../scenes/concavemesh/ConcaveMeshScene.cpp | 22 +++-- testbed/scenes/cubes/CubesScene.cpp | 2 +- testbed/scenes/cubestack/CubeStackScene.cpp | 2 +- .../scenes/heightfield/HeightFieldScene.cpp | 22 +++-- testbed/scenes/joints/JointsScene.cpp | 14 +-- testbed/scenes/pile/PileScene.cpp | 22 +++-- 31 files changed, 378 insertions(+), 228 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9570734e..9c1a1cbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ - Now, the collision shapes need be be created with the PhysicsWorld::createXXXShape() methods instead of using the constructor of the shape as before. For instance, you need to use the PhysicsWorld::createBoxShape() method to create a BoxShape. - DynamicsWorld and CollisionWorld classes have been merged into a single class called PhysicsWorld. - ProxyShape class has been renamed into Collider. + - The Material is now part of the Collider instead of the RigidBody. Therefore, it is now possible to have a RigidBody with multiple + colliders and a different material per Collider. + - The Logger has to be instanciated using the PhysicsCommon::createLogger() method instead of using its constructor. + - The Profiler has to be instanciated using the PhysicsCommon::createProfiler() method instead of using its constructor. - There is now a single MemoryManager (with memory allocators) per PhysicsWorld. The memory allocators are no longer shared between worlds. - An instance of the BoxShape class cannot be instanciated directly anymore. You need to use the PhysicsCommon::createBoxShape() method. - An instance of the SphereShape class cannot be instanciated directly anymore. You need to use the PhysicsCommon::createSphereShape() method. diff --git a/src/body/RigidBody.cpp b/src/body/RigidBody.cpp index 8e29c888..165ebe10 100644 --- a/src/body/RigidBody.cpp +++ b/src/body/RigidBody.cpp @@ -39,9 +39,7 @@ using namespace reactphysics3d; * @param id The ID of the body */ RigidBody::RigidBody(PhysicsWorld& world, Entity entity) - : CollisionBody(world, entity), - mMaterial(world.mConfig.defaultFrictionCoefficient, world.mConfig.defaultRollingRestistance, world.mConfig.defaultBounciness), - mIsCenterOfMassSetByUser(false), mIsInertiaTensorSetByUser(false) { + : CollisionBody(world, entity), mIsCenterOfMassSetByUser(false), mIsInertiaTensorSetByUser(false) { } @@ -431,17 +429,6 @@ void RigidBody::setAngularDamping(decimal angularDamping) { "Body " + std::to_string(mEntity.id) + ": Set angularDamping=" + std::to_string(angularDamping)); } -// 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(mEntity.id) + ": 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 58995bcf..5f1b780a 100644 --- a/src/body/RigidBody.h +++ b/src/body/RigidBody.h @@ -29,7 +29,6 @@ // Libraries #include #include "CollisionBody.h" -#include "engine/Material.h" #include "mathematics/mathematics.h" /// Namespace reactphysics3d @@ -58,9 +57,6 @@ class RigidBody : public CollisionBody { /// by the user with respect to the center of mass of the body Matrix3x3 mUserInertiaTensorLocalInverse; - /// Material properties of the rigid body - Material mMaterial; - /// True if the center of mass is set by the user bool mIsCenterOfMassSetByUser; @@ -142,12 +138,6 @@ class RigidBody : public CollisionBody { /// Set the variable to know if the gravity is applied to this rigid body void enableGravity(bool isEnabled); - /// Return a reference to the material properties of the rigid body - Material& getMaterial(); - - /// Set a new material for this rigid body - void setMaterial(const Material& material); - /// Return the linear velocity damping factor decimal getLinearDamping() const; @@ -216,14 +206,6 @@ class RigidBody : public CollisionBody { friend class Joint; }; -// Return a reference to the material properties of the rigid body -/** - * @return A reference to the material of the body - */ -inline Material& RigidBody::getMaterial() { - return mMaterial; -} - } #endif diff --git a/src/collision/Collider.cpp b/src/collision/Collider.cpp index 77198364..8f2afaf7 100644 --- a/src/collision/Collider.cpp +++ b/src/collision/Collider.cpp @@ -41,6 +41,8 @@ using namespace reactphysics3d; */ Collider::Collider(Entity entity, CollisionBody* body, MemoryManager& memoryManager) :mMemoryManager(memoryManager), mEntity(entity), mBody(body), + mMaterial(body->mWorld.mConfig.defaultFrictionCoefficient, body->mWorld.mConfig.defaultRollingRestistance, + body->mWorld.mConfig.defaultBounciness), mUserData(nullptr) { } @@ -106,7 +108,7 @@ void Collider::setCollideWithMaskBits(unsigned short collideWithMaskBits) { int broadPhaseId = mBody->mWorld.mCollidersComponents.getBroadPhaseId(mEntity); RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Collider, - "Collider" " + std::to_string(broadPhaseId) + ": Set collideWithMaskBits=" + + "Collider" + std::to_string(broadPhaseId) + ": Set collideWithMaskBits=" + std::to_string(collideWithMaskBits)); } @@ -127,7 +129,7 @@ void Collider::setLocalToBodyTransform(const Transform& transform) { mBody->mWorld.mCollisionDetection.updateCollider(mEntity, 0); RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Collider, - "Collider " + std::to_string(broadPhaseId) + ": Set localToBodyTransform=" + + "Collider " + std::to_string(getBroadPhaseId()) + ": Set localToBodyTransform=" + transform.to_string()); } diff --git a/src/collision/Collider.h b/src/collision/Collider.h index eb4d3cba..7d2b46f0 100644 --- a/src/collision/Collider.h +++ b/src/collision/Collider.h @@ -29,6 +29,8 @@ // Libraries #include "body/CollisionBody.h" #include "collision/shapes/CollisionShape.h" +#include "engine/Material.h" +#include "utils/Logger.h" namespace reactphysics3d { @@ -37,13 +39,10 @@ class MemoryManager; // Class Collider /** - * The CollisionShape instances are supposed to be unique for memory optimization. For instance, - * consider two rigid bodies with the same sphere collision shape. In this situation, we will have - * a unique instance of SphereShape but we need to differentiate between the two instances during - * the collision detection. They do not have the same position in the world and they do not - * belong to the same rigid body. The Collider class is used for that purpose by attaching a - * rigid body with one of its collision shape. A body can have multiple colliders (one for - * each collision shape attached to the body). + * A collider has a collision shape (box, sphere, capsule, ...) and is attached to a CollisionBody or + * RigidBody. A body can have multiple colliders. The collider also have a mass value and a Material + * with many physics parameters like friction or bounciness. When you create a body, you need to attach + * at least one collider to it if you want that body to be able to collide in the physics world. */ class Collider { @@ -60,6 +59,9 @@ class Collider { /// Pointer to the parent body CollisionBody* mBody; + /// Material properties of the rigid body + Material mMaterial; + /// Pointer to user data void* mUserData; @@ -151,6 +153,12 @@ class Collider { /// Return the broad-phase id int getBroadPhaseId() const; + /// Return a reference to the material properties of the collider + Material& getMaterial(); + + /// Set a new material for this collider + void setMaterial(const Material& material); + #ifdef IS_PROFILING_ACTIVE /// Set the profiler @@ -221,6 +229,30 @@ inline bool Collider::testAABBOverlap(const AABB& worldAABB) const { return worldAABB.testCollision(getWorldAABB()); } +// Return a reference to the material properties of the collider +/** + * @return A reference to the material of the body + */ +inline Material& Collider::getMaterial() { + return mMaterial; +} + +// Set a new material for this rigid body +/** + * @param material The material you want to set to the body + */ +inline void Collider::setMaterial(const Material& material) { + + mMaterial = material; + +#ifdef IS_LOGGING_ACTIVE + + RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Collider, + "Collider " + std::to_string(mEntity.id) + ": Set Material" + mMaterial.to_string()); +#endif + +} + #ifdef IS_LOGGING_ACTIVE // Set the logger diff --git a/src/engine/Material.h b/src/engine/Material.h index c122b00b..a989f4bc 100644 --- a/src/engine/Material.h +++ b/src/engine/Material.h @@ -94,7 +94,7 @@ class Material { // ---------- Friendship ---------- // - friend class RigidBody; + friend class Collider; }; // Return the bounciness diff --git a/src/engine/PhysicsCommon.cpp b/src/engine/PhysicsCommon.cpp index 1944e6cc..3f4a256e 100644 --- a/src/engine/PhysicsCommon.cpp +++ b/src/engine/PhysicsCommon.cpp @@ -35,7 +35,8 @@ PhysicsCommon::PhysicsCommon(MemoryAllocator* baseMemoryAllocator) mBoxShapes(mMemoryManager.getHeapAllocator()), mCapsuleShapes(mMemoryManager.getHeapAllocator()), mConvexMeshShapes(mMemoryManager.getHeapAllocator()), mConcaveMeshShapes(mMemoryManager.getHeapAllocator()), mHeightFieldShapes(mMemoryManager.getHeapAllocator()), mPolyhedronMeshes(mMemoryManager.getHeapAllocator()), - mTriangleMeshes(mMemoryManager.getHeapAllocator()) { + mTriangleMeshes(mMemoryManager.getHeapAllocator()), mLoggers(mMemoryManager.getHeapAllocator()), + mProfilers(mMemoryManager.getHeapAllocator()) { } @@ -93,11 +94,49 @@ void PhysicsCommon::release() { for (auto it = mTriangleMeshes.begin(); it != mTriangleMeshes.end(); ++it) { destroyTriangleMesh(*it); } + + // Destroy the loggers + for (auto it = mLoggers.begin(); it != mLoggers.end(); ++it) { + destroyLogger(*it); + } + + // Destroy the profilers + for (auto it = mProfilers.begin(); it != mProfilers.end(); ++it) { + destroyProfiler(*it); + } } // Create and return an instance of PhysicsWorld PhysicsWorld* PhysicsCommon::createPhysicsWorld(const PhysicsWorld::WorldSettings& worldSettings, Logger* logger, Profiler* profiler) { +#ifdef IS_PROFILING_ACTIVE + + // If the user has not provided its own profiler, we create one + if (profiler == nullptr) { + + profiler = createProfiler(); + + // Add a destination file for the profiling data + profiler->addFileDestination("rp3d_profiling_" + worldSettings.worldName + ".txt", Profiler::Format::Text); + } + +#endif + +#ifdef IS_LOGGING_ACTIVE + + // If the user has not provided its own logger, we create one + if (logger == nullptr) { + + logger = createLogger(); + + // Add a log destination file + uint logLevel = static_cast(Logger::Level::Information) | static_cast(Logger::Level::Warning) | + static_cast(Logger::Level::Error); + logger->addFileDestination("rp3d_log_" + worldSettings.worldName + ".html", logLevel, Logger::Format::HTML); + } + +#endif + PhysicsWorld* world = new(mMemoryManager.allocate(MemoryManager::AllocationType::Heap, sizeof(PhysicsWorld))) PhysicsWorld(mMemoryManager, worldSettings, logger, profiler); mPhysicsWorlds.add(world); @@ -106,7 +145,7 @@ PhysicsWorld* PhysicsCommon::createPhysicsWorld(const PhysicsWorld::WorldSetting } // Destroy an instance of PhysicsWorld -PhysicsWorld* PhysicsCommon::destroyPhysicsWorld(PhysicsWorld* world) { +void PhysicsCommon::destroyPhysicsWorld(PhysicsWorld* world) { // Call the destructor of the world world->~PhysicsWorld(); @@ -294,3 +333,48 @@ void PhysicsCommon::destroyTriangleMesh(TriangleMesh* triangleMesh) { mTriangleMeshes.remove(triangleMesh); } + +// Create and return a new logger +Logger* PhysicsCommon::createLogger() { + + Logger* logger = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(Logger))) Logger(mMemoryManager.getHeapAllocator()); + + mLoggers.add(logger); + + return logger; +} + +// Destroy a logger +void PhysicsCommon::destroyLogger(Logger* logger) { + + // Call the destructor of the logger + logger->~Logger(); + + // Release allocated memory + mMemoryManager.release(MemoryManager::AllocationType::Pool, logger, sizeof(Logger)); + + mLoggers.remove(logger); +} + +// Create and return a new profiler +/// Note that you need to use a different profiler for each PhysicsWorld. +Profiler* PhysicsCommon::createProfiler() { + + Profiler* profiler = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(Profiler))) Profiler(); + + mProfilers.add(profiler); + + return profiler; +} + +// Destroy a profiler +void PhysicsCommon::destroyProfiler(Profiler* profiler) { + + // Call the destructor of the profiler + profiler->~Profiler(); + + // Release allocated memory + mMemoryManager.release(MemoryManager::AllocationType::Pool, profiler, sizeof(Profiler)); + + mProfilers.remove(profiler); +} diff --git a/src/engine/PhysicsCommon.h b/src/engine/PhysicsCommon.h index d454aa01..8d1dc977 100644 --- a/src/engine/PhysicsCommon.h +++ b/src/engine/PhysicsCommon.h @@ -82,6 +82,12 @@ class PhysicsCommon { /// Set of triangle meshes Set mTriangleMeshes; + /// Set of loggers + Set mLoggers; + + /// Set of loggers + Set mProfilers; + // -------------------- Methods -------------------- // /// Destroy and release everything that has been allocated @@ -100,12 +106,15 @@ class PhysicsCommon { /// Destructor ~PhysicsCommon(); + // TODO : Add better code documentation for all methods in this class (document + // the method parameters with the "@param" keyword for Doxygen + /// Create and return an instance of PhysicsWorld PhysicsWorld* createPhysicsWorld(const PhysicsWorld::WorldSettings& worldSettings = PhysicsWorld::WorldSettings(), - Logger* logger = nullptr, Profiler* profiler = nullptr); + Logger* logger = nullptr, Profiler* profiler = nullptr); /// Destroy an instance of PhysicsWorld - PhysicsWorld* destroyPhysicsWorld(PhysicsWorld* world); + void destroyPhysicsWorld(PhysicsWorld* world); /// Create and return a sphere collision shape SphereShape* createSphereShape(const decimal radius); @@ -157,6 +166,18 @@ class PhysicsCommon { /// Destroy a triangle mesh void destroyTriangleMesh(TriangleMesh* triangleMesh); + + /// Create and return a new logger + Logger* createLogger(); + + /// Destroy a logger + void destroyLogger(Logger* logger); + + /// Create and return a new profiler + Profiler* createProfiler(); + + /// Destroy a profiler + void destroyProfiler(Profiler* profiler); }; } diff --git a/src/engine/PhysicsWorld.cpp b/src/engine/PhysicsWorld.cpp index e064fe1f..bf41d5fb 100644 --- a/src/engine/PhysicsWorld.cpp +++ b/src/engine/PhysicsWorld.cpp @@ -59,8 +59,7 @@ PhysicsWorld::PhysicsWorld(MemoryManager& memoryManager, const WorldSettings& wo mSliderJointsComponents(mMemoryManager.getHeapAllocator()), mCollisionDetection(this, mCollidersComponents, mTransformComponents, mCollisionBodyComponents, mRigidBodyComponents, mMemoryManager), mBodies(mMemoryManager.getHeapAllocator()), mEventListener(nullptr), - mName(worldSettings.worldName), mIsProfilerCreatedByUser(profiler != nullptr), - mIsLoggerCreatedByUser(logger != nullptr), mIslands(mMemoryManager.getSingleFrameAllocator()), + mName(worldSettings.worldName), mIslands(mMemoryManager.getSingleFrameAllocator()), mContactSolverSystem(mMemoryManager, *this, mIslands, mCollisionBodyComponents, mRigidBodyComponents, mCollidersComponents, mConfig.restitutionVelocityThreshold), mConstraintSolverSystem(*this, mIslands, mRigidBodyComponents, mTransformComponents, mJointsComponents, @@ -88,18 +87,9 @@ PhysicsWorld::PhysicsWorld(MemoryManager& memoryManager, const WorldSettings& wo #ifdef IS_PROFILING_ACTIVE + assert(profiler != nullptr); mProfiler = profiler; - // If the user has not provided its own profiler, we create one - if (mProfiler == nullptr) { - - mProfiler = new Profiler(); - - // Add a destination file for the profiling data - mProfiler->addFileDestination("rp3d_profiling_" + mName + ".txt", Profiler::Format::Text); - } - - // Set the profiler mConstraintSolverSystem.setProfiler(mProfiler); mContactSolverSystem.setProfiler(mProfiler); @@ -110,19 +100,9 @@ PhysicsWorld::PhysicsWorld(MemoryManager& memoryManager, const WorldSettings& wo #ifdef IS_LOGGING_ACTIVE + assert(logger != nullptr); mLogger = logger; - // If the user has not provided its own logger, we create one - if (mLogger == nullptr) { - - mLogger = new Logger(); - - // Add a log destination file - uint logLevel = static_cast(Logger::Level::Information) | static_cast(Logger::Level::Warning) | - static_cast(Logger::Level::Error); - mLogger->addFileDestination("rp3d_log_" + mName + ".html", logLevel, Logger::Format::HTML); - } - #endif mNbWorlds++; @@ -150,23 +130,9 @@ PhysicsWorld::~PhysicsWorld() { #ifdef IS_PROFILING_ACTIVE - /// Delete the profiler - if (!mIsProfilerCreatedByUser) { - delete mProfiler; - } - // Print the profiling report into the destinations mProfiler->printReport(); -#endif - -#ifdef IS_LOGGING_ACTIVE - - /// Delete the logger - if (!mIsLoggerCreatedByUser) { - delete mLogger; - } - #endif assert(mBodies.size() == 0); diff --git a/src/engine/PhysicsWorld.h b/src/engine/PhysicsWorld.h index 5d02c876..c70de69d 100644 --- a/src/engine/PhysicsWorld.h +++ b/src/engine/PhysicsWorld.h @@ -234,12 +234,6 @@ class PhysicsWorld { Logger* mLogger; #endif - /// True if the profiler has been created by the user - bool mIsProfilerCreatedByUser; - - /// True if the logger has been created by the user - bool mIsLoggerCreatedByUser; - /// Total number of worlds static uint mNbWorlds; diff --git a/src/memory/HeapAllocator.cpp b/src/memory/HeapAllocator.cpp index d2e2315c..c1537a98 100644 --- a/src/memory/HeapAllocator.cpp +++ b/src/memory/HeapAllocator.cpp @@ -36,8 +36,11 @@ size_t HeapAllocator::INIT_ALLOCATED_SIZE = 5 * 1048576; // 5 Mb // Constructor HeapAllocator::HeapAllocator(MemoryAllocator& baseAllocator, size_t initAllocatedMemory) - : mBaseAllocator(baseAllocator), mAllocatedMemory(0), mMemoryUnits(nullptr), mCachedFreeUnit(nullptr), - mNbTimesAllocateMethodCalled(0) { + : mBaseAllocator(baseAllocator), mAllocatedMemory(0), mMemoryUnits(nullptr), mCachedFreeUnit(nullptr) { + +#ifndef NDEBUG + mNbTimesAllocateMethodCalled = 0; +#endif reserve(initAllocatedMemory == 0 ? INIT_ALLOCATED_SIZE : initAllocatedMemory); } diff --git a/src/systems/ContactSolverSystem.cpp b/src/systems/ContactSolverSystem.cpp index 4c008c3b..16f02a89 100644 --- a/src/systems/ContactSolverSystem.cpp +++ b/src/systems/ContactSolverSystem.cpp @@ -30,6 +30,7 @@ #include "constraint/ContactPoint.h" #include "utils/Profiler.h" #include "engine/Island.h" +#include "collision/Collider.h" #include "components/CollisionBodyComponents.h" #include "components/ColliderComponents.h" #include "collision/ContactManifold.h" @@ -134,6 +135,9 @@ void ContactSolverSystem::initializeForIsland(uint islandIndex) { const uint rigidBodyIndex1 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity1); const uint rigidBodyIndex2 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity2); + Collider* collider1 = mColliderComponents.getCollider(externalManifold.colliderEntity1); + Collider* collider2 = mColliderComponents.getCollider(externalManifold.colliderEntity2); + // Get the position of the two bodies const Vector3& x1 = mRigidBodyComponents.mCentersOfMassWorld[rigidBodyIndex1]; const Vector3& x2 = mRigidBodyComponents.mCentersOfMassWorld[rigidBodyIndex2]; @@ -147,8 +151,8 @@ void ContactSolverSystem::initializeForIsland(uint islandIndex) { mContactConstraints[mNbContactManifolds].massInverseBody1 = mRigidBodyComponents.mInverseMasses[rigidBodyIndex1]; mContactConstraints[mNbContactManifolds].massInverseBody2 = mRigidBodyComponents.mInverseMasses[rigidBodyIndex2]; mContactConstraints[mNbContactManifolds].nbContacts = externalManifold.nbContactPoints; - mContactConstraints[mNbContactManifolds].frictionCoefficient = computeMixedFrictionCoefficient(body1, body2); - mContactConstraints[mNbContactManifolds].rollingResistanceFactor = computeMixedRollingResistance(body1, body2); + mContactConstraints[mNbContactManifolds].frictionCoefficient = computeMixedFrictionCoefficient(collider1, collider2); + mContactConstraints[mNbContactManifolds].rollingResistanceFactor = computeMixedRollingResistance(collider1, collider2); mContactConstraints[mNbContactManifolds].externalContactManifold = &externalManifold; mContactConstraints[mNbContactManifolds].normal.setToZero(); mContactConstraints[mNbContactManifolds].frictionPointBody1.setToZero(); @@ -236,7 +240,7 @@ void ContactSolverSystem::initializeForIsland(uint islandIndex) { decimal deltaVDotN = deltaV.x * mContactPoints[mNbContactPoints].normal.x + deltaV.y * mContactPoints[mNbContactPoints].normal.y + deltaV.z * mContactPoints[mNbContactPoints].normal.z; - const decimal restitutionFactor = computeMixedRestitutionFactor(body1, body2); + const decimal restitutionFactor = computeMixedRestitutionFactor(collider1, collider2); if (deltaVDotN < -mRestitutionVelocityThreshold) { mContactPoints[mNbContactPoints].restitutionBias = restitutionFactor * deltaVDotN; } @@ -769,25 +773,26 @@ void ContactSolverSystem::solve() { } } -// Compute the collision restitution factor from the restitution factor of each body -decimal ContactSolverSystem::computeMixedRestitutionFactor(RigidBody* body1, RigidBody* body2) const { - decimal restitution1 = body1->getMaterial().getBounciness(); - decimal restitution2 = body2->getMaterial().getBounciness(); +// Compute the collision restitution factor from the restitution factor of each collider +decimal ContactSolverSystem::computeMixedRestitutionFactor(Collider* collider1, Collider* collider2) const { + decimal restitution1 = collider1->getMaterial().getBounciness(); + decimal restitution2 = collider2->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 ContactSolverSystem::computeMixedFrictionCoefficient(RigidBody* body1, RigidBody* body2) const { +// Compute the mixed friction coefficient from the friction coefficient of each collider +decimal ContactSolverSystem::computeMixedFrictionCoefficient(Collider* collider1, Collider* collider2) const { + // Use the geometric mean to compute the mixed friction coefficient - return std::sqrt(body1->getMaterial().getFrictionCoefficient() * - body2->getMaterial().getFrictionCoefficient()); + return std::sqrt(collider1->getMaterial().getFrictionCoefficient() * + collider2->getMaterial().getFrictionCoefficient()); } -// Compute th mixed rolling resistance factor between two bodies -inline decimal ContactSolverSystem::computeMixedRollingResistance(RigidBody* body1, RigidBody* body2) const { - return decimal(0.5f) * (body1->getMaterial().getRollingResistance() + body2->getMaterial().getRollingResistance()); +// Compute th mixed rolling resistance factor between two colliders +inline decimal ContactSolverSystem::computeMixedRollingResistance(Collider* collider1, Collider* collider2) const { + return decimal(0.5f) * (collider1->getMaterial().getRollingResistance() + collider2->getMaterial().getRollingResistance()); } // Store the computed impulses to use them to diff --git a/src/systems/ContactSolverSystem.h b/src/systems/ContactSolverSystem.h index 996951fb..a056a4b2 100644 --- a/src/systems/ContactSolverSystem.h +++ b/src/systems/ContactSolverSystem.h @@ -43,6 +43,7 @@ class Profiler; class Island; struct Islands; class RigidBody; +class Collider; class PhysicsWorld; class CollisionBodyComponents; class DynamicsComponents; @@ -338,16 +339,15 @@ class ContactSolverSystem { // -------------------- Methods -------------------- // - /// Compute the collision restitution factor from the restitution factor of each body - decimal computeMixedRestitutionFactor(RigidBody* body1, - RigidBody* body2) const; + /// Compute the collision restitution factor from the restitution factor of each collider + decimal computeMixedRestitutionFactor(Collider* collider1, + Collider* collider2) const; - /// Compute the mixed friction coefficient from the friction coefficient of each body - decimal computeMixedFrictionCoefficient(RigidBody* body1, - RigidBody* body2) const; + /// Compute the mixed friction coefficient from the friction coefficient of each collider + decimal computeMixedFrictionCoefficient(Collider* collider1, Collider* collider2) const; - /// Compute th mixed rolling resistance factor between two bodies - decimal computeMixedRollingResistance(RigidBody* body1, RigidBody* body2) const; + /// Compute th mixed rolling resistance factor between two colliders + decimal computeMixedRollingResistance(Collider* collider1, Collider* collider2) const; /// Compute the two unit orthogonal vectors "t1" and "t2" that span the tangential friction /// plane for a contact manifold. The two vectors have to be diff --git a/src/utils/Logger.cpp b/src/utils/Logger.cpp index 19d7a98d..853c8a59 100644 --- a/src/utils/Logger.cpp +++ b/src/utils/Logger.cpp @@ -32,10 +32,9 @@ using namespace reactphysics3d; // Constructor -Logger::Logger() - : mDestinations(MemoryManager::getBaseAllocator()), mFormatters(MemoryManager::getBaseAllocator()) +Logger::Logger(MemoryAllocator& allocator) + : mAllocator(allocator), mDestinations(allocator), mFormatters(allocator) { - // Create the log formatters mFormatters.add(Pair(Format::Text, new TextFormatter())); mFormatters.add(Pair(Format::HTML, new HtmlFormatter())); @@ -46,7 +45,7 @@ Logger::~Logger() { removeAllDestinations(); - // Remove all the loggers + // Remove all the formatters for (auto it = mFormatters.begin(); it != mFormatters.end(); ++it) { delete it->second; @@ -67,14 +66,14 @@ Logger::Formatter* Logger::getFormatter(Format format) const { // Add a log file destination to the logger void Logger::addFileDestination(const std::string& filePath, uint logLevelFlag, Format format) { - FileDestination* destination = new FileDestination(filePath, logLevelFlag, getFormatter(format)); + FileDestination* destination = new (mAllocator.allocate(sizeof(FileDestination))) FileDestination(filePath, logLevelFlag, getFormatter(format)); mDestinations.add(destination); } /// Add a stream destination to the logger void Logger::addStreamDestination(std::ostream& outputStream, uint logLevelFlag, Format format) { - StreamDestination* destination = new StreamDestination(outputStream, logLevelFlag, getFormatter(format)); + StreamDestination* destination = new (mAllocator.allocate(sizeof(StreamDestination))) StreamDestination(outputStream, logLevelFlag, getFormatter(format)); mDestinations.add(destination); } @@ -83,7 +82,12 @@ void Logger::removeAllDestinations() { // Delete all the destinations for (uint i=0; igetSizeBytes(); + + mDestinations[i]->~Destination(); + + mAllocator.release(mDestinations[i], size); } mDestinations.clear(); diff --git a/src/utils/Logger.h b/src/utils/Logger.h index 5065043c..a1bbc6c0 100644 --- a/src/utils/Logger.h +++ b/src/utils/Logger.h @@ -343,6 +343,9 @@ class Logger { /// Write a message into the output stream virtual void write(const time_t& time, const std::string& message, Level level, Category category) = 0; + + /// Return the size in bytes of the type + virtual size_t getSizeBytes() const=0; }; class FileDestination : public Destination { @@ -386,6 +389,11 @@ class Logger { virtual void write(const time_t& time, const std::string& message, Level level, Category category) override { mFileStream << formatter->format(time, message, level, category) << std::endl << std::flush; } + + /// Return the size in bytes of the type + virtual size_t getSizeBytes() const override { + return sizeof(FileDestination); + } }; /// Stream destination to output the logs into a stream @@ -417,6 +425,11 @@ class Logger { virtual void write(const time_t& time, const std::string& message, Level level, Category category) override { mOutputStream << formatter->format(time, message, level, category) << std::endl << std::flush; } + + /// Return the size in bytes of the type + virtual size_t getSizeBytes() const override { + return sizeof(StreamDestination); + } }; @@ -424,6 +437,9 @@ class Logger { // -------------------- Attributes -------------------- // + /// Memory allocator + MemoryAllocator& mAllocator; + /// All the log destinations List mDestinations; @@ -438,16 +454,16 @@ class Logger { /// Return the corresponding formatter Formatter* getFormatter(Format format) const; - public : - - // -------------------- Methods -------------------- // - /// Constructor - Logger(); + Logger(MemoryAllocator& allocator); /// Destructor ~Logger(); + public : + + // -------------------- Methods -------------------- // + /// Add a file destination to the logger void addFileDestination(const std::string& filePath, uint logLevelFlag, Format format); @@ -459,6 +475,10 @@ class Logger { /// Log something void log(Level level, Category category, const std::string& message); + + // ---------- Friendship ---------- // + + friend class PhysicsCommon; }; } diff --git a/src/utils/Profiler.h b/src/utils/Profiler.h index b1f583f7..0d88c292 100644 --- a/src/utils/Profiler.h +++ b/src/utils/Profiler.h @@ -310,16 +310,16 @@ class Profiler { /// Destroy the profiler (release the memory) void destroy(); + /// Constructor + Profiler(); + + /// Destructor + ~Profiler(); + public : // -------------------- Methods -------------------- // - /// Constructor - Profiler(); - - /// Destructor - ~Profiler(); - /// Method called when we want to start profiling a block of code. void startProfilingBlock(const char *name); @@ -356,6 +356,9 @@ class Profiler { /// Print the report of the profiler in every output destinations void printReport(); + + // ---------- Friendship ---------- // + friend class PhysicsCommon; }; // Class ProfileSample diff --git a/test/tests/collision/TestDynamicAABBTree.h b/test/tests/collision/TestDynamicAABBTree.h index 5c39fb99..15c04edd 100755 --- a/test/tests/collision/TestDynamicAABBTree.h +++ b/test/tests/collision/TestDynamicAABBTree.h @@ -125,12 +125,6 @@ class TestDynamicAABBTree : public Test { // Dynamic AABB Tree DynamicAABBTree tree(mAllocator); -#ifdef IS_PROFILING_ACTIVE - /// Pointer to the profiler - Profiler* profiler = new Profiler(); - tree.setProfiler(profiler); -#endif - int object1Data = 56; int object2Data = 23; int object3Data = 13; @@ -168,10 +162,6 @@ class TestDynamicAABBTree : public Test { rp3d_test(*(int*)(tree.getNodeDataPointer(object2Id)) == object2Data); rp3d_test(*(int*)(tree.getNodeDataPointer(object3Id)) == object3Data); rp3d_test(*(int*)(tree.getNodeDataPointer(object4Id)) == object4Data); - -#ifdef IS_PROFILING_ACTIVE - delete profiler; -#endif } void testOverlapping() { @@ -181,12 +171,6 @@ class TestDynamicAABBTree : public Test { // Dynamic AABB Tree DynamicAABBTree tree(mAllocator); -#ifdef IS_PROFILING_ACTIVE - /// Pointer to the profiler - Profiler* profiler = new Profiler(); - tree.setProfiler(profiler); -#endif - int object1Data = 56; int object2Data = 23; int object3Data = 13; @@ -370,9 +354,6 @@ class TestDynamicAABBTree : public Test { rp3d_test(!isOverlapping(object3Id, overlappingNodes)); rp3d_test(!isOverlapping(object4Id, overlappingNodes)); -#ifdef IS_PROFILING_ACTIVE - delete profiler; -#endif } void testRaycast() { @@ -382,12 +363,6 @@ class TestDynamicAABBTree : public Test { // Dynamic AABB Tree DynamicAABBTree tree(mAllocator); -#ifdef IS_PROFILING_ACTIVE - /// Pointer to the profiler - Profiler* profiler = new Profiler(); - tree.setProfiler(profiler); -#endif - int object1Data = 56; int object2Data = 23; int object3Data = 13; @@ -551,9 +526,6 @@ class TestDynamicAABBTree : public Test { rp3d_test(mRaycastCallback.isHit(object3Id)); rp3d_test(mRaycastCallback.isHit(object4Id)); -#ifdef IS_PROFILING_ACTIVE - delete profiler; -#endif } }; diff --git a/testbed/common/Box.h b/testbed/common/Box.h index 61a80d89..9ff20b1d 100644 --- a/testbed/common/Box.h +++ b/testbed/common/Box.h @@ -82,13 +82,16 @@ class Box : public PhysicsObject { Box(const openglframework::Vector3& size, float mass, reactphysics3d::PhysicsCommon& physicsCommon, reactphysics3d::PhysicsWorld *world, const std::string& meshFolderPath); /// Destructor - ~Box(); + virtual ~Box() override; /// Render the cube at the correct position and with the correct orientation virtual void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) override; /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; + + /// Return the collider + rp3d::Collider* getCollider(); }; // Update the transform matrix of the object @@ -96,5 +99,10 @@ inline void Box::updateTransform(float interpolationFactor) { mTransformMatrix = computeTransform(interpolationFactor, mScalingMatrix); } +// Return the collider +inline rp3d::Collider* Box::getCollider() { + return mCollider; +} + #endif diff --git a/testbed/common/Capsule.h b/testbed/common/Capsule.h index 53d9bac4..92f11066 100644 --- a/testbed/common/Capsule.h +++ b/testbed/common/Capsule.h @@ -51,9 +51,6 @@ class Capsule : public PhysicsObject { rp3d::CapsuleShape* mCapsuleShape; rp3d::Collider* mCollider; - /// Previous transform (for interpolation) - rp3d::Transform mPreviousTransform; - /// Vertex Buffer Object for the vertices data static openglframework::VertexBufferObject mVBOVertices; @@ -86,13 +83,16 @@ class Capsule : public PhysicsObject { const std::string& meshFolderPath); /// Destructor - ~Capsule(); + virtual ~Capsule() override; /// Render the sphere at the correct position and with the correct orientation virtual void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) override; /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; + + /// Return the collider + rp3d::Collider* getCollider(); }; // Update the transform matrix of the object @@ -100,4 +100,9 @@ inline void Capsule::updateTransform(float interpolationFactor) { mTransformMatrix = computeTransform(interpolationFactor, mScalingMatrix); } +// Return the collider +inline rp3d::Collider* Capsule::getCollider() { + return mCollider; +} + #endif diff --git a/testbed/common/ConcaveMesh.h b/testbed/common/ConcaveMesh.h index 460fceb9..345363f4 100644 --- a/testbed/common/ConcaveMesh.h +++ b/testbed/common/ConcaveMesh.h @@ -38,9 +38,6 @@ class ConcaveMesh : public PhysicsObject { // -------------------- Attributes -------------------- // - /// Previous transform (for interpolation) - rp3d::Transform mPreviousTransform; - /// Collision shape rp3d::ConcaveMeshShape* mConcaveShape; rp3d::Collider* mCollider; @@ -82,7 +79,7 @@ class ConcaveMesh : public PhysicsObject { ConcaveMesh(float mass, reactphysics3d::PhysicsCommon& physicsCommon, rp3d::PhysicsWorld* physicsWorld, const std::string& meshPath); /// Destructor - ~ConcaveMesh(); + virtual ~ConcaveMesh() override; /// Render the mesh at the correct position and with the correct orientation void render(openglframework::Shader& shader, @@ -90,6 +87,10 @@ class ConcaveMesh : public PhysicsObject { /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; + + /// Return the collider + rp3d::Collider* getCollider(); + }; // Update the transform matrix of the object @@ -97,4 +98,9 @@ inline void ConcaveMesh::updateTransform(float interpolationFactor) { mTransformMatrix = computeTransform(interpolationFactor, mScalingMatrix); } +// Return the collider +inline rp3d::Collider* ConcaveMesh::getCollider() { + return mCollider; +} + #endif diff --git a/testbed/common/ConvexMesh.h b/testbed/common/ConvexMesh.h index 01adff73..ae25149d 100644 --- a/testbed/common/ConvexMesh.h +++ b/testbed/common/ConvexMesh.h @@ -38,9 +38,6 @@ class ConvexMesh : public PhysicsObject { // -------------------- Attributes -------------------- // - /// Previous transform (for interpolation) - rp3d::Transform mPreviousTransform; - rp3d::PolygonVertexArray::PolygonFace* mPolygonFaces; rp3d::PolygonVertexArray* mPolygonVertexArray; @@ -95,13 +92,16 @@ class ConvexMesh : public PhysicsObject { ConvexMesh(float mass, rp3d::PhysicsCommon& physicsCommon, rp3d::PhysicsWorld* physicsWorld, const std::string& meshPath); /// Destructor - ~ConvexMesh(); + virtual ~ConvexMesh() override; /// Render the mesh at the correct position and with the correct orientation virtual void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) override; /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; + + /// Return the collider + rp3d::Collider* getCollider(); }; // Update the transform matrix of the object @@ -109,4 +109,9 @@ inline void ConvexMesh::updateTransform(float interpolationFactor) { mTransformMatrix = computeTransform(interpolationFactor, mScalingMatrix); } +// Return the collider +inline rp3d::Collider* ConvexMesh::getCollider() { + return mCollider; +} + #endif diff --git a/testbed/common/Dumbbell.h b/testbed/common/Dumbbell.h index ce1e38e7..3c411a55 100644 --- a/testbed/common/Dumbbell.h +++ b/testbed/common/Dumbbell.h @@ -51,9 +51,6 @@ class Dumbbell : public PhysicsObject { /// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions) openglframework::Matrix4 mScalingMatrix; - /// Previous transform (for interpolation) - rp3d::Transform mPreviousTransform; - /// Vertex Buffer Object for the vertices data static openglframework::VertexBufferObject mVBOVertices; @@ -86,13 +83,22 @@ class Dumbbell : public PhysicsObject { const std::string& meshFolderPath); /// Destructor - ~Dumbbell(); + virtual ~Dumbbell() override; /// Render the sphere at the correct position and with the correct orientation virtual void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) override; /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; + + /// Return the capsule collider + rp3d::Collider* getCapsuleCollider(); + + /// Return the first sphere collider + rp3d::Collider* getSphere1Collider(); + + /// Return the second sphere collider + rp3d::Collider* getSphere2Collider(); }; // Update the transform matrix of the object @@ -100,4 +106,19 @@ inline void Dumbbell::updateTransform(float interpolationFactor) { mTransformMatrix = computeTransform(interpolationFactor, mScalingMatrix); } +// Return the capsule collider +inline rp3d::Collider* Dumbbell::getCapsuleCollider() { + return mColliderCapsule; +} + +// Return the first sphere collider +inline rp3d::Collider* Dumbbell::getSphere1Collider() { + return mColliderSphere1; +} + +// Return the second sphere collider +inline rp3d::Collider* Dumbbell::getSphere2Collider() { + return mColliderSphere2; +} + #endif diff --git a/testbed/common/HeightField.h b/testbed/common/HeightField.h index af46aa1f..1599aa79 100644 --- a/testbed/common/HeightField.h +++ b/testbed/common/HeightField.h @@ -45,9 +45,6 @@ class HeightField : public PhysicsObject { /// Height field data float mHeightData[NB_POINTS_WIDTH * NB_POINTS_LENGTH]; - /// Previous transform (for interpolation) - rp3d::Transform mPreviousTransform; - /// Collision shape rp3d::HeightFieldShape* mHeightFieldShape; rp3d::Collider* mCollider; @@ -95,7 +92,7 @@ class HeightField : public PhysicsObject { HeightField(float mass, rp3d::PhysicsCommon& physicsCommon, rp3d::PhysicsWorld* physicsWorld); /// Destructor - ~HeightField(); + virtual ~HeightField() override; /// Render the mesh at the correct position and with the correct orientation void render(openglframework::Shader& shader, @@ -103,6 +100,9 @@ class HeightField : public PhysicsObject { /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; + + /// Return the collider + rp3d::Collider* getCollider(); }; // Update the transform matrix of the object @@ -110,4 +110,9 @@ inline void HeightField::updateTransform(float interpolationFactor) { mTransformMatrix = computeTransform(interpolationFactor, mScalingMatrix); } +// Return the collider +inline rp3d::Collider* HeightField::getCollider() { + return mCollider; +} + #endif diff --git a/testbed/common/Sphere.h b/testbed/common/Sphere.h index 9a517173..a31d287c 100644 --- a/testbed/common/Sphere.h +++ b/testbed/common/Sphere.h @@ -48,9 +48,6 @@ class Sphere : public PhysicsObject { /// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions) openglframework::Matrix4 mScalingMatrix; - /// Previous transform (for interpolation) - rp3d::Transform mPreviousTransform; - /// Vertex Buffer Object for the vertices data static openglframework::VertexBufferObject mVBOVertices; @@ -92,6 +89,9 @@ class Sphere : public PhysicsObject { /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; + + /// Return the collider + rp3d::Collider* getCollider(); }; // Update the transform matrix of the object @@ -99,4 +99,9 @@ inline void Sphere::updateTransform(float interpolationFactor) { mTransformMatrix = computeTransform(interpolationFactor, mScalingMatrix); } +// Return the collider +inline rp3d::Collider* Sphere::getCollider() { + return mCollider; +} + #endif diff --git a/testbed/scenes/collisionshapes/CollisionShapesScene.cpp b/testbed/scenes/collisionshapes/CollisionShapesScene.cpp index 40854ff1..e8601c5f 100644 --- a/testbed/scenes/collisionshapes/CollisionShapesScene.cpp +++ b/testbed/scenes/collisionshapes/CollisionShapesScene.cpp @@ -63,8 +63,12 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettin dumbbell->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = dumbbell->getRigidBody()->getMaterial(); - material.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& capsuleMaterial = dumbbell->getCapsuleCollider()->getMaterial(); + capsuleMaterial.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& sphere1Material = dumbbell->getSphere1Collider()->getMaterial(); + sphere1Material.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& sphere2Material = dumbbell->getSphere2Collider()->getMaterial(); + sphere2Material.setBounciness(rp3d::decimal(0.2)); // Add the mesh the list of dumbbells in the scene mDumbbells.push_back(dumbbell); @@ -82,7 +86,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettin box->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = box->getRigidBody()->getMaterial(); + rp3d::Material& material = box->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the sphere the list of sphere in the scene @@ -97,14 +101,14 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettin Sphere* sphere = new Sphere(SPHERE_RADIUS, BOX_MASS, mPhysicsCommon, mPhysicsWorld, meshFolderPath); // Add some rolling resistance - sphere->getRigidBody()->getMaterial().setRollingResistance(rp3d::decimal(0.08)); + sphere->getCollider()->getMaterial().setRollingResistance(rp3d::decimal(0.08)); // Set the box color sphere->setColor(mObjectColorDemo); sphere->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = sphere->getRigidBody()->getMaterial(); + rp3d::Material& material = sphere->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the sphere the list of sphere in the scene @@ -119,14 +123,14 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettin Capsule* capsule = new Capsule(true, CAPSULE_RADIUS, CAPSULE_HEIGHT, CAPSULE_MASS, mPhysicsCommon, mPhysicsWorld, meshFolderPath); - capsule->getRigidBody()->getMaterial().setRollingResistance(rp3d::decimal(0.08f)); + capsule->getCollider()->getMaterial().setRollingResistance(rp3d::decimal(0.08f)); // Set the box color capsule->setColor(mObjectColorDemo); capsule->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = capsule->getRigidBody()->getMaterial(); + rp3d::Material& material = capsule->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the cylinder the list of sphere in the scene @@ -145,7 +149,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettin mesh->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = mesh->getRigidBody()->getMaterial(); + rp3d::Material& material = mesh->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the mesh the list of sphere in the scene @@ -166,7 +170,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettin mFloor->getRigidBody()->setType(rp3d::BodyType::STATIC); // Change the material properties of the rigid body - rp3d::Material& material = mFloor->getRigidBody()->getMaterial(); + rp3d::Material& material = mFloor->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Get the physics engine parameters diff --git a/testbed/scenes/concavemesh/ConcaveMeshScene.cpp b/testbed/scenes/concavemesh/ConcaveMeshScene.cpp index 43fb7e9b..7e7d6cfa 100644 --- a/testbed/scenes/concavemesh/ConcaveMeshScene.cpp +++ b/testbed/scenes/concavemesh/ConcaveMeshScene.cpp @@ -64,8 +64,12 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& sett dumbbell->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = dumbbell->getRigidBody()->getMaterial(); - material.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& capsuleMaterial = dumbbell->getCapsuleCollider()->getMaterial(); + capsuleMaterial.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& sphere1Material = dumbbell->getSphere1Collider()->getMaterial(); + sphere1Material.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& sphere2Material = dumbbell->getSphere2Collider()->getMaterial(); + sphere2Material.setBounciness(rp3d::decimal(0.2)); // Add the mesh the list of dumbbells in the scene mDumbbells.push_back(dumbbell); @@ -83,7 +87,7 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& sett box->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = box->getRigidBody()->getMaterial(); + rp3d::Material& material = box->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the sphere the list of sphere in the scene @@ -98,14 +102,14 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& sett Sphere* sphere = new Sphere(SPHERE_RADIUS, BOX_MASS, mPhysicsCommon, mPhysicsWorld, meshFolderPath); // Add some rolling resistance - sphere->getRigidBody()->getMaterial().setRollingResistance(rp3d::decimal(0.08)); + sphere->getCollider()->getMaterial().setRollingResistance(rp3d::decimal(0.08)); // Set the box color sphere->setColor(mObjectColorDemo); sphere->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = sphere->getRigidBody()->getMaterial(); + rp3d::Material& material = sphere->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the sphere the list of sphere in the scene @@ -120,14 +124,14 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& sett Capsule* capsule = new Capsule(true, CAPSULE_RADIUS, CAPSULE_HEIGHT, CAPSULE_MASS, mPhysicsCommon, mPhysicsWorld, meshFolderPath); - capsule->getRigidBody()->getMaterial().setRollingResistance(rp3d::decimal(0.08)); + capsule->getCollider()->getMaterial().setRollingResistance(rp3d::decimal(0.08)); // Set the box color capsule->setColor(mObjectColorDemo); capsule->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = capsule->getRigidBody()->getMaterial(); + rp3d::Material& material = capsule->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the cylinder the list of sphere in the scene @@ -146,7 +150,7 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& sett mesh->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = mesh->getRigidBody()->getMaterial(); + rp3d::Material& material = mesh->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the mesh the list of sphere in the scene @@ -172,7 +176,7 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& sett mPhysicsObjects.push_back(mConcaveMesh); // Change the material properties of the rigid body - rp3d::Material& material = mConcaveMesh->getRigidBody()->getMaterial(); + rp3d::Material& material = mConcaveMesh->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); material.setFrictionCoefficient(rp3d::decimal(0.1)); diff --git a/testbed/scenes/cubes/CubesScene.cpp b/testbed/scenes/cubes/CubesScene.cpp index 5c8424d5..c1283c2d 100644 --- a/testbed/scenes/cubes/CubesScene.cpp +++ b/testbed/scenes/cubes/CubesScene.cpp @@ -62,7 +62,7 @@ CubesScene::CubesScene(const std::string& name, EngineSettings& settings) cube->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = cube->getRigidBody()->getMaterial(); + rp3d::Material& material = cube->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.4)); // Add the box the list of box in the scene diff --git a/testbed/scenes/cubestack/CubeStackScene.cpp b/testbed/scenes/cubestack/CubeStackScene.cpp index 6188ddb4..4df85758 100644 --- a/testbed/scenes/cubestack/CubeStackScene.cpp +++ b/testbed/scenes/cubestack/CubeStackScene.cpp @@ -64,7 +64,7 @@ CubeStackScene::CubeStackScene(const std::string& name, EngineSettings& settings cube->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = cube->getRigidBody()->getMaterial(); + rp3d::Material& material = cube->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.4)); // Add the box the list of box in the scene diff --git a/testbed/scenes/heightfield/HeightFieldScene.cpp b/testbed/scenes/heightfield/HeightFieldScene.cpp index fbea65e5..3d41046c 100644 --- a/testbed/scenes/heightfield/HeightFieldScene.cpp +++ b/testbed/scenes/heightfield/HeightFieldScene.cpp @@ -63,8 +63,12 @@ HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& sett dumbbell->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = dumbbell->getRigidBody()->getMaterial(); - material.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& capsuleMaterial = dumbbell->getCapsuleCollider()->getMaterial(); + capsuleMaterial.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& sphere1Material = dumbbell->getSphere1Collider()->getMaterial(); + sphere1Material.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& sphere2Material = dumbbell->getSphere2Collider()->getMaterial(); + sphere2Material.setBounciness(rp3d::decimal(0.2)); // Add the mesh the list of dumbbells in the scene mDumbbells.push_back(dumbbell); @@ -82,7 +86,7 @@ HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& sett box->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = box->getRigidBody()->getMaterial(); + rp3d::Material& material = box->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the sphere the list of sphere in the scene @@ -97,14 +101,14 @@ HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& sett Sphere* sphere = new Sphere(SPHERE_RADIUS, BOX_MASS, mPhysicsCommon, mPhysicsWorld, meshFolderPath); // Add some rolling resistance - sphere->getRigidBody()->getMaterial().setRollingResistance(0.08f); + sphere->getCollider()->getMaterial().setRollingResistance(0.08f); // Set the box color sphere->setColor(mObjectColorDemo); sphere->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = sphere->getRigidBody()->getMaterial(); + rp3d::Material& material = sphere->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the sphere the list of sphere in the scene @@ -119,14 +123,14 @@ HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& sett Capsule* capsule = new Capsule(true, CAPSULE_RADIUS, CAPSULE_HEIGHT, CAPSULE_MASS, mPhysicsCommon, mPhysicsWorld, meshFolderPath); - capsule->getRigidBody()->getMaterial().setRollingResistance(0.08f); + capsule->getCollider()->getMaterial().setRollingResistance(0.08f); // Set the box color capsule->setColor(mObjectColorDemo); capsule->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = capsule->getRigidBody()->getMaterial(); + rp3d::Material& material = capsule->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the cylinder the list of sphere in the scene @@ -145,7 +149,7 @@ HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& sett mesh->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = mesh->getRigidBody()->getMaterial(); + rp3d::Material& material = mesh->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the mesh the list of sphere in the scene @@ -171,7 +175,7 @@ HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& sett mHeightField->setSleepingColor(mFloorColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = mHeightField->getRigidBody()->getMaterial(); + rp3d::Material& material = mHeightField->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); material.setFrictionCoefficient(0.1f); diff --git a/testbed/scenes/joints/JointsScene.cpp b/testbed/scenes/joints/JointsScene.cpp index b3c5df71..c8f03ce7 100644 --- a/testbed/scenes/joints/JointsScene.cpp +++ b/testbed/scenes/joints/JointsScene.cpp @@ -230,7 +230,7 @@ void JointsScene::createBallAndSocketJoints() { mBallAndSocketJointChainBoxes[i]->getRigidBody()->setAngularDamping(rp3d::decimal(0.2)); // Change the material properties of the rigid body - rp3d::Material& material = mBallAndSocketJointChainBoxes[i]->getRigidBody()->getMaterial(); + rp3d::Material& material = mBallAndSocketJointChainBoxes[i]->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.4)); mPhysicsObjects.push_back(mBallAndSocketJointChainBoxes[i]); @@ -277,7 +277,7 @@ void JointsScene::createSliderJoint() { mSliderJointBottomBox->getRigidBody()->setType(rp3d::BodyType::STATIC); // Change the material properties of the rigid body - rp3d::Material& material1 = mSliderJointBottomBox->getRigidBody()->getMaterial(); + rp3d::Material& material1 = mSliderJointBottomBox->getCollider()->getMaterial(); material1.setBounciness(0.4f); mPhysicsObjects.push_back(mSliderJointBottomBox); @@ -296,7 +296,7 @@ void JointsScene::createSliderJoint() { mSliderJointTopBox->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material2 = mSliderJointTopBox->getRigidBody()->getMaterial(); + rp3d::Material& material2 = mSliderJointTopBox->getCollider()->getMaterial(); material2.setBounciness(0.4f); mPhysicsObjects.push_back(mSliderJointTopBox); @@ -338,7 +338,7 @@ void JointsScene::createPropellerHingeJoint() { mPropellerBox->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = mPropellerBox->getRigidBody()->getMaterial(); + rp3d::Material& material = mPropellerBox->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.4)); mPhysicsObjects.push_back(mPropellerBox); @@ -379,7 +379,7 @@ void JointsScene::createFixedJoints() { mFixedJointBox1->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material1 = mFixedJointBox1->getRigidBody()->getMaterial(); + rp3d::Material& material1 = mFixedJointBox1->getCollider()->getMaterial(); material1.setBounciness(rp3d::decimal(0.4)); mPhysicsObjects.push_back(mFixedJointBox1); @@ -397,7 +397,7 @@ void JointsScene::createFixedJoints() { mFixedJointBox2->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material2 = mFixedJointBox2->getRigidBody()->getMaterial(); + rp3d::Material& material2 = mFixedJointBox2->getCollider()->getMaterial(); material2.setBounciness(rp3d::decimal(0.4)); mPhysicsObjects.push_back(mFixedJointBox2); @@ -440,7 +440,7 @@ void JointsScene::createFloor() { mFloor->getRigidBody()->setType(rp3d::BodyType::STATIC); // Change the material properties of the rigid body - rp3d::Material& material = mFloor->getRigidBody()->getMaterial(); + rp3d::Material& material = mFloor->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.3)); mPhysicsObjects.push_back(mFloor); } diff --git a/testbed/scenes/pile/PileScene.cpp b/testbed/scenes/pile/PileScene.cpp index 49c206e6..ceb3b9c8 100644 --- a/testbed/scenes/pile/PileScene.cpp +++ b/testbed/scenes/pile/PileScene.cpp @@ -61,8 +61,12 @@ PileScene::PileScene(const std::string& name, EngineSettings& settings) dumbbell->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = dumbbell->getRigidBody()->getMaterial(); - material.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& capsuleMaterial = dumbbell->getCapsuleCollider()->getMaterial(); + capsuleMaterial.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& sphere1Material = dumbbell->getSphere1Collider()->getMaterial(); + sphere1Material.setBounciness(rp3d::decimal(0.2)); + rp3d::Material& sphere2Material = dumbbell->getSphere2Collider()->getMaterial(); + sphere2Material.setBounciness(rp3d::decimal(0.2)); // Add the mesh the list of dumbbells in the scene mDumbbells.push_back(dumbbell); @@ -80,7 +84,7 @@ PileScene::PileScene(const std::string& name, EngineSettings& settings) box->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = box->getRigidBody()->getMaterial(); + rp3d::Material& material = box->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the sphere the list of sphere in the scene @@ -95,14 +99,14 @@ PileScene::PileScene(const std::string& name, EngineSettings& settings) Sphere* sphere = new Sphere(SPHERE_RADIUS, BOX_MASS, mPhysicsCommon, mPhysicsWorld, meshFolderPath); // Add some rolling resistance - sphere->getRigidBody()->getMaterial().setRollingResistance(rp3d::decimal(0.08)); + sphere->getCollider()->getMaterial().setRollingResistance(rp3d::decimal(0.08)); // Set the box color sphere->setColor(mObjectColorDemo); sphere->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = sphere->getRigidBody()->getMaterial(); + rp3d::Material& material = sphere->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the sphere the list of sphere in the scene @@ -117,14 +121,14 @@ PileScene::PileScene(const std::string& name, EngineSettings& settings) Capsule* capsule = new Capsule(true, CAPSULE_RADIUS, CAPSULE_HEIGHT, CAPSULE_MASS, mPhysicsCommon, mPhysicsWorld, meshFolderPath); - capsule->getRigidBody()->getMaterial().setRollingResistance(rp3d::decimal(0.08f)); + capsule->getCollider()->getMaterial().setRollingResistance(rp3d::decimal(0.08f)); // Set the box color capsule->setColor(mObjectColorDemo); capsule->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = capsule->getRigidBody()->getMaterial(); + rp3d::Material& material = capsule->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the cylinder the list of sphere in the scene @@ -143,7 +147,7 @@ PileScene::PileScene(const std::string& name, EngineSettings& settings) mesh->setSleepingColor(mSleepingColorDemo); // Change the material properties of the rigid body - rp3d::Material& material = mesh->getRigidBody()->getMaterial(); + rp3d::Material& material = mesh->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); // Add the mesh the list of sphere in the scene @@ -169,7 +173,7 @@ PileScene::PileScene(const std::string& name, EngineSettings& settings) mPhysicsObjects.push_back(mSandbox); // Change the material properties of the rigid body - rp3d::Material& material = mSandbox->getRigidBody()->getMaterial(); + rp3d::Material& material = mSandbox->getCollider()->getMaterial(); material.setBounciness(rp3d::decimal(0.2)); material.setFrictionCoefficient(rp3d::decimal(0.1));