[DEBUG] correct no element simulation

This commit is contained in:
Edouard DUPIN 2017-05-17 21:40:09 +02:00
parent bffbb22e1a
commit e3ab17461d
4 changed files with 111 additions and 125 deletions

View File

@ -118,21 +118,28 @@ DynamicsWorld::~DynamicsWorld() {
*/ */
void DynamicsWorld::update(decimal timeStep) { void DynamicsWorld::update(decimal timeStep) {
#ifdef IS_PROFILING_ACTIVE #ifdef IS_PROFILING_ACTIVE
// Increment the frame counter of the profiler // Increment the frame counter of the profiler
Profiler::incrementFrameCounter(); Profiler::incrementFrameCounter();
#endif #endif
PROFILE("DynamicsWorld::update()"); PROFILE("DynamicsWorld::update()");
mTimeStep = timeStep; mTimeStep = timeStep;
// Notify the event listener about the beginning of an internal tick // Notify the event listener about the beginning of an internal tick
if (mEventListener != NULL) mEventListener->beginInternalTick(); if (mEventListener != NULL) {
mEventListener->beginInternalTick();
}
// Reset all the contact manifolds lists of each body // Reset all the contact manifolds lists of each body
resetContactManifoldListsOfBodies(); resetContactManifoldListsOfBodies();
if (mRigidBodies.size() == 0) {
// no rigid body ==> no process to do ...
return;
}
// Compute the collision detection // Compute the collision detection
mCollisionDetection.computeCollisionDetection(); mCollisionDetection.computeCollisionDetection();

View File

@ -169,7 +169,8 @@ def configure(target, my_module):
'etk', 'etk',
'ememory' 'ememory'
]) ])
# TODO: Remove this ...
my_module.add_flag('c++', "-Wno-overloaded-virtual", export=True)
my_module.add_path(".") my_module.add_path(".")
return True return True

View File

