Modify the testbed application so that each scene has it own engine settings
This commit is contained in:
parent
3b90d6d74f
commit
9e3cb9824e
@ -188,6 +188,9 @@ void RagdollScene::reset() {
|
|||||||
// Create the boxes and joints for the ragdoll
|
// Create the boxes and joints for the ragdoll
|
||||||
void RagdollScene::createRagdolls() {
|
void RagdollScene::createRagdolls() {
|
||||||
|
|
||||||
|
const float linearDamping = 0.02f;
|
||||||
|
const float angularDamping = 0.02f;
|
||||||
|
|
||||||
// For each ragdoll
|
// For each ragdoll
|
||||||
for (int i=0; i < NB_RAGDOLLS_ROWS; i++) {
|
for (int i=0; i < NB_RAGDOLLS_ROWS; i++) {
|
||||||
|
|
||||||
@ -208,6 +211,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mHeadBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mHeadBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mHeadBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(7);
|
mHeadBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(7);
|
||||||
mHeadBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mHeadBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mHeadBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mHeadBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mHeadBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mHeadBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the torso box --------------- //
|
// --------------- Create the torso box --------------- //
|
||||||
@ -218,6 +223,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mTorsoBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mTorsoBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mTorsoBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(9);
|
mTorsoBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(9);
|
||||||
mTorsoBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mTorsoBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mTorsoBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mTorsoBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
//mTorsoBox->getRigidBody()->setType(rp3d::BodyType::STATIC);
|
//mTorsoBox->getRigidBody()->setType(rp3d::BodyType::STATIC);
|
||||||
mPhysicsObjects.push_back(mTorsoBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mTorsoBox[ragdollIndex]);
|
||||||
|
|
||||||
@ -229,6 +236,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mLeftUpperArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mLeftUpperArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mLeftUpperArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
mLeftUpperArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
||||||
mLeftUpperArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mLeftUpperArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mLeftUpperArmBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mLeftUpperArmBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mLeftUpperArmBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mLeftUpperArmBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the left lower arm box --------------- //
|
// --------------- Create the left lower arm box --------------- //
|
||||||
@ -239,6 +248,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mLeftLowerArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mLeftLowerArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mLeftLowerArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
mLeftLowerArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
||||||
mLeftLowerArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mLeftLowerArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mLeftLowerArmBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mLeftLowerArmBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mLeftLowerArmBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mLeftLowerArmBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the left upper leg box --------------- //
|
// --------------- Create the left upper leg box --------------- //
|
||||||
@ -249,6 +260,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mLeftUpperLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mLeftUpperLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mLeftUpperLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
mLeftUpperLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
||||||
mLeftUpperLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mLeftUpperLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mLeftUpperLegBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mLeftUpperLegBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mLeftUpperLegBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mLeftUpperLegBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the left lower leg box --------------- //
|
// --------------- Create the left lower leg box --------------- //
|
||||||
@ -259,6 +272,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mLeftLowerLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mLeftLowerLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mLeftLowerLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
mLeftLowerLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
||||||
mLeftLowerLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mLeftLowerLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mLeftLowerLegBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mLeftLowerLegBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mLeftLowerLegBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mLeftLowerLegBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the right upper arm box --------------- //
|
// --------------- Create the right upper arm box --------------- //
|
||||||
@ -269,6 +284,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mRightUpperArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mRightUpperArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mRightUpperArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
mRightUpperArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
||||||
mRightUpperArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mRightUpperArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mRightUpperArmBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mRightUpperArmBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mRightUpperArmBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mRightUpperArmBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the right lower arm box --------------- //
|
// --------------- Create the right lower arm box --------------- //
|
||||||
@ -279,6 +296,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mRightLowerArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mRightLowerArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mRightLowerArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
mRightLowerArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
||||||
mRightLowerArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mRightLowerArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mRightLowerArmBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mRightLowerArmBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mRightLowerArmBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mRightLowerArmBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the right upper leg box --------------- //
|
// --------------- Create the right upper leg box --------------- //
|
||||||
@ -289,6 +308,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mRightUpperLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mRightUpperLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mRightUpperLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
mRightUpperLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
||||||
mRightUpperLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mRightUpperLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mRightUpperLegBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mRightUpperLegBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mRightUpperLegBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mRightUpperLegBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the right lower leg box --------------- //
|
// --------------- Create the right lower leg box --------------- //
|
||||||
@ -299,6 +320,8 @@ void RagdollScene::createRagdolls() {
|
|||||||
mRightLowerLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
mRightLowerLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
|
||||||
mRightLowerLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
mRightLowerLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
|
||||||
mRightLowerLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
mRightLowerLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
|
||||||
|
mRightLowerLegBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
|
||||||
|
mRightLowerLegBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
|
||||||
mPhysicsObjects.push_back(mRightLowerLegBox[ragdollIndex]);
|
mPhysicsObjects.push_back(mRightLowerLegBox[ragdollIndex]);
|
||||||
|
|
||||||
// --------------- Create the joint between head and torso --------------- //
|
// --------------- Create the joint between head and torso --------------- //
|
||||||
|
|||||||
@ -72,6 +72,33 @@ void Gui::init() {
|
|||||||
mTimeSinceLastProfilingDisplay = glfwGetTime();
|
mTimeSinceLastProfilingDisplay = glfwGetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the GUI values with the engine settings from the current scene
|
||||||
|
void Gui::resetWithValuesFromCurrentScene() {
|
||||||
|
|
||||||
|
auto test = mApp->getCurrentSceneEngineSettings();
|
||||||
|
mCheckboxSleeping->set_checked(mApp->getCurrentSceneEngineSettings().isSleepingEnabled);
|
||||||
|
mCheckboxGravity->set_checked(mApp->getCurrentSceneEngineSettings().isGravityEnabled);
|
||||||
|
|
||||||
|
std::ostringstream out;
|
||||||
|
out << std::setprecision(1) << std::fixed << (mApp->getCurrentSceneEngineSettings().timeStep.count() * 1000);
|
||||||
|
mTextboxTimeStep->set_value(out.str());
|
||||||
|
|
||||||
|
mTextboxVelocityIterations->set_value(std::to_string(mApp->getCurrentSceneEngineSettings().nbVelocitySolverIterations));
|
||||||
|
mTextboxPositionIterations->set_value(std::to_string(mApp->getCurrentSceneEngineSettings().nbPositionSolverIterations));
|
||||||
|
|
||||||
|
out.str("");
|
||||||
|
out << std::setprecision(0) << std::fixed << (mApp->getCurrentSceneEngineSettings().timeBeforeSleep * 1000);
|
||||||
|
mTextboxTimeSleep->set_value(out.str());
|
||||||
|
|
||||||
|
out.str("");
|
||||||
|
out << std::setprecision(2) << std::fixed << (mApp->getCurrentSceneEngineSettings().sleepLinearVelocity);
|
||||||
|
mTextboxSleepLinearVel->set_value(out.str());
|
||||||
|
|
||||||
|
out.str("");
|
||||||
|
out << std::setprecision(2) << std::fixed << (mApp->getCurrentSceneEngineSettings().sleepAngularVelocity);
|
||||||
|
mTextboxSleepAngularVel->set_value(out.str());
|
||||||
|
}
|
||||||
|
|
||||||
// Update the GUI
|
// Update the GUI
|
||||||
void Gui::update() {
|
void Gui::update() {
|
||||||
|
|
||||||
@ -177,18 +204,18 @@ void Gui::createSettingsPanel() {
|
|||||||
mPhysicsPanel->set_layout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 0, 5));
|
mPhysicsPanel->set_layout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 0, 5));
|
||||||
|
|
||||||
// Enable/Disable sleeping
|
// Enable/Disable sleeping
|
||||||
CheckBox* checkboxSleeping = new CheckBox(mPhysicsPanel, "Sleeping enabled");
|
mCheckboxSleeping = new CheckBox(mPhysicsPanel, "Sleeping enabled");
|
||||||
checkboxSleeping->set_checked(mApp->mEngineSettings.isSleepingEnabled);
|
mCheckboxSleeping->set_checked(true);
|
||||||
checkboxSleeping->set_callback([&](bool value) {
|
mCheckboxSleeping->set_callback([&](bool value) {
|
||||||
mApp->mEngineSettings.isSleepingEnabled = value;
|
mApp->getCurrentSceneEngineSettings().isSleepingEnabled = value;
|
||||||
mApp->notifyEngineSetttingsChanged();
|
mApp->notifyEngineSetttingsChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Enabled/Disable Gravity
|
// Enabled/Disable Gravity
|
||||||
CheckBox* checkboxGravity = new CheckBox(mPhysicsPanel, "Gravity enabled");
|
mCheckboxGravity = new CheckBox(mPhysicsPanel, "Gravity enabled");
|
||||||
checkboxGravity->set_checked(mApp->mEngineSettings.isGravityEnabled);
|
mCheckboxGravity->set_checked(true);
|
||||||
checkboxGravity->set_callback([&](bool value) {
|
mCheckboxGravity->set_callback([&](bool value) {
|
||||||
mApp->mEngineSettings.isGravityEnabled = value;
|
mApp->getCurrentSceneEngineSettings().isGravityEnabled = value;
|
||||||
mApp->notifyEngineSetttingsChanged();
|
mApp->notifyEngineSetttingsChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -197,14 +224,14 @@ void Gui::createSettingsPanel() {
|
|||||||
panelTimeStep->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
|
panelTimeStep->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
|
||||||
Label* labelTimeStep = new Label(panelTimeStep, "Time step","sans-bold");
|
Label* labelTimeStep = new Label(panelTimeStep, "Time step","sans-bold");
|
||||||
labelTimeStep->set_fixed_width(120);
|
labelTimeStep->set_fixed_width(120);
|
||||||
TextBox* textboxTimeStep = new TextBox(panelTimeStep);
|
mTextboxTimeStep = new TextBox(panelTimeStep);
|
||||||
textboxTimeStep->set_fixed_size(Vector2i(70, 25));
|
mTextboxTimeStep->set_fixed_size(Vector2i(70, 25));
|
||||||
textboxTimeStep->set_editable(true);
|
mTextboxTimeStep->set_editable(true);
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << std::setprecision(1) << std::fixed << (mApp->mEngineSettings.timeStep.count() * 1000);
|
out << std::setprecision(1) << std::fixed << 0;
|
||||||
textboxTimeStep->set_value(out.str());
|
mTextboxTimeStep->set_value(out.str());
|
||||||
textboxTimeStep->set_units("ms");
|
mTextboxTimeStep->set_units("ms");
|
||||||
textboxTimeStep->set_callback([&, textboxTimeStep](const std::string &str) {
|
mTextboxTimeStep->set_callback([&](const std::string &str) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
float value = std::stof(str);
|
float value = std::stof(str);
|
||||||
@ -214,9 +241,9 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
if (finalValue < 1 || finalValue > 1000) return false;
|
if (finalValue < 1 || finalValue > 1000) return false;
|
||||||
|
|
||||||
mApp->mEngineSettings.timeStep = std::chrono::duration<double>(finalValue / 1000.0f);
|
mApp->getCurrentSceneEngineSettings().timeStep = std::chrono::duration<double>(finalValue / 1000.0f);
|
||||||
mApp->notifyEngineSetttingsChanged();
|
mApp->notifyEngineSetttingsChanged();
|
||||||
textboxTimeStep->set_value(out.str());
|
mTextboxTimeStep->set_value(out.str());
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return false;
|
return false;
|
||||||
@ -224,20 +251,20 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
textboxTimeStep->set_font_size(16);
|
mTextboxTimeStep->set_font_size(16);
|
||||||
textboxTimeStep->set_alignment(TextBox::Alignment::Right);
|
mTextboxTimeStep->set_alignment(TextBox::Alignment::Right);
|
||||||
|
|
||||||
// Velocity solver iterations
|
// Velocity solver iterations
|
||||||
Widget* panelVelocityIterations = new Widget(mPhysicsPanel);
|
Widget* panelVelocityIterations = new Widget(mPhysicsPanel);
|
||||||
panelVelocityIterations->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
|
panelVelocityIterations->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
|
||||||
Label* labelVelocityIterations = new Label(panelVelocityIterations, "Velocity solver","sans-bold");
|
Label* labelVelocityIterations = new Label(panelVelocityIterations, "Velocity solver","sans-bold");
|
||||||
labelVelocityIterations->set_fixed_width(120);
|
labelVelocityIterations->set_fixed_width(120);
|
||||||
TextBox* textboxVelocityIterations = new TextBox(panelVelocityIterations);
|
mTextboxVelocityIterations = new TextBox(panelVelocityIterations);
|
||||||
textboxVelocityIterations->set_fixed_size(Vector2i(70, 25));
|
mTextboxVelocityIterations->set_fixed_size(Vector2i(70, 25));
|
||||||
textboxVelocityIterations->set_editable(true);
|
mTextboxVelocityIterations->set_editable(true);
|
||||||
textboxVelocityIterations->set_value(std::to_string(mApp->mEngineSettings.nbVelocitySolverIterations));
|
mTextboxVelocityIterations->set_value(std::to_string(0));
|
||||||
textboxVelocityIterations->set_units("iter");
|
mTextboxVelocityIterations->set_units("iter");
|
||||||
textboxVelocityIterations->set_callback([&, textboxVelocityIterations](const std::string &str) {
|
mTextboxVelocityIterations->set_callback([&](const std::string &str) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
float value = std::stof(str);
|
float value = std::stof(str);
|
||||||
@ -246,9 +273,9 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
if (value < 1 || value > 1000) return false;
|
if (value < 1 || value > 1000) return false;
|
||||||
|
|
||||||
mApp->mEngineSettings.nbVelocitySolverIterations = value;
|
mApp->getCurrentSceneEngineSettings().nbVelocitySolverIterations = value;
|
||||||
mApp->notifyEngineSetttingsChanged();
|
mApp->notifyEngineSetttingsChanged();
|
||||||
textboxVelocityIterations->set_value(out.str());
|
mTextboxVelocityIterations->set_value(out.str());
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return false;
|
return false;
|
||||||
@ -256,20 +283,20 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
textboxVelocityIterations->set_font_size(16);
|
mTextboxVelocityIterations->set_font_size(16);
|
||||||
textboxVelocityIterations->set_alignment(TextBox::Alignment::Right);
|
mTextboxVelocityIterations->set_alignment(TextBox::Alignment::Right);
|
||||||
|
|
||||||
// Position solver iterations
|
// Position solver iterations
|
||||||
Widget* panelPositionIterations = new Widget(mPhysicsPanel);
|
Widget* panelPositionIterations = new Widget(mPhysicsPanel);
|
||||||
panelPositionIterations->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
|
panelPositionIterations->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 5));
|
||||||
Label* labelPositionIterations = new Label(panelPositionIterations, "Position solver","sans-bold");
|
Label* labelPositionIterations = new Label(panelPositionIterations, "Position solver","sans-bold");
|
||||||
labelPositionIterations->set_fixed_width(120);
|
labelPositionIterations->set_fixed_width(120);
|
||||||
TextBox* textboxPositionIterations = new TextBox(panelPositionIterations);
|
mTextboxPositionIterations = new TextBox(panelPositionIterations);
|
||||||
textboxPositionIterations->set_fixed_size(Vector2i(70, 25));
|
mTextboxPositionIterations->set_fixed_size(Vector2i(70, 25));
|
||||||
textboxPositionIterations->set_editable(true);
|
mTextboxPositionIterations->set_editable(true);
|
||||||
textboxPositionIterations->set_value(std::to_string(mApp->mEngineSettings.nbPositionSolverIterations));
|
mTextboxPositionIterations->set_value(std::to_string(0));
|
||||||
textboxPositionIterations->set_units("iter");
|
mTextboxPositionIterations->set_units("iter");
|
||||||
textboxPositionIterations->set_callback([&, textboxPositionIterations](const std::string &str) {
|
mTextboxPositionIterations->set_callback([&](const std::string &str) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
float value = std::stof(str);
|
float value = std::stof(str);
|
||||||
@ -278,9 +305,9 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
if (value < 1 || value > 1000) return false;
|
if (value < 1 || value > 1000) return false;
|
||||||
|
|
||||||
mApp->mEngineSettings.nbPositionSolverIterations = value;
|
mApp->getCurrentSceneEngineSettings().nbPositionSolverIterations = value;
|
||||||
mApp->notifyEngineSetttingsChanged();
|
mApp->notifyEngineSetttingsChanged();
|
||||||
textboxPositionIterations->set_value(out.str());
|
mTextboxPositionIterations->set_value(out.str());
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return false;
|
return false;
|
||||||
@ -288,8 +315,8 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
textboxPositionIterations->set_font_size(16);
|
mTextboxPositionIterations->set_font_size(16);
|
||||||
textboxPositionIterations->set_alignment(TextBox::Alignment::Right);
|
mTextboxPositionIterations->set_alignment(TextBox::Alignment::Right);
|
||||||
|
|
||||||
// Time before sleep
|
// Time before sleep
|
||||||
Widget* panelTimeSleep = new Widget(mPhysicsPanel);
|
Widget* panelTimeSleep = new Widget(mPhysicsPanel);
|
||||||
@ -297,13 +324,13 @@ void Gui::createSettingsPanel() {
|
|||||||
Label* labelTimeSleep = new Label(panelTimeSleep, "Time before sleep","sans-bold");
|
Label* labelTimeSleep = new Label(panelTimeSleep, "Time before sleep","sans-bold");
|
||||||
labelTimeSleep->set_fixed_width(120);
|
labelTimeSleep->set_fixed_width(120);
|
||||||
out.str("");
|
out.str("");
|
||||||
out << std::setprecision(0) << std::fixed << (mApp->mEngineSettings.timeBeforeSleep * 1000);
|
out << std::setprecision(0) << std::fixed << 0;
|
||||||
TextBox* textboxTimeSleep = new TextBox(panelTimeSleep);
|
mTextboxTimeSleep = new TextBox(panelTimeSleep);
|
||||||
textboxTimeSleep->set_fixed_size(Vector2i(70, 25));
|
mTextboxTimeSleep->set_fixed_size(Vector2i(70, 25));
|
||||||
textboxTimeSleep->set_editable(true);
|
mTextboxTimeSleep->set_editable(true);
|
||||||
textboxTimeSleep->set_value(out.str());
|
mTextboxTimeSleep->set_value(out.str());
|
||||||
textboxTimeSleep->set_units("ms");
|
mTextboxTimeSleep->set_units("ms");
|
||||||
textboxTimeSleep->set_callback([&, textboxTimeSleep](const std::string &str) {
|
mTextboxTimeSleep->set_callback([&](const std::string &str) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
float value = std::stof(str);
|
float value = std::stof(str);
|
||||||
@ -313,9 +340,9 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
if (finalValue < 1 || finalValue > 100000) return false;
|
if (finalValue < 1 || finalValue > 100000) return false;
|
||||||
|
|
||||||
mApp->mEngineSettings.timeBeforeSleep = finalValue / 1000.0f;
|
mApp->getCurrentSceneEngineSettings().timeBeforeSleep = finalValue / 1000.0f;
|
||||||
mApp->notifyEngineSetttingsChanged();
|
mApp->notifyEngineSetttingsChanged();
|
||||||
textboxTimeSleep->set_value(out.str());
|
mTextboxTimeSleep->set_value(out.str());
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return false;
|
return false;
|
||||||
@ -323,8 +350,8 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
textboxTimeSleep->set_font_size(16);
|
mTextboxTimeSleep->set_font_size(16);
|
||||||
textboxTimeSleep->set_alignment(TextBox::Alignment::Right);
|
mTextboxTimeSleep->set_alignment(TextBox::Alignment::Right);
|
||||||
|
|
||||||
// Sleep linear velocity
|
// Sleep linear velocity
|
||||||
Widget* panelSleepLinearVel = new Widget(mPhysicsPanel);
|
Widget* panelSleepLinearVel = new Widget(mPhysicsPanel);
|
||||||
@ -332,13 +359,13 @@ void Gui::createSettingsPanel() {
|
|||||||
Label* labelSleepLinearVel = new Label(panelSleepLinearVel, "Sleep linear velocity","sans-bold");
|
Label* labelSleepLinearVel = new Label(panelSleepLinearVel, "Sleep linear velocity","sans-bold");
|
||||||
labelSleepLinearVel->set_fixed_width(120);
|
labelSleepLinearVel->set_fixed_width(120);
|
||||||
out.str("");
|
out.str("");
|
||||||
out << std::setprecision(2) << std::fixed << (mApp->mEngineSettings.sleepLinearVelocity);
|
out << std::setprecision(2) << std::fixed << 0;
|
||||||
TextBox* textboxSleepLinearVel = new TextBox(panelSleepLinearVel);
|
mTextboxSleepLinearVel = new TextBox(panelSleepLinearVel);
|
||||||
textboxSleepLinearVel->set_fixed_size(Vector2i(70, 25));
|
mTextboxSleepLinearVel->set_fixed_size(Vector2i(70, 25));
|
||||||
textboxSleepLinearVel->set_editable(true);
|
mTextboxSleepLinearVel->set_editable(true);
|
||||||
textboxSleepLinearVel->set_value(out.str());
|
mTextboxSleepLinearVel->set_value(out.str());
|
||||||
textboxSleepLinearVel->set_units("m/s");
|
mTextboxSleepLinearVel->set_units("m/s");
|
||||||
textboxSleepLinearVel->set_callback([&, textboxSleepLinearVel](const std::string &str) {
|
mTextboxSleepLinearVel->set_callback([&](const std::string &str) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
float value = std::stof(str);
|
float value = std::stof(str);
|
||||||
@ -348,9 +375,9 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
if (finalValue < 0 || finalValue > 10000) return false;
|
if (finalValue < 0 || finalValue > 10000) return false;
|
||||||
|
|
||||||
mApp->mEngineSettings.sleepLinearVelocity = finalValue;
|
mApp->getCurrentSceneEngineSettings().sleepLinearVelocity = finalValue;
|
||||||
mApp->notifyEngineSetttingsChanged();
|
mApp->notifyEngineSetttingsChanged();
|
||||||
textboxSleepLinearVel->set_value(out.str());
|
mTextboxSleepLinearVel->set_value(out.str());
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return false;
|
return false;
|
||||||
@ -358,8 +385,8 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
textboxSleepLinearVel->set_font_size(16);
|
mTextboxSleepLinearVel->set_font_size(16);
|
||||||
textboxSleepLinearVel->set_alignment(TextBox::Alignment::Right);
|
mTextboxSleepLinearVel->set_alignment(TextBox::Alignment::Right);
|
||||||
|
|
||||||
// Sleep angular velocity
|
// Sleep angular velocity
|
||||||
Widget* panelSleepAngularVel = new Widget(mPhysicsPanel);
|
Widget* panelSleepAngularVel = new Widget(mPhysicsPanel);
|
||||||
@ -367,13 +394,13 @@ void Gui::createSettingsPanel() {
|
|||||||
Label* labelSleepAngularVel = new Label(panelSleepAngularVel, "Sleep angular velocity","sans-bold");
|
Label* labelSleepAngularVel = new Label(panelSleepAngularVel, "Sleep angular velocity","sans-bold");
|
||||||
labelSleepAngularVel->set_fixed_width(120);
|
labelSleepAngularVel->set_fixed_width(120);
|
||||||
out.str("");
|
out.str("");
|
||||||
out << std::setprecision(2) << std::fixed << (mApp->mEngineSettings.sleepAngularVelocity);
|
out << std::setprecision(2) << std::fixed << 0;
|
||||||
TextBox* textboxSleepAngularVel = new TextBox(panelSleepAngularVel);
|
mTextboxSleepAngularVel = new TextBox(panelSleepAngularVel);
|
||||||
textboxSleepAngularVel->set_fixed_size(Vector2i(70, 25));
|
mTextboxSleepAngularVel->set_fixed_size(Vector2i(70, 25));
|
||||||
textboxSleepAngularVel->set_editable(true);
|
mTextboxSleepAngularVel->set_editable(true);
|
||||||
textboxSleepAngularVel->set_value(out.str());
|
mTextboxSleepAngularVel->set_value(out.str());
|
||||||
textboxSleepAngularVel->set_units("rad/s");
|
mTextboxSleepAngularVel->set_units("rad/s");
|
||||||
textboxSleepAngularVel->set_callback([&, textboxSleepAngularVel](const std::string &str) {
|
mTextboxSleepAngularVel->set_callback([&](const std::string &str) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
float value = std::stof(str);
|
float value = std::stof(str);
|
||||||
@ -383,9 +410,9 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
if (finalValue < 0 || finalValue > 10000) return false;
|
if (finalValue < 0 || finalValue > 10000) return false;
|
||||||
|
|
||||||
mApp->mEngineSettings.sleepAngularVelocity = finalValue;
|
mApp->getCurrentSceneEngineSettings().sleepAngularVelocity = finalValue;
|
||||||
mApp->notifyEngineSetttingsChanged();
|
mApp->notifyEngineSetttingsChanged();
|
||||||
textboxSleepAngularVel->set_value(out.str());
|
mTextboxSleepAngularVel->set_value(out.str());
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return false;
|
return false;
|
||||||
@ -393,8 +420,8 @@ void Gui::createSettingsPanel() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
textboxSleepAngularVel->set_font_size(16);
|
mTextboxSleepAngularVel->set_font_size(16);
|
||||||
textboxSleepAngularVel->set_alignment(TextBox::Alignment::Right);
|
mTextboxSleepAngularVel->set_alignment(TextBox::Alignment::Right);
|
||||||
|
|
||||||
// ---------- Rendering Panel ----------
|
// ---------- Rendering Panel ----------
|
||||||
mRenderingPanel = new Widget(mSettingsPanel);
|
mRenderingPanel = new Widget(mSettingsPanel);
|
||||||
|
|||||||
@ -72,6 +72,15 @@ class Gui {
|
|||||||
Label* mTotalPhysicsTimeLabel;
|
Label* mTotalPhysicsTimeLabel;
|
||||||
Label* mPhysicsStepTimeLabel;
|
Label* mPhysicsStepTimeLabel;
|
||||||
|
|
||||||
|
CheckBox* mCheckboxSleeping;
|
||||||
|
CheckBox* mCheckboxGravity;
|
||||||
|
TextBox* mTextboxTimeStep;
|
||||||
|
TextBox* mTextboxVelocityIterations;
|
||||||
|
TextBox* mTextboxPositionIterations;
|
||||||
|
TextBox* mTextboxTimeSleep;
|
||||||
|
TextBox* mTextboxSleepLinearVel;
|
||||||
|
TextBox* mTextboxSleepAngularVel;
|
||||||
|
|
||||||
std::vector<CheckBox*> mCheckboxesScenes;
|
std::vector<CheckBox*> mCheckboxesScenes;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
@ -123,6 +132,9 @@ class Gui {
|
|||||||
/// Display the GUI
|
/// Display the GUI
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
/// Update the GUI values with the engine settings from the current scene
|
||||||
|
void resetWithValuesFromCurrentScene();
|
||||||
|
|
||||||
static void setScroll(double scrollX, double scrollY);
|
static void setScroll(double scrollX, double scrollY);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -100,7 +100,7 @@ class Scene : public rp3d::EventListener {
|
|||||||
std::string mName;
|
std::string mName;
|
||||||
|
|
||||||
/// Physics engine settings
|
/// Physics engine settings
|
||||||
EngineSettings& mEngineSettings;
|
EngineSettings mEngineSettings;
|
||||||
|
|
||||||
/// Camera
|
/// Camera
|
||||||
openglframework::Camera mCamera;
|
openglframework::Camera mCamera;
|
||||||
@ -257,6 +257,9 @@ class Scene : public rp3d::EventListener {
|
|||||||
|
|
||||||
/// Update the engine settings
|
/// Update the engine settings
|
||||||
virtual void updateEngineSettings() = 0;
|
virtual void updateEngineSettings() = 0;
|
||||||
|
|
||||||
|
/// Return a reference to the engine settings of the scene
|
||||||
|
EngineSettings& getEngineSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Called when a keyboard event occurs
|
// Called when a keyboard event occurs
|
||||||
@ -348,4 +351,9 @@ inline void Scene::setIsWireframeEnabled(bool isEnabled) {
|
|||||||
mIsWireframeEnabled = isEnabled;
|
mIsWireframeEnabled = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a reference to the engine settings of the scene
|
||||||
|
inline EngineSettings& Scene::getEngineSettings() {
|
||||||
|
return mEngineSettings;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -685,18 +685,15 @@ rp3d::decimal SceneDemo::notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo)
|
|||||||
// Update the engine settings
|
// Update the engine settings
|
||||||
void SceneDemo::updateEngineSettings() {
|
void SceneDemo::updateEngineSettings() {
|
||||||
|
|
||||||
if (mIsPhysicsWorldSimulated) {
|
// Update the physics engine parameters
|
||||||
|
mPhysicsWorld->setIsGravityEnabled(mEngineSettings.isGravityEnabled);
|
||||||
// Update the physics engine parameters
|
rp3d::Vector3 gravity(mEngineSettings.gravity.x, mEngineSettings.gravity.y,
|
||||||
mPhysicsWorld->setIsGravityEnabled(mEngineSettings.isGravityEnabled);
|
mEngineSettings.gravity.z);
|
||||||
rp3d::Vector3 gravity(mEngineSettings.gravity.x, mEngineSettings.gravity.y,
|
mPhysicsWorld->setGravity(gravity);
|
||||||
mEngineSettings.gravity.z);
|
mPhysicsWorld->enableSleeping(mEngineSettings.isSleepingEnabled);
|
||||||
mPhysicsWorld->setGravity(gravity);
|
mPhysicsWorld->setSleepLinearVelocity(mEngineSettings.sleepLinearVelocity);
|
||||||
mPhysicsWorld->enableSleeping(mEngineSettings.isSleepingEnabled);
|
mPhysicsWorld->setSleepAngularVelocity(mEngineSettings.sleepAngularVelocity);
|
||||||
mPhysicsWorld->setSleepLinearVelocity(mEngineSettings.sleepLinearVelocity);
|
mPhysicsWorld->setNbIterationsPositionSolver(mEngineSettings.nbPositionSolverIterations);
|
||||||
mPhysicsWorld->setSleepAngularVelocity(mEngineSettings.sleepAngularVelocity);
|
mPhysicsWorld->setNbIterationsVelocitySolver(mEngineSettings.nbVelocitySolverIterations);
|
||||||
mPhysicsWorld->setNbIterationsPositionSolver(mEngineSettings.nbPositionSolverIterations);
|
mPhysicsWorld->setTimeBeforeSleep(mEngineSettings.timeBeforeSleep);
|
||||||
mPhysicsWorld->setNbIterationsVelocitySolver(mEngineSettings.nbVelocitySolverIterations);
|
|
||||||
mPhysicsWorld->setTimeBeforeSleep(mEngineSettings.timeBeforeSleep);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,6 +48,7 @@
|
|||||||
#include "hingejoint/HingeJointScene.h"
|
#include "hingejoint/HingeJointScene.h"
|
||||||
#include "sliderjoint/SliderJointScene.h"
|
#include "sliderjoint/SliderJointScene.h"
|
||||||
#include "ragdoll/RagdollScene.h"
|
#include "ragdoll/RagdollScene.h"
|
||||||
|
#include "rope/RopeScene.h"
|
||||||
|
|
||||||
using namespace openglframework;
|
using namespace openglframework;
|
||||||
using namespace jointsscene;
|
using namespace jointsscene;
|
||||||
@ -69,6 +70,7 @@ using namespace ballandsocketjointscene;
|
|||||||
using namespace hingejointscene;
|
using namespace hingejointscene;
|
||||||
using namespace sliderjointscene;
|
using namespace sliderjointscene;
|
||||||
using namespace ragdollscene;
|
using namespace ragdollscene;
|
||||||
|
using namespace ropescene;
|
||||||
|
|
||||||
// Initialization of static variables
|
// Initialization of static variables
|
||||||
const float TestbedApplication::SCROLL_SENSITIVITY = 0.08f;
|
const float TestbedApplication::SCROLL_SENSITIVITY = 0.08f;
|
||||||
@ -77,7 +79,7 @@ const float TestbedApplication::SCROLL_SENSITIVITY = 0.08f;
|
|||||||
TestbedApplication::TestbedApplication(bool isFullscreen, int windowWidth, int windowHeight)
|
TestbedApplication::TestbedApplication(bool isFullscreen, int windowWidth, int windowHeight)
|
||||||
: Screen(Vector2i(windowWidth, windowHeight), "Testbed ReactPhysics3D v" + rp3d::RP3D_VERSION, true, isFullscreen, true, true, false, 4, 1),
|
: Screen(Vector2i(windowWidth, windowHeight), "Testbed ReactPhysics3D v" + rp3d::RP3D_VERSION, true, isFullscreen, true, true, false, 4, 1),
|
||||||
mIsInitialized(false), mGui(this), mCurrentScene(nullptr),
|
mIsInitialized(false), mGui(this), mCurrentScene(nullptr),
|
||||||
mEngineSettings(EngineSettings::defaultSettings()),
|
mDefaultEngineSettings(EngineSettings::defaultSettings()),
|
||||||
mFPS(0), mNbFrames(0), mPreviousTime(0),
|
mFPS(0), mNbFrames(0), mPreviousTime(0),
|
||||||
mLastTimeComputedFPS(0), mFrameTime(0), mTotalPhysicsTime(0), mPhysicsStepTime(0),
|
mLastTimeComputedFPS(0), mFrameTime(0), mTotalPhysicsTime(0), mPhysicsStepTime(0),
|
||||||
mWidth(windowWidth), mHeight(windowHeight),
|
mWidth(windowWidth), mHeight(windowHeight),
|
||||||
@ -109,6 +111,10 @@ void TestbedApplication::init() {
|
|||||||
// Initialize the GUI
|
// Initialize the GUI
|
||||||
mGui.init();
|
mGui.init();
|
||||||
|
|
||||||
|
// Select the initial scene
|
||||||
|
const int firstSceneIndex = 0;
|
||||||
|
switchScene(mScenes[firstSceneIndex]);
|
||||||
|
|
||||||
mTimer.start();
|
mTimer.start();
|
||||||
|
|
||||||
int glMajorVersion, glMinorVersion;
|
int glMajorVersion, glMinorVersion;
|
||||||
@ -132,86 +138,85 @@ void TestbedApplication::init() {
|
|||||||
void TestbedApplication::createScenes() {
|
void TestbedApplication::createScenes() {
|
||||||
|
|
||||||
// Cubes scene
|
// Cubes scene
|
||||||
CubesScene* cubeScene = new CubesScene("Cubes", mEngineSettings);
|
CubesScene* cubeScene = new CubesScene("Cubes", mDefaultEngineSettings);
|
||||||
mScenes.push_back(cubeScene);
|
mScenes.push_back(cubeScene);
|
||||||
|
|
||||||
// Cube Stack scene
|
// Cube Stack scene
|
||||||
CubeStackScene* cubeStackScene = new CubeStackScene("Cube Stack", mEngineSettings);
|
CubeStackScene* cubeStackScene = new CubeStackScene("Cube Stack", mDefaultEngineSettings);
|
||||||
mScenes.push_back(cubeStackScene);
|
mScenes.push_back(cubeStackScene);
|
||||||
|
|
||||||
// Joints scene
|
// Joints scene
|
||||||
JointsScene* jointsScene = new JointsScene("Joints", mEngineSettings);
|
JointsScene* jointsScene = new JointsScene("Joints", mDefaultEngineSettings);
|
||||||
mScenes.push_back(jointsScene);
|
mScenes.push_back(jointsScene);
|
||||||
|
|
||||||
// Collision shapes scene
|
// Collision shapes scene
|
||||||
CollisionShapesScene* collisionShapesScene = new CollisionShapesScene("Collision Shapes", mEngineSettings);
|
CollisionShapesScene* collisionShapesScene = new CollisionShapesScene("Collision Shapes", mDefaultEngineSettings);
|
||||||
mScenes.push_back(collisionShapesScene);
|
mScenes.push_back(collisionShapesScene);
|
||||||
|
|
||||||
// Heightfield shape scene
|
// Heightfield shape scene
|
||||||
HeightFieldScene* heightFieldScene = new HeightFieldScene("Heightfield", mEngineSettings);
|
HeightFieldScene* heightFieldScene = new HeightFieldScene("Heightfield", mDefaultEngineSettings);
|
||||||
mScenes.push_back(heightFieldScene);
|
mScenes.push_back(heightFieldScene);
|
||||||
|
|
||||||
// Raycast scene
|
// Raycast scene
|
||||||
RaycastScene* raycastScene = new RaycastScene("Raycast", mEngineSettings);
|
RaycastScene* raycastScene = new RaycastScene("Raycast", mDefaultEngineSettings);
|
||||||
mScenes.push_back(raycastScene);
|
mScenes.push_back(raycastScene);
|
||||||
|
|
||||||
// Collision Detection scene
|
// Collision Detection scene
|
||||||
CollisionDetectionScene* collisionDetectionScene = new CollisionDetectionScene("Collision Detection", mEngineSettings);
|
CollisionDetectionScene* collisionDetectionScene = new CollisionDetectionScene("Collision Detection", mDefaultEngineSettings);
|
||||||
mScenes.push_back(collisionDetectionScene);
|
mScenes.push_back(collisionDetectionScene);
|
||||||
|
|
||||||
// Concave Mesh scene
|
// Concave Mesh scene
|
||||||
ConcaveMeshScene* concaveMeshScene = new ConcaveMeshScene("Concave Mesh", mEngineSettings);
|
ConcaveMeshScene* concaveMeshScene = new ConcaveMeshScene("Concave Mesh", mDefaultEngineSettings);
|
||||||
mScenes.push_back(concaveMeshScene);
|
mScenes.push_back(concaveMeshScene);
|
||||||
|
|
||||||
// Pile scene
|
// Pile scene
|
||||||
PileScene* pileScene = new PileScene("Pile", mEngineSettings);
|
PileScene* pileScene = new PileScene("Pile", mDefaultEngineSettings);
|
||||||
mScenes.push_back(pileScene);
|
mScenes.push_back(pileScene);
|
||||||
|
|
||||||
// Box Tower scene
|
// Box Tower scene
|
||||||
BoxTowerScene* boxTowerScene = new BoxTowerScene("Box Tower", mEngineSettings);
|
BoxTowerScene* boxTowerScene = new BoxTowerScene("Box Tower", mDefaultEngineSettings);
|
||||||
mScenes.push_back(boxTowerScene);
|
mScenes.push_back(boxTowerScene);
|
||||||
|
|
||||||
// Ball and Socket joints Net scene
|
// Ball and Socket joints Net scene
|
||||||
BallAndSocketJointsNetScene* ballAndSocketJointsNetScene = new BallAndSocketJointsNetScene("BallAndSocket Joints Net", mEngineSettings);
|
BallAndSocketJointsNetScene* ballAndSocketJointsNetScene = new BallAndSocketJointsNetScene("BallAndSocket Joints Net", mDefaultEngineSettings);
|
||||||
mScenes.push_back(ballAndSocketJointsNetScene);
|
mScenes.push_back(ballAndSocketJointsNetScene);
|
||||||
|
|
||||||
// Ball and Socket joints chain scene
|
// Ball and Socket joints chain scene
|
||||||
BallAndSocketJointsChainScene* ballAndSocketJointsChainScene = new BallAndSocketJointsChainScene("BallAndSocket Joints Chain", mEngineSettings);
|
BallAndSocketJointsChainScene* ballAndSocketJointsChainScene = new BallAndSocketJointsChainScene("BallAndSocket Joints Chain", mDefaultEngineSettings);
|
||||||
mScenes.push_back(ballAndSocketJointsChainScene);
|
mScenes.push_back(ballAndSocketJointsChainScene);
|
||||||
|
|
||||||
// Hinge joints chain scene
|
// Hinge joints chain scene
|
||||||
HingeJointsChainScene* hingeJointsChainScene = new HingeJointsChainScene("Hinge Joints Chain", mEngineSettings);
|
HingeJointsChainScene* hingeJointsChainScene = new HingeJointsChainScene("Hinge Joints Chain", mDefaultEngineSettings);
|
||||||
mScenes.push_back(hingeJointsChainScene);
|
mScenes.push_back(hingeJointsChainScene);
|
||||||
|
|
||||||
// Bridge scene
|
// Bridge scene
|
||||||
BridgeScene* bridgeScene = new BridgeScene("Bridge", mEngineSettings);
|
BridgeScene* bridgeScene = new BridgeScene("Bridge", mDefaultEngineSettings);
|
||||||
mScenes.push_back(bridgeScene);
|
mScenes.push_back(bridgeScene);
|
||||||
|
|
||||||
// Fixed joint scene
|
// Fixed joint scene
|
||||||
FixedJointScene* fixedJointScene = new FixedJointScene("Fixed joint", mEngineSettings);
|
FixedJointScene* fixedJointScene = new FixedJointScene("Fixed joint", mDefaultEngineSettings);
|
||||||
mScenes.push_back(fixedJointScene);
|
mScenes.push_back(fixedJointScene);
|
||||||
|
|
||||||
// Ball and Socket joint scene
|
// Ball and Socket joint scene
|
||||||
BallAndSocketJointScene* ballAndSocketJointScene = new BallAndSocketJointScene("Ball and Socket joint", mEngineSettings);
|
BallAndSocketJointScene* ballAndSocketJointScene = new BallAndSocketJointScene("Ball and Socket joint", mDefaultEngineSettings);
|
||||||
mScenes.push_back(ballAndSocketJointScene);
|
mScenes.push_back(ballAndSocketJointScene);
|
||||||
|
|
||||||
// Hinge joint scene
|
// Hinge joint scene
|
||||||
HingeJointScene* hingeJointScene = new HingeJointScene("Hinge joint", mEngineSettings);
|
HingeJointScene* hingeJointScene = new HingeJointScene("Hinge joint", mDefaultEngineSettings);
|
||||||
mScenes.push_back(hingeJointScene);
|
mScenes.push_back(hingeJointScene);
|
||||||
|
|
||||||
// Slider joint scene
|
// Slider joint scene
|
||||||
SliderJointScene* sliderJointScene = new SliderJointScene("Slider joint", mEngineSettings);
|
SliderJointScene* sliderJointScene = new SliderJointScene("Slider joint", mDefaultEngineSettings);
|
||||||
mScenes.push_back(sliderJointScene);
|
mScenes.push_back(sliderJointScene);
|
||||||
|
|
||||||
// Ragdoll scene
|
// Ragdoll scene
|
||||||
RagdollScene* ragdollScene = new RagdollScene("Ragdoll", mEngineSettings);
|
RagdollScene* ragdollScene = new RagdollScene("Ragdoll", mDefaultEngineSettings);
|
||||||
mScenes.push_back(ragdollScene);
|
mScenes.push_back(ragdollScene);
|
||||||
|
|
||||||
|
// Rope scene
|
||||||
|
RopeScene* ropeScene = new RopeScene("Rope", mDefaultEngineSettings);
|
||||||
|
mScenes.push_back(ropeScene);
|
||||||
assert(mScenes.size() > 0);
|
assert(mScenes.size() > 0);
|
||||||
|
|
||||||
const int firstSceneIndex = 0;
|
|
||||||
|
|
||||||
switchScene(mScenes[firstSceneIndex]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all the scenes
|
// Remove all the scenes
|
||||||
@ -235,7 +240,7 @@ void TestbedApplication::updateSinglePhysicsStep() {
|
|||||||
void TestbedApplication::updatePhysics() {
|
void TestbedApplication::updatePhysics() {
|
||||||
|
|
||||||
// Update the elapsed time
|
// Update the elapsed time
|
||||||
mEngineSettings.elapsedTime = mTimer.getElapsedPhysicsTime();
|
mCurrentScene->getEngineSettings().elapsedTime = mTimer.getElapsedPhysicsTime();
|
||||||
|
|
||||||
if (mTimer.isRunning()) {
|
if (mTimer.isRunning()) {
|
||||||
|
|
||||||
@ -243,7 +248,7 @@ void TestbedApplication::updatePhysics() {
|
|||||||
mTimer.update();
|
mTimer.update();
|
||||||
|
|
||||||
// While the time accumulator is not empty
|
// While the time accumulator is not empty
|
||||||
while(mTimer.isPossibleToTakeStep(mEngineSettings.timeStep)) {
|
while(mTimer.isPossibleToTakeStep(mCurrentScene->getEngineSettings().timeStep)) {
|
||||||
|
|
||||||
double currentTime = glfwGetTime();
|
double currentTime = glfwGetTime();
|
||||||
|
|
||||||
@ -253,7 +258,7 @@ void TestbedApplication::updatePhysics() {
|
|||||||
mPhysicsStepTime = glfwGetTime() - currentTime;
|
mPhysicsStepTime = glfwGetTime() - currentTime;
|
||||||
|
|
||||||
// Update the timer
|
// Update the timer
|
||||||
mTimer.nextStep(mEngineSettings.timeStep);
|
mTimer.nextStep(mCurrentScene->getEngineSettings().timeStep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,7 +282,7 @@ void TestbedApplication::update() {
|
|||||||
mTotalPhysicsTime = glfwGetTime() - currentTime;
|
mTotalPhysicsTime = glfwGetTime() - currentTime;
|
||||||
|
|
||||||
// Compute the interpolation factor
|
// Compute the interpolation factor
|
||||||
float factor = mTimer.computeInterpolationFactor(mEngineSettings.timeStep);
|
float factor = mTimer.computeInterpolationFactor(mDefaultEngineSettings.timeStep);
|
||||||
assert(factor >= 0.0f && factor <= 1.0f);
|
assert(factor >= 0.0f && factor <= 1.0f);
|
||||||
|
|
||||||
// Notify the scene about the interpolation factor
|
// Notify the scene about the interpolation factor
|
||||||
@ -358,6 +363,7 @@ void TestbedApplication::switchScene(Scene* newScene) {
|
|||||||
// Reset the scene
|
// Reset the scene
|
||||||
mCurrentScene->reset();
|
mCurrentScene->reset();
|
||||||
|
|
||||||
|
mGui.resetWithValuesFromCurrentScene();
|
||||||
mCurrentScene->updateEngineSettings();
|
mCurrentScene->updateEngineSettings();
|
||||||
|
|
||||||
resize_event(Vector2i(0, 0));
|
resize_event(Vector2i(0, 0));
|
||||||
|
|||||||
@ -62,8 +62,8 @@ class TestbedApplication : public Screen {
|
|||||||
/// Current 3D scene
|
/// Current 3D scene
|
||||||
Scene* mCurrentScene;
|
Scene* mCurrentScene;
|
||||||
|
|
||||||
/// Physics engine settings
|
/// Physics engine default settings
|
||||||
EngineSettings mEngineSettings;
|
EngineSettings mDefaultEngineSettings;
|
||||||
|
|
||||||
/// Current number of frames per seconds
|
/// Current number of frames per seconds
|
||||||
double mFPS;
|
double mFPS;
|
||||||
@ -171,6 +171,9 @@ class TestbedApplication : public Screen {
|
|||||||
/// Set the variable to know if we need to take a single physics step
|
/// Set the variable to know if we need to take a single physics step
|
||||||
void toggleTakeSinglePhysicsStep();
|
void toggleTakeSinglePhysicsStep();
|
||||||
|
|
||||||
|
/// Return the engine settings of the current scene
|
||||||
|
EngineSettings& getCurrentSceneEngineSettings();
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
@ -273,4 +276,9 @@ inline void TestbedApplication::enableVSync(bool enable) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the engine settings of the current scene
|
||||||
|
inline EngineSettings& TestbedApplication::getCurrentSceneEngineSettings() {
|
||||||
|
return mCurrentScene->getEngineSettings();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user