FPS Control working, minor UI cleanup.
parent
23d7cf03f6
commit
1848fd14cf
|
@ -23,6 +23,14 @@ inline void CameraState_Init(CameraState* camera_state) {
|
|||
camera_state->up[1] = 1.f;
|
||||
camera_state->up[2] = 0.f;
|
||||
|
||||
camera_state->pos[0] = 0.f;
|
||||
camera_state->pos[1] = 0.f;
|
||||
camera_state->pos[2] = 0.f;
|
||||
|
||||
camera_state->vel[0] = 0.f;
|
||||
camera_state->vel[1] = 0.f;
|
||||
camera_state->vel[2] = 0.f;
|
||||
|
||||
memcpy(&camera_state->mtxView, &mtx_identity, sizeof(camera_state->mtxView));
|
||||
CameraState_CalcFromMatrix(camera_state, &camera_state->mtxView);
|
||||
}
|
||||
|
@ -93,9 +101,9 @@ inline void CameraState_Update(
|
|||
|
||||
camera_state->heading -= dt * mouse_dx * mouse_sensitivity * M_PI / 180.f;
|
||||
if (camera_state->heading < -M_PI) {
|
||||
camera_state->heading += M_PI;
|
||||
camera_state->heading += M_PI * 2.f;
|
||||
} else if (camera_state->heading > M_PI) {
|
||||
camera_state->heading -= M_PI;
|
||||
camera_state->heading -= M_PI * 2.f;
|
||||
}
|
||||
camera_state->pitch += dt * mouse_dy * mouse_sensitivity * M_PI / 180.f;
|
||||
if (camera_state->pitch < -M_PI * 0.49) {
|
||||
|
|
|
@ -118,8 +118,6 @@ void simulator_reset() {
|
|||
void simulator_gui() {
|
||||
ZoneScoped;
|
||||
|
||||
ImGui::Begin("Simulator");
|
||||
|
||||
sStateHistoryCurrent =
|
||||
std::min(sStateHistoryCurrent, sthstry_get_num_states(sStateHistory) - 1);
|
||||
|
||||
|
@ -184,8 +182,6 @@ void simulator_gui() {
|
|||
ImGui::PopID();
|
||||
body.updateCollisionShapes();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void simulator_update(double dt) {
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
// clang-format on
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <csignal>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <Tracy.hpp>
|
||||
#include <csignal>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -20,10 +20,10 @@
|
|||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#endif
|
||||
#include "imgui_internal.h"
|
||||
#include "render_utils.h"
|
||||
#include "simulator.h"
|
||||
#include "srender.h"
|
||||
#include "utils.h"
|
||||
#include "render_utils.h"
|
||||
|
||||
GLFWwindow* gWindow = nullptr;
|
||||
GuiInputState* gGuiInputState = nullptr;
|
||||
|
@ -64,6 +64,14 @@ bool gGizmoEnabled = true;
|
|||
enum ControlMode { ControlModeNone = 0, ControlModeFirstPersonView = 1 };
|
||||
ControlMode gControlMode = ControlModeNone;
|
||||
|
||||
struct Dialogs {
|
||||
bool mCameraDialog = false;
|
||||
bool mImGuiDemo = false;
|
||||
bool mSimulator = false;
|
||||
bool mImGuizmoTransform = false;
|
||||
};
|
||||
Dialogs* gDialogs = nullptr;
|
||||
|
||||
using namespace std;
|
||||
|
||||
static void error_callback(int error, const char* description) {
|
||||
|
@ -254,7 +262,8 @@ void ShowTransformManip(
|
|||
window_size.x -= imgui_style.WindowPadding.x * 2;
|
||||
window_size.y -= imgui_style.WindowPadding.y * 2 + title_height;
|
||||
|
||||
ImGui::Begin("Guizmo");
|
||||
if (gDialogs->mImGuizmoTransform) {
|
||||
ImGui::Begin("Guizmo", &gDialogs->mImGuizmoTransform);
|
||||
|
||||
if (editTransformDecomposition) {
|
||||
if (ImGui::IsKeyPressed(90)) mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||
|
@ -271,7 +280,9 @@ void ShowTransformManip(
|
|||
mCurrentGizmoOperation == ImGuizmo::ROTATE))
|
||||
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||
if (ImGui::RadioButton(
|
||||
"Scale",
|
||||
mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||
if (ImGui::RadioButton(
|
||||
"Universal",
|
||||
|
@ -325,6 +336,7 @@ void ShowTransformManip(
|
|||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
float viewManipulateRight = io.DisplaySize.x;
|
||||
|
@ -407,7 +419,12 @@ void DoRender() {
|
|||
|
||||
if (gViewMode == ViewModeSimulation) {
|
||||
simulator_draw(gRndrCmds);
|
||||
|
||||
if (gDialogs->mSimulator) {
|
||||
ImGui::Begin("Simulator", &gDialogs->mSimulator);
|
||||
simulator_gui();
|
||||
ImGui::End();
|
||||
}
|
||||
} else {
|
||||
RenderGuizmoTest(gRndrCmds);
|
||||
}
|
||||
|
@ -426,7 +443,8 @@ void DoRender() {
|
|||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ShowViewManip();
|
||||
ShowTransformManip((float*)&(gCameraState->mtxView),
|
||||
ShowTransformManip(
|
||||
(float*)&(gCameraState->mtxView),
|
||||
(float*)&(gProjMatrix),
|
||||
(float*)(&gTransformMatrix));
|
||||
|
||||
|
@ -516,6 +534,9 @@ int main(void) {
|
|||
CameraState_Init(&camera_state);
|
||||
gCameraState = &camera_state;
|
||||
|
||||
Dialogs dialogs;
|
||||
gDialogs = &dialogs;
|
||||
|
||||
gRndr = srndr_create();
|
||||
gView = srview_create();
|
||||
gRndrCmds = srcmdbuf_create(1024);
|
||||
|
@ -575,11 +596,13 @@ int main(void) {
|
|||
ImGui::BeginMainMenuBar();
|
||||
|
||||
if (ImGui::BeginMenu("Dialogs")) {
|
||||
ImGui::Checkbox("ImGui Demo", &show_demo_window);
|
||||
ImGui::Checkbox("Camera", &gDialogs->mCameraDialog);
|
||||
ImGui::Checkbox("Simulator", &gDialogs->mSimulator);
|
||||
ImGui::Checkbox("ImGuizmo Transform", &gDialogs->mImGuizmoTransform);
|
||||
ImGui::Checkbox("ImGui Demo", &gDialogs->mImGuiDemo);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
|
||||
float menu_bar_height = ImGui::GetWindowHeight();
|
||||
ImGui::EndMainMenuBar();
|
||||
|
||||
|
@ -616,26 +639,49 @@ int main(void) {
|
|||
camera_accel[2] += 100.f;
|
||||
}
|
||||
|
||||
CameraState_Update(gCameraState, frame_delta_time, gGuiInputState->mousedX, gGuiInputState->mousedY, camera_accel);
|
||||
CameraState_Update(
|
||||
gCameraState,
|
||||
frame_delta_time,
|
||||
gGuiInputState->mousedX,
|
||||
gGuiInputState->mousedY,
|
||||
camera_accel);
|
||||
}
|
||||
|
||||
ImGui::Begin("Camera Controls");
|
||||
if (gDialogs->mCameraDialog) {
|
||||
ImGui::Begin("Camera Controls", &gDialogs->mCameraDialog);
|
||||
|
||||
bool changed = false;
|
||||
changed = ImGui::SliderFloat("Heading", &gCameraState->heading, -M_PI * 0.98, M_PI * 0.98);
|
||||
changed = ImGui::SliderFloat("Pitch", &gCameraState->pitch, -M_PI * 0.49, M_PI * 0.49) || changed;
|
||||
changed = ImGui::SliderFloat(
|
||||
"Heading",
|
||||
&gCameraState->heading,
|
||||
-M_PI * 0.98,
|
||||
M_PI * 0.98);
|
||||
changed = ImGui::SliderFloat(
|
||||
"Pitch",
|
||||
&gCameraState->pitch,
|
||||
-M_PI * 0.49,
|
||||
M_PI * 0.49)
|
||||
|| changed;
|
||||
|
||||
changed = ImGui::SliderFloat3("Forward", gCameraState->forward, -1.f, 1.f) || changed;
|
||||
changed = ImGui::SliderFloat3("Right", gCameraState->right, -1.f, 1.f) || changed;
|
||||
changed = ImGui::SliderFloat3("Up", gCameraState->up, -1.f, 1.f) || changed;
|
||||
changed = ImGui::SliderFloat3("Pos", gCameraState->pos, -100.f, 100.f) || changed;
|
||||
changed =
|
||||
ImGui::SliderFloat3("Forward", gCameraState->forward, -1.f, 1.f)
|
||||
|| changed;
|
||||
changed = ImGui::SliderFloat3("Right", gCameraState->right, -1.f, 1.f)
|
||||
|| changed;
|
||||
changed =
|
||||
ImGui::SliderFloat3("Up", gCameraState->up, -1.f, 1.f) || changed;
|
||||
changed = ImGui::SliderFloat3("Pos", gCameraState->pos, -100.f, 100.f)
|
||||
|| changed;
|
||||
|
||||
if (changed) {
|
||||
CameraState_CalcToMatrix(gCameraState, &gCameraState->mtxView);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if (show_demo_window) ImGui::ShowDemoWindow();
|
||||
if (gDialogs->mImGuiDemo) {
|
||||
ImGui::ShowDemoWindow(&gDialogs->mImGuiDemo);
|
||||
}
|
||||
|
||||
ShowDockspace(true);
|
||||
|
||||
|
|
Loading…
Reference in New Issue