@ -44,10 +44,10 @@ CubesScene::CubesScene(const std::string& name)
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0); rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
// Create the dynamics world for the physics simulation // Create the dynamics world for the physics simulation
mDynamicsWorld = new rp3d::DynamicsWorld(gravity); m_dynamicsWorld = new rp3d::DynamicsWorld(gravity);
// Set the number of iterations of the constraint solver // Set the number of iterations of the constraint solver
mDynamicsWorld->setNbIterationsVelocitySolver(15); m_dynamicsWorld->setNbIterationsVelocitySolver(15);
float radius = 2.0f; float radius = 2.0f;
@ -61,7 +61,7 @@ CubesScene::CubesScene(const std::string& name)
0); 0);
// Create a cube and a corresponding rigid in the dynamics world // Create a cube and a corresponding rigid in the dynamics world
Box* cube = new Box(BOX_SIZE, position , BOX_MASS, mDynamicsWorld); Box* cube = new Box(BOX_SIZE, position , BOX_MASS, m_dynamicsWorld);
// Set the box color // Set the box color
cube->setColor(mDemoColors[i % mNbDemoColors]); cube->setColor(mDemoColors[i % mNbDemoColors]);
@ -77,7 +77,7 @@ CubesScene::CubesScene(const std::string& name)
// Create the floor // Create the floor
openglframework::Vector3 floorPosition(0, 0, 0); openglframework::Vector3 floorPosition(0, 0, 0);
mFloor = new Box(FLOOR_SIZE, floorPosition, FLOOR_MASS, mDynamicsWorld); mFloor = new Box(FLOOR_SIZE, floorPosition, FLOOR_MASS, m_dynamicsWorld);
mFloor->setColor(mGreyColorDemo); mFloor->setColor(mGreyColorDemo);
mFloor->setSleepingColor(mGreyColorDemo); mFloor->setSleepingColor(mGreyColorDemo);
@ -89,15 +89,15 @@ CubesScene::CubesScene(const std::string& name)
material.setBounciness(rp3d::decimal(0.3)); material.setBounciness(rp3d::decimal(0.3));
// Get the physics engine parameters // Get the physics engine parameters
mEngineSettings.isGravityEnabled = mDynamicsWorld->isGravityEnabled(); mEngineSettings.isGravityEnabled = m_dynamicsWorld->isGravityEnabled();
rp3d::Vector3 gravityVector = mDynamicsWorld->getGravity(); rp3d::Vector3 gravityVector = m_dynamicsWorld->getGravity();
mEngineSettings.gravity = openglframework::Vector3(gravityVector.x, gravityVector.y, gravityVector.z); mEngineSettings.gravity = openglframework::Vector3(gravityVector.x, gravityVector.y, gravityVector.z);
mEngineSettings.isSleepingEnabled = mDynamicsWorld->isSleepingEnabled(); mEngineSettings.isSleepingEnabled = m_dynamicsWorld->isSleepingEnabled();
mEngineSettings.sleepLinearVelocity = mDynamicsWorld->getSleepLinearVelocity(); mEngineSettings.sleepLinearVelocity = m_dynamicsWorld->getSleepLinearVelocity();
mEngineSettings.sleepAngularVelocity = mDynamicsWorld->getSleepAngularVelocity(); mEngineSettings.sleepAngularVelocity = m_dynamicsWorld->getSleepAngularVelocity();
mEngineSettings.nbPositionSolverIterations = mDynamicsWorld->getNbIterationsPositionSolver(); mEngineSettings.nbPositionSolverIterations = m_dynamicsWorld->getNbIterationsPositionSolver();
mEngineSettings.nbVelocitySolverIterations = mDynamicsWorld->getNbIterationsVelocitySolver(); mEngineSettings.nbVelocitySolverIterations = m_dynamicsWorld->getNbIterationsVelocitySolver();
mEngineSettings.timeBeforeSleep = mDynamicsWorld->getTimeBeforeSleep(); mEngineSettings.timeBeforeSleep = m_dynamicsWorld->getTimeBeforeSleep();
} }
// Destructor // Destructor
@ -107,39 +107,39 @@ CubesScene::~CubesScene() {
for (std::vector<Box*>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) { for (std::vector<Box*>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) {
// Destroy the corresponding rigid body from the dynamics world // Destroy the corresponding rigid body from the dynamics world
mDynamicsWorld->destroyRigidBody((*it)->getRigidBody()); m_dynamicsWorld->destroyRigidBody((*it)->getRigidBody());
// Destroy the cube // Destroy the cube
delete (*it); delete (*it);
} }
// Destroy the rigid body of the floor // Destroy the rigid body of the floor
mDynamicsWorld->destroyRigidBody(mFloor->getRigidBody()); m_dynamicsWorld->destroyRigidBody(mFloor->getRigidBody());
// Destroy the floor // Destroy the floor
delete mFloor; delete mFloor;
// Destroy the dynamics world // Destroy the dynamics world
delete mDynamicsWorld; delete m_dynamicsWorld;
} }
// Update the physics world (take a simulation step) // Update the physics world (take a simulation step)
void CubesScene::updatePhysics() { void CubesScene::updatePhysics() {
// Update the physics engine parameters // Update the physics engine parameters
mDynamicsWorld->setIsGratityEnabled(mEngineSettings.isGravityEnabled); m_dynamicsWorld->setIsGratityEnabled(mEngineSettings.isGravityEnabled);
rp3d::Vector3 gravity(mEngineSettings.gravity.x, mEngineSettings.gravity.y, rp3d::Vector3 gravity(mEngineSettings.gravity.x, mEngineSettings.gravity.y,
mEngineSettings.gravity.z); mEngineSettings.gravity.z);
mDynamicsWorld->setGravity(gravity); m_dynamicsWorld->setGravity(gravity);
mDynamicsWorld->enableSleeping(mEngineSettings.isSleepingEnabled); m_dynamicsWorld->enableSleeping(mEngineSettings.isSleepingEnabled);
mDynamicsWorld->setSleepLinearVelocity(mEngineSettings.sleepLinearVelocity); m_dynamicsWorld->setSleepLinearVelocity(mEngineSettings.sleepLinearVelocity);
mDynamicsWorld->setSleepAngularVelocity(mEngineSettings.sleepAngularVelocity); m_dynamicsWorld->setSleepAngularVelocity(mEngineSettings.sleepAngularVelocity);
mDynamicsWorld->setNbIterationsPositionSolver(mEngineSettings.nbPositionSolverIterations); m_dynamicsWorld->setNbIterationsPositionSolver(mEngineSettings.nbPositionSolverIterations);
mDynamicsWorld->setNbIterationsVelocitySolver(mEngineSettings.nbVelocitySolverIterations); m_dynamicsWorld->setNbIterationsVelocitySolver(mEngineSettings.nbVelocitySolverIterations);
mDynamicsWorld->setTimeBeforeSleep(mEngineSettings.timeBeforeSleep); m_dynamicsWorld->setTimeBeforeSleep(mEngineSettings.timeBeforeSleep);
// Take a simulation step // Take a simulation step
mDynamicsWorld->update(mEngineSettings.timeStep); m_dynamicsWorld->update(mEngineSettings.timeStep);
} }
// Update the scene // Update the scene

