Skip to content

Commit

Permalink
toggle imgui
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed May 26, 2024
1 parent ec9b288 commit 9b5cb1c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion engine/include/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CameraController {
// Dtor
~CameraController() = default;

void update(float delta_time);
void update(float delta_time, bool& imgui);

private:
static constexpr float normal_speed = 5.f;
Expand Down
10 changes: 7 additions & 3 deletions engine/src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ glm::vec3 cartesian_to_spherical(glm::vec3 vec) {
return glm::vec3 {abs, std::atan2(x, z), std::acos(y / abs)};
}

void CameraController::update(float delta_time) {
void CameraController::update(float delta_time, bool& imgui) {
const glm::vec3 right =
glm::normalize(glm::cross(m_camera.forward, m_camera.up));

// Update speed
m_speed = Input::is_down(Keyboard::LShift) ? sprint_speed : normal_speed;

if (Input::is_down(Keyboard::F1)) {
imgui = true;
}
if(Input::is_down(Keyboard::F2)) {
imgui = false;
}
// Update camera position
if (Input::is_down(Keyboard::W)) {
m_camera.position += m_camera.forward * m_speed * delta_time;
Expand Down Expand Up @@ -68,8 +74,6 @@ void CameraController::update(float delta_time) {
m_camera.forward = spherical_to_cartesian(spherical_forward);
}



// Update camera direction
if (Input::is_down(Mouse::Right)) {
glm::vec3 spherical_forward = cartesian_to_spherical(m_camera.forward);
Expand Down
7 changes: 5 additions & 2 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bool culling = false;
bool lighting = false;
float speed_factor = 1.0f;
bool models_menus = false;
bool imgui = false;

int total_models = 0;
int nr_models = 0;
Expand Down Expand Up @@ -214,7 +215,7 @@ void update() {
Input::process_input();
static CameraController cameraController(camera);
float delta_time = compute_delta_time();
cameraController.update(delta_time);
cameraController.update(delta_time, imgui);
}

void renderScene(void) {
Expand All @@ -241,7 +242,9 @@ void renderScene(void) {
c.group.drawGroup(lighting, frustsum, normals, speed_factor, nr_models);

// Start the Dear ImGui frame
renderMenu();
if(imgui) {
renderMenu();
}

// End of frame
glutSwapBuffers();
Expand Down
3 changes: 1 addition & 2 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Collapsed=0

[Window][Infos]
Pos=15,18

Size=325,139
Size=311,139
Collapsed=0

[Window][Options]
Expand Down

0 comments on commit 9b5cb1c

Please sign in to comment.