[DEBUG] correct no element simulation
This commit is contained in:
parent
bffbb22e1a
commit
e3ab17461d
@ -118,49 +118,56 @@ 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();
|
||||||
|
|
||||||
// Compute the collision detection
|
if (mRigidBodies.size() == 0) {
|
||||||
mCollisionDetection.computeCollisionDetection();
|
// no rigid body ==> no process to do ...
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the islands (separate groups of bodies with constraints between each others)
|
// Compute the collision detection
|
||||||
computeIslands();
|
mCollisionDetection.computeCollisionDetection();
|
||||||
|
|
||||||
// Integrate the velocities
|
// Compute the islands (separate groups of bodies with constraints between each others)
|
||||||
integrateRigidBodiesVelocities();
|
computeIslands();
|
||||||
|
|
||||||
// Solve the contacts and constraints
|
// Integrate the velocities
|
||||||
solveContactsAndConstraints();
|
integrateRigidBodiesVelocities();
|
||||||
|
|
||||||
// Integrate the position and orientation of each body
|
// Solve the contacts and constraints
|
||||||
integrateRigidBodiesPositions();
|
solveContactsAndConstraints();
|
||||||
|
|
||||||
// Solve the position correction for constraints
|
// Integrate the position and orientation of each body
|
||||||
solvePositionCorrection();
|
integrateRigidBodiesPositions();
|
||||||
|
|
||||||
// Update the state (positions and velocities) of the bodies
|
// Solve the position correction for constraints
|
||||||
updateBodiesState();
|
solvePositionCorrection();
|
||||||
|
|
||||||
if (mIsSleepingEnabled) updateSleepingBodies();
|
// Update the state (positions and velocities) of the bodies
|
||||||
|
updateBodiesState();
|
||||||
|
|
||||||
// Notify the event listener about the end of an internal tick
|
if (mIsSleepingEnabled) updateSleepingBodies();
|
||||||
if (mEventListener != NULL) mEventListener->endInternalTick();
|
|
||||||
|
|
||||||
// Reset the external force and torque applied to the bodies
|
// Notify the event listener about the end of an internal tick
|
||||||
resetBodiesForceAndTorque();
|
if (mEventListener != NULL) mEventListener->endInternalTick();
|
||||||
|
|
||||||
|
// Reset the external force and torque applied to the bodies
|
||||||
|
resetBodiesForceAndTorque();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integrate position and orientation of the rigid bodies.
|
// Integrate position and orientation of the rigid bodies.
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
protected :
|
||||||
class CubesScene : public SceneDemo {
|
/// All the boxes of the scene
|
||||||
|
std::vector<Box*> mBoxes;
|
||||||
protected :
|
/// Box for the floor
|
||||||
|
Box* mFloor;
|
||||||
// -------------------- Attributes -------------------- //
|
/// Dynamics world used for the physics simulation
|
||||||
|
rp3d::DynamicsWorld* m_dynamicsWorld;
|
||||||
/// All the boxes of the scene
|
public:
|
||||||
std::vector<Box*> mBoxes;
|
/// Constructor
|
||||||
|
CubesScene(const std::string& name);
|
||||||
/// Box for the floor
|
/// Destructor
|
||||||
Box* mFloor;
|
virtual ~CubesScene();
|
||||||
|
/// Update the physics world (take a simulation step)
|
||||||
/// Dynamics world used for the physics simulation
|
/// Can be called several times per frame
|
||||||
rp3d::DynamicsWorld* mDynamicsWorld;
|
virtual void updatePhysics();
|
||||||
|
/// Update the scene (take a simulation step)
|
||||||
public:
|
virtual void update();
|
||||||
|
/// Render the scene in a single pass
|
||||||
// -------------------- Methods -------------------- //
|
virtual void renderSinglePass(openglframework::Shader& shader,
|
||||||
|
const openglframework::Matrix4& worldToCameraMatrix);
|
||||||
/// Constructor
|
/// Reset the scene
|
||||||
CubesScene(const std::string& name);
|
virtual void reset();
|
||||||
|
/// Return all the contact points of the scene
|
||||||
/// Destructor
|
virtual std::vector<ContactPoint> getContactPoints() const {
|
||||||
virtual ~CubesScene();
|
return computeContactPointsOfWorld(m_dynamicsWorld);
|
||||||
|
}
|
||||||
/// Update the physics world (take a simulation step)
|
};
|
||||||
/// Can be called several times per frame
|
|
||||||
virtual void updatePhysics();
|
|
||||||
|
|
||||||
/// Update the scene (take a simulation step)
|
|
||||||
virtual void update();
|
|
||||||
|
|
||||||
/// Render the scene in a single pass
|
|
||||||
virtual void renderSinglePass(openglframework::Shader& shader,
|
|
||||||
const openglframework::Matrix4& worldToCameraMatrix);
|
|
||||||
|
|
||||||
/// Reset the scene
|
|
||||||
virtual void reset();
|
|
||||||
|
|
||||||
/// Return all the contact points of the scene
|
|
||||||
virtual std::vector<ContactPoint> getContactPoints() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return all the contact points of the scene
|
|
||||||
inline std::vector<ContactPoint> CubesScene::getContactPoints() const {
|
|
||||||
return computeContactPointsOfWorld(mDynamicsWorld);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user