Browse Source

Played with ImGui

* Added a primitive Vehicle editor and bad documentation viewer
* Added ImGui window for toggling settings
* Updated Base2.0
* Fixed warnings
ogre-port2
Macoy Madson 11 months ago
parent
commit
d39676ff69
14 changed files with 263 additions and 93 deletions
  1. +1
    -1
      Dependencies/base2.0
  2. +10
    -1
      Jamfile
  3. +4
    -4
      src/Audio.cpp
  4. +1
    -0
      src/DebugDisplay.cpp
  5. +3
    -0
      src/GameVehicle.hpp
  6. +1
    -1
      src/Joystick.cpp
  7. +59
    -7
      src/Main.cpp
  8. +13
    -13
      src/ModelUtilities/ObjLoader.cpp
  9. +2
    -2
      src/PhysicsVehicle.cpp
  10. +3
    -3
      src/PhysicsVehicle.hpp
  11. +58
    -58
      src/RenderLibs/Horde3D/Horde3DCore.cpp
  12. +3
    -3
      src/Terrain.cpp
  13. +100
    -0
      src/VehicleEditor.cpp
  14. +5
    -0
      src/VehicleEditor.hpp

+ 1
- 1
Dependencies/base2.0

@ -1 +1 @@
Subproject commit b4a9fcba37bc4febff689f0c3e3f8c8d37797085
Subproject commit cf0451664674d91c3c0eb6c11981b420107d26e2

+ 10
- 1
Jamfile View File

@ -18,7 +18,9 @@ src/PhysicsVehicle.cpp
src/PhysicsWorld.cpp
src/Terrain.cpp
src/GameVehicle.cpp
#Third party
# Editors
src/VehicleEditor.cpp
# Third party
Dependencies/tracy/TracyClient.cpp
;
@ -67,6 +69,13 @@ assets/male_casualsuit06_diffuse.png
Bulk Content/textures : assets/Wheel_Rear.png
assets/TestGrid_Sandy.png ;
# TODO: Make sure textures get copied if assets are updated
# This doesn't work
# NotFile Content/textures ;
# NotFile Content/assets ;
# Depends Content/textures : dataAssets ;
# Depends Content/assets : dataAssets ;
BuildAsset assets/Wheel_Rear : assets/Wheel_Rear.blend ;
BuildAsset assets/Wheel_Front : assets/Wheel_Front.blend ;
BuildAsset assets/World : assets/World.blend ;


+ 4
- 4
src/Audio.cpp View File

@ -177,11 +177,11 @@ bool VehicleEngineAudioStream::onGetData(sf::SoundStream::Chunk& data)
engineRpm = lastEngineRpm;
}
const SoundSample maxMotion = 10;
const float pi = std::acos(-1);
// const SoundSample maxMotion = 10;
// const float pi = std::acos(-1);
SoundSample lastSample = sampleBuffer[ArraySize(sampleBuffer) - 1];
int triangleWaveDirection = 1;
int triangleWaveSpeed = 1000;
// int triangleWaveDirection = 1;
// int triangleWaveSpeed = 1000;
unsigned int engineUpSquareNextNSamples = 0;
for (unsigned int i = 0; i < ArraySize(sampleBuffer); ++i)
{


+ 1
- 0
src/DebugDisplay.cpp View File

@ -24,6 +24,7 @@ void initialize(window* newOutputWindow)
displayText.setSize(32);
displayText.setColor(232, 30, 34, 255);
displayText.setOutlineColor(0, 30, 34, 255);
outputWindow = newOutputWindow;
}


+ 3
- 0
src/GameVehicle.hpp View File