View File

@ -33,64 +33,42 @@
#include <ephysics/SceneDemo.h> #include <ephysics/SceneDemo.h>
namespace cubesscene { namespace cubesscene {
// Constants
// Constants const float SCENE_RADIUS = 30.0f; // Radius of the scene in meters
const float SCENE_RADIUS = 30.0f; // Radius of the scene in meters const int NB_CUBES = 30; // Number of boxes in the scene
const int NB_CUBES = 30; // Number of boxes in the scene const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters
const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters const openglframework::Vector3 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions in meters
const openglframework::Vector3 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions in meters const float BOX_MASS = 1.0f; // Box mass in kilograms
const float BOX_MASS = 1.0f; // Box mass in kilograms const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms // Class CubesScene
class CubesScene : public SceneDemo {
// Class CubesScene
class CubesScene : public SceneDemo {
protected : protected :
// -------------------- Attributes -------------------- //
/// All the boxes of the scene /// All the boxes of the scene
std::vector<Box*> mBoxes; std::vector<Box*> mBoxes;
/// Box for the floor /// Box for the floor
Box* mFloor; Box* mFloor;
/// Dynamics world used for the physics simulation /// Dynamics world used for the physics simulation
rp3d::DynamicsWorld* mDynamicsWorld; rp3d::DynamicsWorld* m_dynamicsWorld;
public: public:
// -------------------- Methods -------------------- //
/// Constructor /// Constructor
CubesScene(const std::string& name); CubesScene(const std::string& name);
/// Destructor /// Destructor
virtual ~CubesScene(); virtual ~CubesScene();
/// Update the physics world (take a simulation step) /// Update the physics world (take a simulation step)
/// Can be called several times per frame /// Can be called several times per frame
virtual void updatePhysics(); virtual void updatePhysics();
/// Update the scene (take a simulation step) /// Update the scene (take a simulation step)
virtual void update(); virtual void update();
/// Render the scene in a single pass /// Render the scene in a single pass
virtual void renderSinglePass(openglframework::Shader& shader, virtual void renderSinglePass(openglframework::Shader& shader,
const openglframework::Matrix4& worldToCameraMatrix); const openglframework::Matrix4& worldToCameraMatrix);
/// Reset the scene /// Reset the scene
virtual void reset(); virtual void reset();
/// Return all the contact points of the scene /// Return all the contact points of the scene
virtual std::vector<ContactPoint> getContactPoints() const; virtual std::vector<ContactPoint> getContactPoints() const {
}; return computeContactPointsOfWorld(m_dynamicsWorld);
}
// Return all the contact points of the scene };
inline std::vector<ContactPoint> CubesScene::getContactPoints() const {
return computeContactPointsOfWorld(mDynamicsWorld);
}
} }
#endif #endif