2015-04-08 18:47:55 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
|
|
|
* Copyright (c) 2010-2015 Daniel Chappuis *
|
|
|
|
*********************************************************************************
|
|
|
|
* *
|
|
|
|
* This software is provided 'as-is', without any express or implied warranty. *
|
|
|
|
* In no event will the authors be held liable for any damages arising from the *
|
|
|
|
* use of this software. *
|
|
|
|
* *
|
|
|
|
* Permission is granted to anyone to use this software for any purpose, *
|
|
|
|
* including commercial applications, and to alter it and redistribute it *
|
|
|
|
* freely, subject to the following restrictions: *
|
|
|
|
* *
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not claim *
|
|
|
|
* that you wrote the original software. If you use this software in a *
|
|
|
|
* product, an acknowledgment in the product documentation would be *
|
|
|
|
* appreciated but is not required. *
|
|
|
|
* *
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be *
|
|
|
|
* misrepresented as being the original software. *
|
|
|
|
* *
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution. *
|
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
// Libraries
|
|
|
|
#include "Gui.h"
|
2015-04-28 21:47:29 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2015-08-06 19:06:35 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
2015-06-01 21:40:44 +00:00
|
|
|
#include "TestbedApplication.h"
|
2015-04-28 21:47:29 +00:00
|
|
|
|
|
|
|
GLFWwindow* Gui::mWindow = NULL;
|
|
|
|
double Gui::g_Time = 0.0f;
|
|
|
|
bool Gui::g_MousePressed[3] = {false, false, false};
|
|
|
|
float Gui::g_MouseWheel = 0.0f;
|
|
|
|
GLuint Gui::g_FontTexture = 0;
|
|
|
|
size_t Gui::g_VboSize = 0;
|
2015-05-24 15:23:55 +00:00
|
|
|
int Gui::g_AttribLocationTex = 0, Gui::g_AttribLocationProjMtx = 0;
|
|
|
|
int Gui::g_AttribLocationPosition = 0, Gui::g_AttribLocationUV = 0, Gui::g_AttribLocationColor = 0;
|
|
|
|
Shader Gui::mShader;
|
2015-06-01 21:40:44 +00:00
|
|
|
openglframework::VertexBufferObject Gui::mVBO(GL_ARRAY_BUFFER);
|
|
|
|
openglframework::VertexArrayObject Gui::mVAO;
|
|
|
|
Gui::LeftPane Gui::mLeftPane = SCENES;
|
2015-07-11 16:35:58 +00:00
|
|
|
double Gui::mScrollX = 0.0;
|
|
|
|
double Gui::mScrollY = 0.0;
|
2015-08-06 19:06:35 +00:00
|
|
|
double Gui::mTimeSinceLastProfilingDisplay = 0;
|
|
|
|
double Gui::mCachedFPS = 0;
|
|
|
|
double Gui::mCachedUpdateTime = 0;
|
|
|
|
double Gui::mCachedPhysicsUpdateTime = 0;
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-04-15 21:11:27 +00:00
|
|
|
// Constructor
|
|
|
|
Gui::Gui() {
|
2015-06-01 21:40:44 +00:00
|
|
|
|
2015-04-28 21:47:29 +00:00
|
|
|
g_Time = 0.0f;
|
|
|
|
g_MousePressed[0] = false;
|
|
|
|
g_MousePressed[1] = false;
|
|
|
|
g_MousePressed[2] = false;
|
|
|
|
g_MouseWheel = 0.0f;
|
|
|
|
g_FontTexture = 0;
|
|
|
|
g_VboSize = 0;
|
2015-04-15 21:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
Gui::~Gui() {
|
|
|
|
|
2015-06-01 21:40:44 +00:00
|
|
|
mVAO.destroy();
|
|
|
|
mVBO.destroy();
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-05-24 15:23:55 +00:00
|
|
|
mShader.destroy();
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
imguiRenderGLDestroy();
|
2015-04-28 21:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create and return the singleton instance of this class
|
|
|
|
Gui& Gui::getInstance() {
|
|
|
|
static Gui instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initialize the GUI
|
|
|
|
void Gui::init() {
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Init UI
|
|
|
|
if (!imguiRenderGLInit("DroidSans.ttf")) {
|
|
|
|
fprintf(stderr, "Could not init GUI renderer.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-06-30 17:50:17 +00:00
|
|
|
|
2015-08-06 19:06:35 +00:00
|
|
|
mTimeSinceLastProfilingDisplay = glfwGetTime();
|
2015-06-01 21:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::displayLeftPane() {
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
TestbedApplication& app = TestbedApplication::getInstance();
|
2015-06-01 21:40:44 +00:00
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
const float scalingX = app.mWindowToFramebufferRatio.x;
|
|
|
|
const float scalingY = app.mWindowToFramebufferRatio.y;
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
int windowWidth, windowHeight;
|
|
|
|
glfwGetWindowSize(mWindow, &windowWidth, &windowHeight);
|
2015-06-01 21:40:44 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
int scrollarea = 0;
|
2015-08-06 19:06:35 +00:00
|
|
|
imguiBeginScrollArea(NULL, 0, app.mWindowToFramebufferRatio.y * (windowHeight - LEFT_PANE_HEADER_HEIGHT),
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
|
|
|
app.mWindowToFramebufferRatio.y * LEFT_PANE_HEADER_HEIGHT, &scrollarea);
|
2015-06-30 17:50:17 +00:00
|
|
|
|
2015-07-31 19:54:02 +00:00
|
|
|
// ------ Header ----- //
|
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiHorizontalSpace(scalingX * 2.5);
|
|
|
|
imguiVerticalSpace(scalingY * 5);
|
2015-07-31 19:54:02 +00:00
|
|
|
imguiStartLine();
|
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
const int button_width = app.mWindowToFramebufferRatio.x * 75.0f;
|
|
|
|
const int button_height = app.mWindowToFramebufferRatio.y * 20.0f;
|
2015-07-31 19:54:02 +00:00
|
|
|
|
|
|
|
// Play/Pause
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiButton(app.mTimer.isRunning() ? "Pause" : "Play", true, button_width, button_height, scalingX, scalingY)) {
|
2015-07-31 19:54:02 +00:00
|
|
|
app.togglePlayPauseSimulation();
|
|
|
|
}
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiHorizontalSpace(scalingX * 2.5);
|
2015-07-31 19:54:02 +00:00
|
|
|
|
|
|
|
// Step
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiButton("Step", !app.mTimer.isRunning(), button_width, button_height, scalingX, scalingY)) {
|
2015-07-31 19:54:02 +00:00
|
|
|
app.toggleTakeSinglePhysicsStep();
|
|
|
|
}
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiHorizontalSpace(scalingX * 2.5);
|
2015-07-31 19:54:02 +00:00
|
|
|
|
|
|
|
// Restart
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiButton("Restart", true, button_width, button_height, scalingX, scalingY)) {
|
2015-07-31 19:54:02 +00:00
|
|
|
app.restartSimulation();
|
|
|
|
}
|
|
|
|
|
|
|
|
imguiEndLine();
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiVerticalSpace(scalingY * 35);
|
2015-07-31 19:54:02 +00:00
|
|
|
|
2015-07-11 22:05:49 +00:00
|
|
|
imguiSeparatorLine();
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiVerticalSpace(scalingY * 2.5);
|
2015-07-11 22:05:49 +00:00
|
|
|
imguiStartLine();
|
2015-06-01 21:40:44 +00:00
|
|
|
|
2015-07-31 19:54:02 +00:00
|
|
|
// ----- Left Pane Tabs ----- //
|
|
|
|
|
2015-07-11 22:05:49 +00:00
|
|
|
int widthButton = app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH / 4.3;
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiButton("Scenes", true, widthButton, button_height, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
mLeftPane = SCENES;
|
|
|
|
}
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiHorizontalSpace(scalingX * 2.5);
|
2015-06-01 21:40:44 +00:00
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiButton("Physics", true, widthButton, button_height, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
mLeftPane = PHYSICS;
|
|
|
|
}
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiHorizontalSpace(scalingX * 2.5);
|
2015-06-01 21:40:44 +00:00
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiButton("Rendering", true, widthButton, button_height, scalingX, scalingY)) {
|
2015-08-06 19:06:35 +00:00
|
|
|
mLeftPane = RENDERING;
|
|
|
|
}
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiHorizontalSpace(scalingX * 2.5);
|
2015-07-11 22:05:49 +00:00
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiButton("Profiling", true, widthButton, button_height, scalingX, scalingY)) {
|
2015-08-06 19:06:35 +00:00
|
|
|
mLeftPane = PROFILING;
|
|
|
|
}
|
2015-07-11 22:05:49 +00:00
|
|
|
|
|
|
|
imguiEndLine();
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiVerticalSpace(scalingY * (BUTTON_HEIGHT/2 + 15));
|
2015-07-11 22:05:49 +00:00
|
|
|
imguiSeparatorLine();
|
2015-07-11 16:35:58 +00:00
|
|
|
imguiEndScrollArea();
|
|
|
|
|
|
|
|
// Display the left pane content
|
|
|
|
switch(mLeftPane) {
|
|
|
|
case SCENES: displayScenesPane(); break;
|
|
|
|
case PHYSICS: displayPhysicsPane(); break;
|
|
|
|
case RENDERING: displayRenderingPane(); break;
|
|
|
|
case PROFILING: displayProfilingPane(); break;
|
|
|
|
}
|
2015-06-01 21:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display the list of scenes
|
|
|
|
void Gui::displayScenesPane() {
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
TestbedApplication& app = TestbedApplication::getInstance();
|
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
const float scalingX = app.mWindowToFramebufferRatio.x;
|
|
|
|
const float scalingY = app.mWindowToFramebufferRatio.y;
|
|
|
|
|
2015-06-01 21:40:44 +00:00
|
|
|
static int choice = 0;
|
|
|
|
int startChoice = choice;
|
2015-07-11 16:35:58 +00:00
|
|
|
int scrollarea = 1;
|
|
|
|
int windowWidth, windowHeight;
|
|
|
|
glfwGetWindowSize(mWindow, &windowWidth, &windowHeight);
|
|
|
|
|
2015-06-01 21:40:44 +00:00
|
|
|
std::vector<Scene*> scenes = app.getScenes();
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
imguiBeginScrollArea("Scenes", 0, 0,
|
|
|
|
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
2015-08-06 19:06:35 +00:00
|
|
|
app.mWindowToFramebufferRatio.y * (windowHeight - LEFT_PANE_HEADER_HEIGHT),
|
2015-07-11 16:35:58 +00:00
|
|
|
&scrollarea);
|
|
|
|
|
2015-07-11 22:05:49 +00:00
|
|
|
imguiVerticalSpace(15);
|
|
|
|
|
2015-06-01 21:40:44 +00:00
|
|
|
// For each scene
|
|
|
|
for (int i=0; i<scenes.size(); i++) {
|
|
|
|
|
|
|
|
// Display a radio button
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiCheck(scenes[i]->getName().c_str(), choice == i, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
choice = i;
|
|
|
|
}
|
2015-06-01 21:40:44 +00:00
|
|
|
}
|
|
|
|
if (choice != startChoice) {
|
|
|
|
app.switchScene(scenes[choice]);
|
|
|
|
}
|
2015-07-11 16:35:58 +00:00
|
|
|
|
|
|
|
imguiEndScrollArea();
|
2015-06-01 21:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::displayPhysicsPane() {
|
|
|
|
|
2015-06-30 17:50:17 +00:00
|
|
|
TestbedApplication& app = TestbedApplication::getInstance();
|
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
const float scalingX = app.mWindowToFramebufferRatio.x;
|
|
|
|
const float scalingY = app.mWindowToFramebufferRatio.y;
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
int windowWidth, windowHeight;
|
|
|
|
glfwGetWindowSize(mWindow, &windowWidth, &windowHeight);
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
int scrollarea = 2;
|
|
|
|
imguiBeginScrollArea("Physics Engine Parameters", 0, 0,
|
|
|
|
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
2015-08-06 19:06:35 +00:00
|
|
|
app.mWindowToFramebufferRatio.y * (windowHeight - LEFT_PANE_HEADER_HEIGHT),
|
2015-07-11 16:35:58 +00:00
|
|
|
&scrollarea);
|
2015-04-15 21:11:27 +00:00
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiVerticalSpace(10 * scalingY);
|
2015-07-11 22:05:49 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Enabled/Disable Sleeping
|
2015-09-22 05:32:18 +00:00
|
|
|
bool toggle = imguiCheck("Sleeping enabled", app.mEngineSettings.isSleepingEnabled, true, scalingX, scalingY);
|
2015-07-11 16:35:58 +00:00
|
|
|
if (toggle) {
|
|
|
|
app.mEngineSettings.isSleepingEnabled = !app.mEngineSettings.isSleepingEnabled;
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Enabled/Disable Gravity
|
2015-09-22 05:32:18 +00:00
|
|
|
toggle = imguiCheck("Gravity enabled", app.mEngineSettings.isGravityEnabled, true, scalingX, scalingY);
|
2015-07-11 16:35:58 +00:00
|
|
|
if (toggle) {
|
|
|
|
app.mEngineSettings.isGravityEnabled = !app.mEngineSettings.isGravityEnabled;
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiVerticalSpace(10 * scalingY);
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Timestep
|
|
|
|
float timeStep = app.mEngineSettings.timeStep;
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Timestep", &timeStep, 0.001f, 1.0f, 0.001f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.timeStep = timeStep;
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Nb velocity solver iterations
|
|
|
|
float nbVelocityIterations = static_cast<float>(app.mEngineSettings.nbVelocitySolverIterations);
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Velocity Solver Iterations", &nbVelocityIterations, 1.0f, 100.0f, 1.0f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.nbVelocitySolverIterations = static_cast<int>(nbVelocityIterations);
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Nb position solver iterations
|
|
|
|
float nbPositionIterations = static_cast<float>(app.mEngineSettings.nbPositionSolverIterations);
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Position Solver Iterations", &nbPositionIterations, 1.0f, 100.0f, 1.0f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.nbPositionSolverIterations = static_cast<int>(nbPositionIterations);
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Time before sleep
|
|
|
|
float timeBeforeSleep = app.mEngineSettings.timeBeforeSleep;
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Time before sleep", &timeBeforeSleep, 0.0f, 60.0f, 0.5f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.timeBeforeSleep = timeBeforeSleep;
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Sleep linear velocity
|
|
|
|
float sleepLinearVelocity = app.mEngineSettings.sleepLinearVelocity;
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Sleep linear velocity", &sleepLinearVelocity, 0.0f, 30.0f, 0.5f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.sleepLinearVelocity = sleepLinearVelocity;
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Sleep angular velocity
|
|
|
|
float sleepAngularVelocity = app.mEngineSettings.sleepAngularVelocity;
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Sleep angular velocity", &sleepAngularVelocity, 0.0f, 30.0f, 0.5f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.sleepAngularVelocity = sleepAngularVelocity;
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Gravity vector
|
|
|
|
openglframework::Vector3 gravity = app.mEngineSettings.gravity;
|
|
|
|
float gravityX = gravity.x, gravityY = gravity.y, gravityZ = gravity.z;
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Gravity X", &gravityX, -50.0f, 50.0f, 0.5f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.gravity.x = gravityX;
|
2015-04-28 21:47:29 +00:00
|
|
|
}
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Gravity Y", &gravityY, -50.0f, 50.0f, 0.5f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.gravity.y = gravityY;
|
2015-04-28 21:47:29 +00:00
|
|
|
}
|
2015-09-22 05:32:18 +00:00
|
|
|
if (imguiSlider("Gravity Z", &gravityZ, -50.0f, 50.0f, 0.5f, true, scalingX, scalingY)) {
|
2015-07-11 16:35:58 +00:00
|
|
|
app.mEngineSettings.gravity.z = gravityZ;
|
2015-04-28 21:47:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
imguiEndScrollArea();
|
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
void Gui::displayRenderingPane() {
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-08-06 19:06:35 +00:00
|
|
|
TestbedApplication& app = TestbedApplication::getInstance();
|
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
const float scalingX = app.mWindowToFramebufferRatio.x;
|
|
|
|
const float scalingY = app.mWindowToFramebufferRatio.y;
|
|
|
|
|
2015-08-06 19:06:35 +00:00
|
|
|
int windowWidth, windowHeight;
|
|
|
|
glfwGetWindowSize(mWindow, &windowWidth, &windowHeight);
|
|
|
|
|
|
|
|
int scrollarea = 2;
|
|
|
|
imguiBeginScrollArea("Rendering Parameters", 0, 0,
|
|
|
|
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
|
|
|
app.mWindowToFramebufferRatio.y * (windowHeight - LEFT_PANE_HEADER_HEIGHT),
|
|
|
|
&scrollarea);
|
|
|
|
|
|
|
|
imguiVerticalSpace(15);
|
|
|
|
|
2015-08-11 16:32:45 +00:00
|
|
|
// Display/Hide contact points
|
2015-09-22 05:32:18 +00:00
|
|
|
bool toggleContactPoints = imguiCheck("Contacts", app.mIsContactPointsDisplayed, true, scalingX, scalingY);
|
2015-08-11 16:32:45 +00:00
|
|
|
if (toggleContactPoints) {
|
|
|
|
app.displayContactPoints(!app.mIsContactPointsDisplayed);
|
|
|
|
}
|
|
|
|
|
2015-08-06 19:06:35 +00:00
|
|
|
// Enabled/Disable VSync
|
2015-09-22 05:32:18 +00:00
|
|
|
bool toggleVSync = imguiCheck("V Sync", app.mIsVSyncEnabled, true, scalingX, scalingY);
|
2015-08-06 19:06:35 +00:00
|
|
|
if (toggleVSync) {
|
|
|
|
app.enableVSync(!app.mIsVSyncEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enabled/Disable Shadows
|
2015-09-22 05:32:18 +00:00
|
|
|
bool toggleShadows = imguiCheck("Shadows", app.mIsShadowMappingEnabled, true, scalingX, scalingY);
|
2015-08-06 19:06:35 +00:00
|
|
|
if (toggleShadows) {
|
|
|
|
app.enableShadows(!app.mIsShadowMappingEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
imguiEndScrollArea();
|
2015-04-28 21:47:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
void Gui::displayProfilingPane() {
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-08-06 19:06:35 +00:00
|
|
|
TestbedApplication& app = TestbedApplication::getInstance();
|
|
|
|
|
2015-09-22 05:32:18 +00:00
|
|
|
const float scalingX = app.mWindowToFramebufferRatio.x;
|
|
|
|
const float scalingY = app.mWindowToFramebufferRatio.y;
|
|
|
|
|
2015-08-06 19:06:35 +00:00
|
|
|
double currentTime = glfwGetTime();
|
|
|
|
if ((currentTime - mTimeSinceLastProfilingDisplay) > TIME_INTERVAL_DISPLAY_PROFILING_INFO) {
|
|
|
|
mTimeSinceLastProfilingDisplay = currentTime;
|
|
|
|
mCachedFPS = app.mFPS;
|
|
|
|
mCachedUpdateTime = app.mUpdateTime;
|
|
|
|
mCachedPhysicsUpdateTime = app.mPhysicsUpdateTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
int windowWidth, windowHeight;
|
|
|
|
glfwGetWindowSize(mWindow, &windowWidth, &windowHeight);
|
|
|
|
|
|
|
|
int scrollarea = 2;
|
|
|
|
imguiBeginScrollArea("Profiling", 0, 0,
|
|
|
|
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
|
|
|
app.mWindowToFramebufferRatio.y * (windowHeight - LEFT_PANE_HEADER_HEIGHT),
|
|
|
|
&scrollarea);
|
|
|
|
|
|
|
|
imguiVerticalSpace(15);
|
|
|
|
|
|
|
|
// Framerate (FPS)
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::setprecision(4) << mCachedFPS;
|
|
|
|
std::string fps = std::string("FPS : ") + ss.str();
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiItem(fps.c_str(), true, scalingX, scalingY);
|
2015-08-06 19:06:35 +00:00
|
|
|
|
|
|
|
// Update time
|
|
|
|
std::stringstream ss1;
|
|
|
|
double updateTime = mCachedUpdateTime * 1000.0;
|
|
|
|
ss1 << std::setprecision(4) << updateTime;
|
|
|
|
std::string updateTimeStr = std::string("Update time (ms) : ") + ss1.str();
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiItem(updateTimeStr.c_str(), true, scalingX, scalingY);
|
2015-08-06 19:06:35 +00:00
|
|
|
|
|
|
|
// Update time (physics)
|
|
|
|
std::stringstream ss2;
|
|
|
|
ss2 << std::setprecision(4) << (mCachedPhysicsUpdateTime * 1000.0);
|
|
|
|
std::string updatePhysicsTimeStr = std::string("Update physics time (ms) : ") + ss2.str();
|
2015-09-22 05:32:18 +00:00
|
|
|
imguiItem(updatePhysicsTimeStr.c_str(), true, scalingX, scalingY);
|
2015-08-06 19:06:35 +00:00
|
|
|
|
|
|
|
imguiEndScrollArea();
|
2015-07-11 16:35:58 +00:00
|
|
|
}
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
// Display the GUI
|
|
|
|
void Gui::render() {
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
TestbedApplication& app = TestbedApplication::getInstance();
|
2015-04-28 21:47:29 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
int display_w, display_h;
|
|
|
|
glfwGetFramebufferSize(mWindow, &display_w, &display_h);
|
|
|
|
|
|
|
|
int windowWidth, windowHeight;
|
|
|
|
glfwGetWindowSize(mWindow, &windowWidth, &windowHeight);
|
|
|
|
|
|
|
|
// Mouse position
|
|
|
|
double mouseX, mouseY;
|
|
|
|
glfwGetCursorPos(mWindow, &mouseX, &mouseY);
|
|
|
|
|
|
|
|
// Mouse buttons
|
|
|
|
int leftButton = glfwGetMouseButton(mWindow, GLFW_MOUSE_BUTTON_LEFT);
|
|
|
|
unsigned char mousebutton = 0;
|
|
|
|
if(leftButton == GLFW_PRESS ) {
|
|
|
|
mousebutton |= IMGUI_MBUT_LEFT;
|
2015-04-28 21:47:29 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
imguiBeginFrame(app.mWindowToFramebufferRatio.x * mouseX,
|
2015-07-11 22:05:49 +00:00
|
|
|
app.mWindowToFramebufferRatio.y * (windowHeight - mouseY), mousebutton,
|
|
|
|
- app.mWindowToFramebufferRatio.y * mScrollY);
|
2015-07-11 16:35:58 +00:00
|
|
|
resetScroll();
|
2015-04-28 21:47:29 +00:00
|
|
|
|
2015-07-31 19:54:02 +00:00
|
|
|
//displayHeader();
|
2015-07-11 16:35:58 +00:00
|
|
|
displayLeftPane();
|
|
|
|
|
|
|
|
imguiEndFrame();
|
2015-04-08 18:47:55 +00:00
|
|
|
|
2015-07-11 16:35:58 +00:00
|
|
|
imguiRenderGLDraw(display_w, display_h);
|
2015-04-08 18:47:55 +00:00
|
|
|
}
|