The Material is now part of the Collider instead of the RigidBody, fixes compilation errors with Logger and Profiler.
This commit is contained in:
parent
36bdfe8037
commit
c5873dbc6b
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
// Libraries
|
||||
#include <cassert>
|
||||
#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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -94,7 +94,7 @@ class Material {
|
|||
|
||||
// ---------- Friendship ---------- //
|
||||
|
||||
friend class RigidBody;
|
||||
friend class Collider;
|
||||
};
|
||||
|
||||
// Return the bounciness
|
||||
|
|
|
@ -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<uint>(Logger::Level::Information) | static_cast<uint>(Logger::Level::Warning) |
|
||||
static_cast<uint>(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);
|
||||
}
|
||||
|
|
|
@ -82,6 +82,12 @@ class PhysicsCommon {
|
|||
/// Set of triangle meshes
|
||||
Set<TriangleMesh*> mTriangleMeshes;
|
||||
|
||||
/// Set of loggers
|
||||
Set<Logger*> mLoggers;
|
||||
|
||||
/// Set of loggers
|
||||
Set<Profiler*> 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);
|
||||
|
||||
/// 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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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<uint>(Logger::Level::Information) | static_cast<uint>(Logger::Level::Warning) |
|
||||
static_cast<uint>(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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, Formatter*>(Format::Text, new TextFormatter()));
|
||||
mFormatters.add(Pair<Format, Formatter*>(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; i<mDestinations.size(); i++) {
|
||||
delete mDestinations[i];
|
||||
|
||||
size_t size = mDestinations[i]->getSizeBytes();
|
||||
|
||||
mDestinations[i]->~Destination();
|
||||
|
||||
mAllocator.release(mDestinations[i], size);
|
||||
}
|
||||
|
||||
mDestinations.clear();
|
||||
|
|
|
@ -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<Destination*> 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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -310,16 +310,16 @@ class Profiler {
|
|||
/// Destroy the profiler (release the memory)
|
||||
void destroy();
|
||||
|
||||
public :
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
Profiler();
|
||||
|
||||
/// Destructor
|
||||
~Profiler();
|
||||
|
||||
public :
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// 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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user