Work on the GUI
This commit is contained in:
parent
80cf65ccf2
commit
82f6bf2dbb
|
@ -373,7 +373,7 @@ inline Vector3 DynamicsWorld::getGravity() const {
|
|||
/**
|
||||
* @param gravity The gravity vector (in meter per seconds squared)
|
||||
*/
|
||||
inline Vector3 DynamicsWorld::setGravity(Vector3& gravity) {
|
||||
inline void DynamicsWorld::setGravity(Vector3& gravity) {
|
||||
mGravity = gravity;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,8 @@ void Gui::init() {
|
|||
|
||||
void Gui::displayHeader() {
|
||||
|
||||
TestbedApplication& app = TestbedApplication::getInstance();
|
||||
|
||||
ImVec2 buttonSize(120, 40);
|
||||
|
||||
int display_w, display_h;
|
||||
|
@ -122,10 +124,23 @@ void Gui::displayHeader() {
|
|||
|
||||
ImGui::Begin("Header", NULL, ImVec2(display_w, HEADER_HEIGHT), 1.0f, window_flags);
|
||||
ImGui::SetWindowPos(ImVec2(0, 0));
|
||||
ImGui::Button("Play", buttonSize); ImGui::SameLine();
|
||||
ImGui::Button("Pause", buttonSize); ImGui::SameLine();
|
||||
ImGui::Button("Step", buttonSize); ImGui::SameLine();
|
||||
ImGui::Button("Restart", buttonSize); ImGui::SameLine();
|
||||
|
||||
bool isRunning = app.mTimer.isRunning();
|
||||
if (ImGui::Button(isRunning ? "Pause" : "Play", buttonSize)) {
|
||||
app.togglePlayPauseSimulation();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("Step", buttonSize)) {
|
||||
app.toggleTakeSinglePhysicsStep();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("Restart", buttonSize)) {
|
||||
app.restartSimulation();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::End();
|
||||
|
||||
ImGui::PopStyleColor(1);
|
||||
|
@ -152,8 +167,16 @@ void Gui::displayLeftPane() {
|
|||
ImGui::SetWindowPos(ImVec2(0, HEADER_HEIGHT));
|
||||
|
||||
// ----- Left Pane Header ----- //
|
||||
ImGui::Button("Scenes", buttonSize); ImGui::SameLine();
|
||||
ImGui::Button("Physics", buttonSize); ImGui::SameLine();
|
||||
if (ImGui::Button("Scenes", buttonSize)) {
|
||||
mLeftPane = SCENES;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("Physics", buttonSize)) {
|
||||
mLeftPane = PHYSICS;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::Button("Rendering", buttonSize); ImGui::SameLine();
|
||||
ImGui::Button("Profiling", buttonSize);
|
||||
|
||||
|
@ -194,6 +217,11 @@ void Gui::displayScenesPane() {
|
|||
|
||||
void Gui::displayPhysicsPane() {
|
||||
|
||||
TestbedApplication& app = TestbedApplication::getInstance();
|
||||
|
||||
// Physics time step
|
||||
//float timestep = app.ge;
|
||||
//ImGui::InputFloat("Timestep", ×tep, 0.01f, 1.0f);
|
||||
}
|
||||
|
||||
void Gui::displayRenderingPane() {
|
||||
|
@ -241,10 +269,6 @@ void Gui::render() {
|
|||
//glfwPollEvents();
|
||||
beginNewFrame();
|
||||
|
||||
bool show_test_window = true;
|
||||
bool show_another_window = false;
|
||||
ImVec4 clear_color = ImColor(255, 255, 255);
|
||||
|
||||
displayHeader();
|
||||
displayLeftPane();
|
||||
|
||||
|
|
|
@ -37,6 +37,14 @@ struct EngineSettings {
|
|||
|
||||
float elapsedTime; // Elapsed time (in seconds)
|
||||
float timeStep; // Current time step (in seconds)
|
||||
int nbVelocitySolverIterations; // Nb of velocity solver iterations
|
||||
int nbPositionSolverIterations; // Nb of position solver iterations
|
||||
bool isSleepingEnabled; // True if sleeping technique is enabled
|
||||
float timeBeforeSleep; // Time of inactivity before a body sleep
|
||||
float sleepLinearVelocity; // Sleep linear velocity
|
||||
float sleepAngularVelocity; // Sleep angular velocity
|
||||
bool isGravityEnabled; // True if gravity is enabled
|
||||
openglframework::Vector3 gravity; // Gravity vector
|
||||
|
||||
/// Constructor
|
||||
EngineSettings() : elapsedTime(0.0f), timeStep(0.0f) {
|
||||
|
|
|
@ -57,6 +57,8 @@ TestbedApplication::TestbedApplication() : mFPS(0), mNbFrames(0), mPreviousTime(
|
|||
mIsMultisamplingActive = true;
|
||||
mWidth = 1280;
|
||||
mHeight = 720;
|
||||
mSinglePhysicsStepEnabled = false;
|
||||
mSinglePhysicsStepDone = false;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
|
@ -175,6 +177,13 @@ void TestbedApplication::destroyScenes() {
|
|||
mCurrentScene = NULL;
|
||||
}
|
||||
|
||||
void TestbedApplication::updateSinglePhysicsStep() {
|
||||
|
||||
assert(!mTimer.isRunning());
|
||||
|
||||
mCurrentScene->updatePhysics();
|
||||
}
|
||||
|
||||
// Update the physics of the current scene
|
||||
void TestbedApplication::updatePhysics() {
|
||||
|
||||
|
@ -202,7 +211,13 @@ void TestbedApplication::updatePhysics() {
|
|||
void TestbedApplication::update() {
|
||||
|
||||
// Update the physics
|
||||
if (mSinglePhysicsStepEnabled && !mSinglePhysicsStepDone) {
|
||||
updateSinglePhysicsStep();
|
||||
mSinglePhysicsStepDone = true;
|
||||
}
|
||||
else {
|
||||
updatePhysics();
|
||||
}
|
||||
|
||||
// Compute the interpolation factor
|
||||
float factor = mTimer.computeInterpolationFactor(mEngineSettings.timeStep);
|
||||
|
|
|
@ -81,6 +81,12 @@ class TestbedApplication {
|
|||
/// Width and height of the window
|
||||
int mWidth, mHeight;
|
||||
|
||||
/// True if the next simulation update is a single physics step
|
||||
bool mSinglePhysicsStepEnabled;
|
||||
|
||||
/// True if the single physics step has been taken already
|
||||
bool mSinglePhysicsStepDone;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Private constructor (for the singleton class)
|
||||
|
@ -98,6 +104,9 @@ class TestbedApplication {
|
|||
/// Update
|
||||
void update();
|
||||
|
||||
/// Update the simulation by taking a single physics step
|
||||
void updateSinglePhysicsStep();
|
||||
|
||||
/// Called when the windows is reshaped
|
||||
void reshape();
|
||||
|
||||
|
@ -140,6 +149,15 @@ class TestbedApplication {
|
|||
/// Return the list of the scenes
|
||||
std::vector<Scene*> getScenes();
|
||||
|
||||
/// Start/stop the simulation
|
||||
void togglePlayPauseSimulation();
|
||||
|
||||
/// Restart the simulation
|
||||
void restartSimulation();
|
||||
|
||||
/// Set the variable to know if we need to take a single physics step
|
||||
void toggleTakeSinglePhysicsStep();
|
||||
|
||||
public :
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
@ -169,5 +187,31 @@ inline std::vector<Scene*> TestbedApplication::getScenes() {
|
|||
return mScenes;
|
||||
}
|
||||
|
||||
// Start the simulation
|
||||
inline void TestbedApplication::togglePlayPauseSimulation() {
|
||||
|
||||
if (mTimer.isRunning()) {
|
||||
mTimer.stop();
|
||||
}
|
||||
else {
|
||||
mTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
// Restart the simulation
|
||||
inline void TestbedApplication::restartSimulation() {
|
||||
mCurrentScene->reset();
|
||||
mTimer.start();
|
||||
}
|
||||
|
||||
// Take a single step of simulation
|
||||
inline void TestbedApplication::toggleTakeSinglePhysicsStep() {
|
||||
mSinglePhysicsStepEnabled = true;
|
||||
mSinglePhysicsStepDone = false;
|
||||
|
||||
if (mTimer.isRunning()) {
|
||||
mSinglePhysicsStepEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user