[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) {
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
// Increment the frame counter of the profiler
|
||||
Profiler::incrementFrameCounter();
|
||||
#endif
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
// Increment the frame counter of the profiler
|
||||
Profiler::incrementFrameCounter();
|
||||
#endif
|
||||
|
||||
PROFILE("DynamicsWorld::update()");
|
||||
|
||||
mTimeStep = timeStep;
|
||||
|
||||
// Notify the event listener about the beginning of an internal tick
|
||||
if (mEventListener != NULL) mEventListener->beginInternalTick();
|
||||
|
||||
// Reset all the contact manifolds lists of each body
|
||||
resetContactManifoldListsOfBodies();
|
||||
|
||||
// Compute the collision detection
|
||||
mCollisionDetection.computeCollisionDetection();
|
||||
|
||||
// Compute the islands (separate groups of bodies with constraints between each others)
|
||||
computeIslands();
|
||||
|
||||
// Integrate the velocities
|
||||
integrateRigidBodiesVelocities();
|
||||
|
||||
// Solve the contacts and constraints
|
||||
solveContactsAndConstraints();
|
||||
|
||||
// Integrate the position and orientation of each body
|
||||
integrateRigidBodiesPositions();
|
||||
|
||||
// Solve the position correction for constraints
|
||||
solvePositionCorrection();
|
||||
|
||||
// Update the state (positions and velocities) of the bodies
|
||||
updateBodiesState();
|
||||
|
||||
if (mIsSleepingEnabled) updateSleepingBodies();
|
||||
|
||||
// Notify the event listener about the end of an internal tick
|
||||
if (mEventListener != NULL) mEventListener->endInternalTick();
|
||||
|
||||
// Reset the external force and torque applied to the bodies
|
||||
resetBodiesForceAndTorque();
|
||||
PROFILE("DynamicsWorld::update()");
|
||||
|
||||
mTimeStep = timeStep;
|
||||
|
||||
// Notify the event listener about the beginning of an internal tick
|
||||
if (mEventListener != NULL) {
|
||||
mEventListener->beginInternalTick();
|
||||
}
|
||||
|
||||
// Reset all the contact manifolds lists of each body
|
||||
resetContactManifoldListsOfBodies();
|
||||
|
||||
if (mRigidBodies.size() == 0) {
|
||||
// no rigid body ==> no process to do ...
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute the collision detection
|
||||
mCollisionDetection.computeCollisionDetection();
|
||||
|
||||
// Compute the islands (separate groups of bodies with constraints between each others)
|
||||
computeIslands();
|
||||
|
||||
// Integrate the velocities
|
||||
integrateRigidBodiesVelocities();
|
||||
|
||||
// Solve the contacts and constraints
|
||||
solveContactsAndConstraints();
|
||||
|
||||
// Integrate the position and orientation of each body
|
||||
integrateRigidBodiesPositions();
|
||||
|
||||
// Solve the position correction for constraints
|
||||
solvePositionCorrection();
|
||||
|
||||
// Update the state (positions and velocities) of the bodies
|
||||
updateBodiesState();
|
||||
|
||||
if (mIsSleepingEnabled) updateSleepingBodies();
|
||||
|
||||
// Notify the event listener about the end of an internal tick
|
||||
if (mEventListener != NULL) mEventListener->endInternalTick();
|
||||
|
||||
// Reset the external force and torque applied to the bodies
|
||||
resetBodiesForceAndTorque();
|
||||
}
|
||||
|
||||
// Integrate position and orientation of the rigid bodies.
|
||||
|
@ -169,7 +169,8 @@ def configure(target, my_module):
|
||||
'etk',
|
||||
'ememory'
|
||||
])
|
||||
|
||||
# TODO: Remove this ...
|
||||
my_module.add_flag('c++', "-Wno-overloaded-virtual", export=True)
|
||||
my_module.add_path(".")
|
||||
return True
|
||||
|
||||
|
@ -44,10 +44,10 @@ CubesScene::CubesScene(const std::string& name)
|
||||
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
|
||||
|
||||
// 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
|
||||
mDynamicsWorld->setNbIterationsVelocitySolver(15);
|
||||
m_dynamicsWorld->setNbIterationsVelocitySolver(15);
|
||||
|
||||
float radius = 2.0f;
|
||||
|
||||
@ -61,7 +61,7 @@ CubesScene::CubesScene(const std::string& name)
|
||||
0);
|
||||
|
||||
// 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
|
||||
cube->setColor(mDemoColors[i % mNbDemoColors]);
|
||||
@ -77,7 +77,7 @@ CubesScene::CubesScene(const std::string& name)
|
||||
|
||||
// Create the floor
|
||||
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->setSleepingColor(mGreyColorDemo);
|
||||
|
||||
@ -89,15 +89,15 @@ CubesScene::CubesScene(const std::string& name)
|
||||
material.setBounciness(rp3d::decimal(0.3));
|
||||
|
||||
// Get the physics engine parameters
|
||||
mEngineSettings.isGravityEnabled = mDynamicsWorld->isGravityEnabled();
|
||||
rp3d::Vector3 gravityVector = mDynamicsWorld->getGravity();
|
||||
mEngineSettings.isGravityEnabled = m_dynamicsWorld->isGravityEnabled();
|
||||
rp3d::Vector3 gravityVector = m_dynamicsWorld->getGravity();
|
||||
mEngineSettings.gravity = openglframework::Vector3(gravityVector.x, gravityVector.y, gravityVector.z);
|
||||
mEngineSettings.isSleepingEnabled = mDynamicsWorld->isSleepingEnabled();
|
||||
mEngineSettings.sleepLinearVelocity = mDynamicsWorld->getSleepLinearVelocity();
|
||||
mEngineSettings.sleepAngularVelocity = mDynamicsWorld->getSleepAngularVelocity();
|
||||
mEngineSettings.nbPositionSolverIterations = mDynamicsWorld->getNbIterationsPositionSolver();
|
||||
mEngineSettings.nbVelocitySolverIterations = mDynamicsWorld->getNbIterationsVelocitySolver();
|
||||
mEngineSettings.timeBeforeSleep = mDynamicsWorld->getTimeBeforeSleep();
|
||||
mEngineSettings.isSleepingEnabled = m_dynamicsWorld->isSleepingEnabled();
|
||||
mEngineSettings.sleepLinearVelocity = m_dynamicsWorld->getSleepLinearVelocity();
|
||||
mEngineSettings.sleepAngularVelocity = m_dynamicsWorld->getSleepAngularVelocity();
|
||||
mEngineSettings.nbPositionSolverIterations = m_dynamicsWorld->getNbIterationsPositionSolver();
|
||||
mEngineSettings.nbVelocitySolverIterations = m_dynamicsWorld->getNbIterationsVelocitySolver();
|
||||
mEngineSettings.timeBeforeSleep = m_dynamicsWorld->getTimeBeforeSleep();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@ -107,39 +107,39 @@ CubesScene::~CubesScene() {
|
||||
for (std::vector<Box*>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) {
|
||||
|
||||
// Destroy the corresponding rigid body from the dynamics world
|
||||
mDynamicsWorld->destroyRigidBody((*it)->getRigidBody());
|
||||
m_dynamicsWorld->destroyRigidBody((*it)->getRigidBody());
|
||||
|
||||
// Destroy the cube
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
// Destroy the rigid body of the floor
|
||||
mDynamicsWorld->destroyRigidBody(mFloor->getRigidBody());
|
||||
m_dynamicsWorld->destroyRigidBody(mFloor->getRigidBody());
|
||||
|
||||
// Destroy the floor
|
||||
delete mFloor;
|
||||
|
||||
// Destroy the dynamics world
|
||||
delete mDynamicsWorld;
|
||||
delete m_dynamicsWorld;
|
||||
}
|
||||
|
||||
// Update the physics world (take a simulation step)
|
||||
void CubesScene::updatePhysics() {
|
||||
|
||||
// Update the physics engine parameters
|
||||
mDynamicsWorld->setIsGratityEnabled(mEngineSettings.isGravityEnabled);
|
||||
m_dynamicsWorld->setIsGratityEnabled(mEngineSettings.isGravityEnabled);
|
||||
rp3d::Vector3 gravity(mEngineSettings.gravity.x, mEngineSettings.gravity.y,
|
||||
mEngineSettings.gravity.z);
|
||||
mDynamicsWorld->setGravity(gravity);
|
||||
mDynamicsWorld->enableSleeping(mEngineSettings.isSleepingEnabled);
|
||||
mDynamicsWorld->setSleepLinearVelocity(mEngineSettings.sleepLinearVelocity);
|
||||
mDynamicsWorld->setSleepAngularVelocity(mEngineSettings.sleepAngularVelocity);
|
||||
mDynamicsWorld->setNbIterationsPositionSolver(mEngineSettings.nbPositionSolverIterations);
|
||||
mDynamicsWorld->setNbIterationsVelocitySolver(mEngineSettings.nbVelocitySolverIterations);
|
||||
mDynamicsWorld->setTimeBeforeSleep(mEngineSettings.timeBeforeSleep);
|
||||
m_dynamicsWorld->setGravity(gravity);
|
||||
m_dynamicsWorld->enableSleeping(mEngineSettings.isSleepingEnabled);
|
||||
m_dynamicsWorld->setSleepLinearVelocity(mEngineSettings.sleepLinearVelocity);
|
||||
m_dynamicsWorld->setSleepAngularVelocity(mEngineSettings.sleepAngularVelocity);
|
||||
m_dynamicsWorld->setNbIterationsPositionSolver(mEngineSettings.nbPositionSolverIterations);
|
||||
m_dynamicsWorld->setNbIterationsVelocitySolver(mEngineSettings.nbVelocitySolverIterations);
|
||||
m_dynamicsWorld->setTimeBeforeSleep(mEngineSettings.timeBeforeSleep);
|
||||
|
||||
// Take a simulation step
|
||||
mDynamicsWorld->update(mEngineSettings.timeStep);
|
||||
m_dynamicsWorld->update(mEngineSettings.timeStep);
|
||||
}
|
||||
|
||||
// Update the scene
|
||||
|
@ -33,64 +33,42 @@
|
||||
#include <ephysics/SceneDemo.h>
|
||||
|
||||
namespace cubesscene {
|
||||
|
||||
// Constants
|
||||
const float SCENE_RADIUS = 30.0f; // Radius of the scene in meters
|
||||
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 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions in meters
|
||||
const float BOX_MASS = 1.0f; // Box mass in kilograms
|
||||
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
|
||||
|
||||
// Class CubesScene
|
||||
class CubesScene : public SceneDemo {
|
||||
|
||||
protected :
|
||||
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// All the boxes of the scene
|
||||
std::vector<Box*> mBoxes;
|
||||
|
||||
/// Box for the floor
|
||||
Box* mFloor;
|
||||
|
||||
/// Dynamics world used for the physics simulation
|
||||
rp3d::DynamicsWorld* mDynamicsWorld;
|
||||
|
||||
public:
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
CubesScene(const std::string& name);
|
||||
|
||||
/// Destructor
|
||||
virtual ~CubesScene();
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
// Constants
|
||||
const float SCENE_RADIUS = 30.0f; // Radius of the scene in meters
|
||||
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 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions in meters
|
||||
const float BOX_MASS = 1.0f; // Box mass in kilograms
|
||||
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
|
||||
// Class CubesScene
|
||||
class CubesScene : public SceneDemo {
|
||||
protected :
|
||||
/// All the boxes of the scene
|
||||
std::vector<Box*> mBoxes;
|
||||
/// Box for the floor
|
||||
Box* mFloor;
|
||||
/// Dynamics world used for the physics simulation
|
||||
rp3d::DynamicsWorld* m_dynamicsWorld;
|
||||
public:
|
||||
/// Constructor
|
||||
CubesScene(const std::string& name);
|
||||
/// Destructor
|
||||
virtual ~CubesScene();
|
||||
/// 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 computeContactPointsOfWorld(m_dynamicsWorld);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user