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