@ -4,9 +4,12 @@
class PhysicsVehicle;
class PhysicsWorld;
struct PhysicsVehicleTuning;
namespace GameVehicles
{
extern PhysicsVehicleTuning defaultTuning;
PhysicsVehicle* CreateVehicle(PhysicsWorld& world, const glm::mat4& startTransform);
void UpdatePhysics(float deltaTime);


+ 1
- 1
src/Joystick.cpp View File

@ -58,7 +58,7 @@ bool isJoystickValid(int playerJoystickId)
{
if (!sf::Joystick::isConnected(playerJoystickId))
{
LOGE << "Player Joystick " << playerJoystickId << " is not connected";
// LOGE << "Player Joystick " << playerJoystickId << " is not connected";
return false;
}
return true;


+ 59
- 7
src/Main.cpp View File

@ -36,6 +36,7 @@
#include "PhysicsWorld.hpp"
#include "PickUpObjective.hpp"
#include "Terrain.hpp"
#include "VehicleEditor.hpp"
#include "imgui.h"
#include "imgui-SFML.h"
@ -63,7 +64,11 @@ bool debugDraw3D = true;
bool debugDraw2D = true;
// bool debugDraw2D = false;
bool enableGui = false;
// Show ImGui dialogs
// bool enableDevGui = false;
bool enableDevGui = true;
bool showImGuiDemo = false;
bool showVehicleEditor = false;
bool useJoystick = true;
// bool useJoystick = false;
@ -219,6 +224,7 @@ void handleConfigurationInput(inputManager& input, PhysicsVehicle& mainVehicle)
{
debugDraw3D = !debugDraw3D;
debugDraw2D = !debugDraw2D;
enableDevGui = !enableDevGui;
}
if (input.WasTapped(inputCode::F10, noKeyRepeat))
{
@ -269,10 +275,14 @@ int main()
DebugDisplay::initialize(&mainWindow);
Graphics::Initialize(WindowWidth, WindowHeight);
if (enableGui)
if (enableDevGui)
{
PerfTimeNamedScope(imguiInit, "IMGUI Initialization", tracy::Color::Purple);
PerfTimeNamedScope(imguiInit, "ImGui Initialization", tracy::Color::Purple);
ImGui::SFML::Init(*(mainWindow.getBase()));
ImGuiStyle& style = ImGui::GetStyle();
style.ScaleAllSizes(1.7f);
style.Alpha = 0.75f;
}
}
@ -369,10 +379,21 @@ int main()
PerfManualZoneEnd(InitializeContext);
while (!mainWindow.shouldClose() && !input.isPressed(inputCode::Escape))
while (!input.isPressed(inputCode::Escape))
{
PerfTimeNamedScope(timeFrameScope, "Frame", tracy::Color::SlateBlue);
{
PerfTimeNamedScope(windowEventsScope, "Poll Window Events", tracy::Color::Red);
bool shouldClose =
mainWindow.pollEventsUpdateState([](sf::RenderWindow* win, const sf::Event& event) {
ImGui::SFML::ProcessEvent(event);
});
if (shouldClose)
break;
}
PerfManualZoneBegin(GameplayContext, "Gameplay", tracy::Color::RoyalBlue);
// Input
@ -678,13 +699,44 @@ int main()
}
}
if (enableGui)
if (enableDevGui)
{
PerfTimeNamedScope(imguiScope, "IMGUI", tracy::Color::RosyBrown1);
PerfTimeNamedScope(imguiScope, "ImGui update and render", tracy::Color::RosyBrown1);
ImGui::SFML::Update(*mainWindow.getBase(), imguiDeltaClock.restart());
ImGui::ShowDemoWindow();
ImGui::Begin("Options");
{
ImGui::Checkbox("Enable Dev UI", &enableDevGui);
ImGui::Checkbox("Show ImGui Demo", &showImGuiDemo);
ImGui::Checkbox("Show Vehicle Editor", &showVehicleEditor);
ImGui::Separator();
ImGui::Checkbox("Draw physics", &debugPhysicsDraw);
ImGui::Checkbox("Draw 3D lines", &debugDraw3D);
ImGui::Checkbox("Draw 2D overlays", &debugDraw2D);
ImGui::Separator();
ImGui::Checkbox("Use Joystick input", &useJoystick);
ImGui::Checkbox("Toggle free/chase camera", &useChaseCam);
bool splitscreenBeforeUI = splitScreen;
ImGui::Checkbox("Splitscreen", &splitScreen);
if (splitScreen != splitscreenBeforeUI)
{
Graphics::SetViewport(0, 0, WindowWidth, WindowHeight);
}
ImGui::Checkbox("Two player", &twoPlayer);
}
ImGui::End();
if (showVehicleEditor)
updateVehicleEditor(physicsWorld, &vehicle);
if (showImGuiDemo)
ImGui::ShowDemoWindow();
ImGui::SFML::Render(*mainWindow.getBase());
}


+ 13
- 13
src/ModelUtilities/ObjLoader.cpp View File

@ -45,7 +45,7 @@ bool objTest()
size_t index_offset = 0;
for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++)
{
int fv = shapes[s].mesh.num_face_vertices[f];
size_t fv = static_cast<size_t>(shapes[s].mesh.num_face_vertices[f]);
// Loop over vertices in the face.
for (size_t v = 0; v < fv; v++)
@ -55,11 +55,11 @@ bool objTest()
tinyobj::real_t vx = attrib.vertices[3 * idx.vertex_index + 0];
tinyobj::real_t vy = attrib.vertices[3 * idx.vertex_index + 1];
tinyobj::real_t vz = attrib.vertices[3 * idx.vertex_index + 2];
tinyobj::real_t nx = attrib.normals[3 * idx.normal_index + 0];
tinyobj::real_t ny = attrib.normals[3 * idx.normal_index + 1];
tinyobj::real_t nz = attrib.normals[3 * idx.normal_index + 2];
tinyobj::real_t tx = attrib.texcoords[2 * idx.texcoord_index + 0];
tinyobj::real_t ty = attrib.texcoords[2 * idx.texcoord_index + 1];
// tinyobj::real_t nx = attrib.normals[3 * idx.normal_index + 0];
// tinyobj::real_t ny = attrib.normals[3 * idx.normal_index + 1];
// tinyobj::real_t nz = attrib.normals[3 * idx.normal_index + 2];
// tinyobj::real_t tx = attrib.texcoords[2 * idx.texcoord_index + 0];
// tinyobj::real_t ty = attrib.texcoords[2 * idx.texcoord_index + 1];
// Optional: vertex colors
// tinyobj::real_t red = attrib.colors[3*idx.vertex_index+0];
// tinyobj::real_t green = attrib.colors[3*idx.vertex_index+1];
@ -120,7 +120,7 @@ bool objToBulletTriangleMesh(PhysicsWorld& world, const char* filename)
size_t numFaces = shapes[s].mesh.num_face_vertices.size();
for (size_t f = 0; f < numFaces; f++)
{
int fv = shapes[s].mesh.num_face_vertices[f];
size_t fv = static_cast<size_t>(shapes[s].mesh.num_face_vertices[f]);
// Loop over vertices in the face.
for (size_t v = 0; v < fv; v++)
@ -130,11 +130,11 @@ bool objToBulletTriangleMesh(PhysicsWorld& world, const char* filename)
tinyobj::real_t vx = attrib.vertices[3 * idx.vertex_index + 0];
tinyobj::real_t vy = attrib.vertices[3 * idx.vertex_index + 1];
tinyobj::real_t vz = attrib.vertices[3 * idx.vertex_index + 2];
tinyobj::real_t nx = attrib.normals[3 * idx.normal_index + 0];
tinyobj::real_t ny = attrib.normals[3 * idx.normal_index + 1];
tinyobj::real_t nz = attrib.normals[3 * idx.normal_index + 2];
tinyobj::real_t tx = attrib.texcoords[2 * idx.texcoord_index + 0];
tinyobj::real_t ty = attrib.texcoords[2 * idx.texcoord_index + 1];
// tinyobj::real_t nx = attrib.normals[3 * idx.normal_index + 0];
// tinyobj::real_t ny = attrib.normals[3 * idx.normal_index + 1];
// tinyobj::real_t nz = attrib.normals[3 * idx.normal_index + 2];
// tinyobj::real_t tx = attrib.texcoords[2 * idx.texcoord_index + 0];
// tinyobj::real_t ty = attrib.texcoords[2 * idx.texcoord_index + 1];
// Optional: vertex colors
// tinyobj::real_t red = attrib.colors[3*idx.vertex_index+0];
// tinyobj::real_t green = attrib.colors[3*idx.vertex_index+1];
@ -144,7 +144,7 @@ bool objToBulletTriangleMesh(PhysicsWorld& world, const char* filename)
btVector3 vertex = {vx, vy, vz};
// Make room (TODO: Preallocate)
if (idx.vertex_index >= bulletVertices->size())
if (static_cast<size_t>(idx.vertex_index) >= bulletVertices->size())
bulletVertices->resize(idx.vertex_index + 1);
(*bulletVertices)[idx.vertex_index] = vertex;
bulletIndicies->push_back(idx.vertex_index);


+ 2
- 2
src/PhysicsVehicle.cpp View File

@ -373,8 +373,8 @@ void PhysicsVehicle::Update(float deltaTime)
playVehicleShifting();
}
LOGV << "Input throttle: " << ThrottlePercent << " Gear: " << SelectedGear
<< " output force: " << engineForce;
// LOGV << "Input throttle: " << ThrottlePercent << " Gear: " << SelectedGear
// << " output force: " << engineForce;
// Apply forces
// Rear-wheel drive


+ 3
- 3
src/PhysicsVehicle.hpp View File

@ -33,7 +33,7 @@ struct PhysicsVehicleTuning
// chassisLocalOffset shifts the chassis collision shape relative to the vehicle origin
// If chassisLocalOffset = {0.f, 0.f, 0.f}, the chassis half-width, half-height, half-length
// bounding box will be centered around 0, 0, 0
const btVector3 chassisLocalOffset = {0.f, 1.022f / 2.f, 0.f};
btVector3 chassisLocalOffset = {0.f, 1.022f / 2.f, 0.f};
// Offset the top of the wheel relative to the origin
// float connectionHeight = 0.827f; // 1.2f;
@ -54,9 +54,9 @@ struct PhysicsVehicleTuning
// Not really necessary to customize these, unless you're making something weird
// These need to be normalized, otherwise they scale the wheels
// The direction of the raycast from connectionHeight to (suspensionRestLength + wheelRadius)
const btVector3 wheelDirectionCS0 = {0.f, -1.f, 0.f};
btVector3 wheelDirectionCS0 = {0.f, -1.f, 0.f};
// The normal of the hubcap, basically
const btVector3 wheelAxleCS = {-1.f, 0.f, 0.f};
btVector3 wheelAxleCS = {-1.f, 0.f, 0.f};
// const btVector3 wheelAxleCS = {0.f, 0.f, -1.f};
// How much force it takes to compress the spring.


+ 58
- 58
src/RenderLibs/Horde3D/Horde3DCore.cpp View File

@ -113,64 +113,64 @@ H3DNode CreateProceduralGeometry(const char* geoName, float* vertices, unsigned
namespace Graphics
{
static void TestProceduralGeometry_Cube()
{
float size = 10.f;
float vertices[] = {
// Top fl [0]
-1.f * size,
1.f * size,
-1.f * size,
// Top fr [1]
1.f * size,
1.f * size,
-1.f * size,
// Top bl [2]
-1.f * size,
1.f * size,
1.f * size,
// Top br [3]
1.f * size,
1.f * size,
1.f * size,
// Bottom fl [4]
-1.f * size,
-1.f * size,
-1.f * size,
// Bottom fr [5]
1.f * size,
-1.f * size,
-1.f * size,
// Bottom bl [6]
-1.f * size,
-1.f * size,
1.f * size,
// Bottom br [7]
1.f * size,
-1.f * size,
1.f * size,
};
unsigned int numVertices = ArraySize(vertices) / 3;
unsigned int indices[] = {// Top
0, 2, 1, 1, 2, 3,
// Front
0, 1, 4, 4, 1, 5,
// Left
6, 2, 4, 4, 2, 0,
// Back
3, 2, 6, 6, 7, 3,
// Right
5, 1, 7, 7, 1, 3,
// Bottom
6, 4, 7, 7, 4, 5};
unsigned int numIndices = ArraySize(indices);
CreateProceduralGeometry("ProceduralGeo_Cube", vertices, indices, nullptr, nullptr, nullptr,
nullptr, nullptr, numVertices, numIndices);
}
// static void TestProceduralGeometry_Cube()
// {
// float size = 10.f;
// float vertices[] = {
// // Top fl [0]
// -1.f * size,
// 1.f * size,
// -1.f * size,
// // Top fr [1]
// 1.f * size,
// 1.f * size,
// -1.f * size,
// // Top bl [2]
// -1.f * size,
// 1.f * size,
// 1.f * size,
// // Top br [3]
// 1.f * size,
// 1.f * size,
// 1.f * size,
// // Bottom fl [4]
// -1.f * size,
// -1.f * size,
// -1.f * size,
// // Bottom fr [5]
// 1.f * size,
// -1.f * size,
// -1.f * size,
// // Bottom bl [6]
// -1.f * size,
// -1.f * size,
// 1.f * size,
// // Bottom br [7]
// 1.f * size,
// -1.f * size,
// 1.f * size,
// };
// unsigned int numVertices = ArraySize(vertices) / 3;
// unsigned int indices[] = {// Top
// 0, 2, 1, 1, 2, 3,
// // Front
// 0, 1, 4, 4, 1, 5,
// // Left
// 6, 2, 4, 4, 2, 0,
// // Back
// 3, 2, 6, 6, 7, 3,
// // Right
// 5, 1, 7, 7, 1, 3,
// // Bottom
// 6, 4, 7, 7, 4, 5};
// unsigned int numIndices = ArraySize(indices);
// CreateProceduralGeometry("ProceduralGeo_Cube", vertices, indices, nullptr, nullptr, nullptr,
// nullptr, nullptr, numVertices, numIndices);
// }
void Initialize(int winWidth, int winHeight)
{


+ 3
- 3
src/Terrain.cpp View File

@ -22,7 +22,7 @@
static int s_gridSize = 20 + 1; // must be (2^N) + 1
// static int s_gridSize = 16 + 1; // must be (2^N) + 1
// static int s_gridSize = 8 + 1; // must be (2^N) + 1
static btScalar s_gridSpacing = 1.0;
// static btScalar s_gridSpacing = 1.0;
static const int upAxis = 1;
static const int worldSeed = 51388234;
@ -142,8 +142,8 @@ void createCollisionHeightfield(PhysicsWorld& world)
// Note that this origin will be center of heightfield, so it will need to be adjusted if bounds
// change
transform.setOrigin(btVector3(-17.f, -5.f, 250.f));
btRigidBody* body =
world.localCreateRigidBody(PhysicsWorld::StaticRigidBodyMass, transform, heightfieldShape);
// btRigidBody* body =
world.localCreateRigidBody(PhysicsWorld::StaticRigidBodyMass, transform, heightfieldShape);
// Rendering: create render geo from the heightfield
{


+ 100
- 0
src/VehicleEditor.cpp View File

@ -0,0 +1,100 @@
#include "VehicleEditor.hpp"
#include "GameVehicle.hpp"
#include "Logging.hpp"
#include "PhysicsVehicle.hpp"
#include "imgui-SFML.h"
#include "imgui.h"
#include <glm/mat4x4.hpp> // mat4
#include <fstream>
#include <string>
bool showTuningHelp = false;
static const char* tuningDocumentationFilename = "docs/VehicleTuning.org";
static std::vector<std::string> tuningDocumentationLines;
static void loadTuningDocumentation()
{
std::ifstream inputFileStream(tuningDocumentationFilename);
std::string line;
if (inputFileStream.is_open())
{
while (std::getline(inputFileStream, line))
{
tuningDocumentationLines.push_back(line);
}
}
else
LOGE << "Could not open Vehicle tuning documentation '" << tuningDocumentationFilename
<< "'";
}
// This currently has to delete and recreate the vehicle when parameters change
void updateVehicleEditor(PhysicsWorld& world, PhysicsVehicle** vehicleToEdit)
{
PhysicsVehicleTuning& tuning = GameVehicles::defaultTuning;
ImGui::Begin("Vehicle Tuning Editor");
{
ImGui::SliderFloat("Mass (Kg)", &tuning.massKg, 1.f, 10000.f);
ImGui::SliderFloat("Chassis Width", &tuning.chassisWidth, 0.f, 50.f);
ImGui::SliderFloat("Chassis Height", &tuning.chassisHeight, 0.f, 50.f);
ImGui::SliderFloat("Chassis Length", &tuning.chassisLength, 0.f, 50.f);
ImGui::SliderFloat("Connection Height", &tuning.connectionHeight, 0.f, 10.f);
ImGui::SliderFloat("wheel Radius", &tuning.wheelRadius, 0.f, 10.f);
ImGui::SliderFloat("wheel Width", &tuning.wheelWidth, 0.f, 10.f);
ImGui::Separator();
ImGui::SliderFloat("Wheel Friction", &tuning.wheelFriction, 0.f, 1000.f);
ImGui::Separator();
ImGui::SliderFloat("Suspension Rest Length", &tuning.suspensionRestLength, 0.f, 1000.f);
ImGui::SliderFloat("Suspension Stiffness", &tuning.suspensionStiffness, 0.f, 1000.f);
ImGui::SliderFloat("Suspension Damping Relaxation", &tuning.suspensionDampingRelaxation,
0.f, 1000.f);
ImGui::SliderFloat("Suspension Damping Compression", &tuning.suspensionDampingCompression,
0.f, 1000.f);
ImGui::SliderFloat("Roll Influence", &tuning.rollInfluence, 0.f, 1000.f);
ImGui::Separator();
ImGui::SliderFloat("Default Braking Force", &tuning.defaultBrakingForce, 0.f, 1000.f);
ImGui::Separator();
ImGui::Checkbox("Show tuning documentation (Warning: may affect framerate)", &showTuningHelp);
if (ImGui::Button("Reset to defaults"))
tuning = {};
if (ImGui::Button("Commit changes and reset vehicle"))
{
// TODO No way to reset vehicle to new tuning
*vehicleToEdit = GameVehicles::CreateVehicle(world, glm::mat4(1.f));
}
}
ImGui::End();
// Not great, but sort of works
if (showTuningHelp)
{
if (tuningDocumentationLines.empty())
loadTuningDocumentation();
ImGui::Begin("Vehicle Tuning Documentation");
bool headerShowLines = true;
for (std::string& line : tuningDocumentationLines)
{
// Handle case where *bold text* starts a line
if (line[0] == '*' && (line[1] == ' ' || line[1] == '*'))
headerShowLines = ImGui::CollapsingHeader(line.c_str());
else
{
if (!headerShowLines)
continue;
ImGui::TextWrapped("%s", line.c_str());
}
}
ImGui::End();
}
}

+ 5
- 0
src/VehicleEditor.hpp View File

@ -0,0 +1,5 @@
#pragma once
class PhysicsWorld;
class PhysicsVehicle;
void updateVehicleEditor(PhysicsWorld& world, PhysicsVehicle** vehicleToEdit);

Loading…
Cancel
Save