Skip to content

Commit

Permalink
option to move camera with mouse wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Oct 5, 2024
1 parent c6b0e5f commit 96ecf1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/renderer/editor/scene_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ SceneView::SceneView(StudioApp& app)

m_app.getSettings().registerPtr("quicksearch_preview", &m_search_preview, "Scene view");
m_app.getSettings().registerPtr("show_camera_preview", &m_show_camera_preview, "Scene view");
m_app.getSettings().registerPtr("mouse_wheel_changes_speed", &m_mouse_wheel_changes_speed, "Scene view");
}

void SceneView::toggleProjection() {
Expand Down Expand Up @@ -1062,18 +1063,24 @@ void SceneView::update(float time_delta)

if (ImGui::IsAnyItemActive()) return;
if (!m_is_mouse_captured) return;
if (ImGui::GetIO().KeyCtrl) return;
if (io.KeyCtrl) return;

int screen_x = int(ImGui::GetIO().MousePos.x);
int screen_y = int(ImGui::GetIO().MousePos.y);
int screen_x = int(io.MousePos.x);
int screen_y = int(io.MousePos.y);
bool is_inside = screen_x >= m_screen_x && screen_y >= m_screen_y && screen_x <= m_screen_x + m_width &&
screen_y <= m_screen_y + m_height;
if (!is_inside) return;

m_camera_speed = maximum(0.01f, m_camera_speed + ImGui::GetIO().MouseWheel / 20.0f);
if (m_mouse_wheel_changes_speed) {
m_camera_speed = maximum(0.01f, m_camera_speed + io.MouseWheel / 20.0f);
}
else {
if (io.MouseWheel > 0) m_view->moveCamera(1.0f, 0, 0, io.MouseWheel);
if (io.MouseWheel < 0) m_view->moveCamera(-1.0f, 0, 0, -io.MouseWheel);
}

float speed = m_camera_speed * time_delta * 60.f;
if (ImGui::GetIO().KeyShift) speed *= 10;
if (io.KeyShift) speed *= 10;
const CommonActions& actions = m_app.getCommonActions();
if (actions.cam_forward.isActive()) m_view->moveCamera(1.0f, 0, 0, speed);
if (actions.cam_backward.isActive()) m_view->moveCamera(-1.0f, 0, 0, speed);
Expand Down
1 change: 1 addition & 0 deletions src/renderer/editor/scene_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct SceneView : StudioApp::GUIPlugin
UniquePtr<Pipeline> m_camera_preview_pipeline;
LogUI& m_log_ui;
bool m_show_camera_preview = true;
bool m_mouse_wheel_changes_speed = true;

WorldEditor& m_editor;
struct WorldViewImpl* m_view;
Expand Down

0 comments on commit 96ecf1a

Please sign in to comment.