Skip to content

Commit

Permalink
can adjust camera move speed by holding right mouse button and scroll (
Browse files Browse the repository at this point in the history
…#140)

* can adjust camera move speed by holding right mouse button and scroll

* fix the coding style

* coding style

Co-authored-by: Shuyan Hu <[email protected]>
Co-authored-by: Olorin <[email protected]>
  • Loading branch information
3 people authored Apr 26, 2022
1 parent 91edfa9 commit 78e37ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions engine/source/editor/include/editor_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace Pilot
Vector2 m_engine_window_size {1280.0f, 768.0f};
float m_mouse_x {0.0f};
float m_mouse_y {0.0f};
float m_camera_speed {0.05f};

bool m_is_editor_mode {true};
int m_key_state {0};
Expand Down
27 changes: 24 additions & 3 deletions engine/source/editor/source/editor_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Pilot
Pilot::Quaternion& values,
float resetValue = 0.0f,
float columnWidth = 100.0f);

EditorUI::EditorUI(PilotEditor* editor) : m_editor(editor)
{
Path& path_service = Path::getInstance();
Expand Down Expand Up @@ -690,6 +691,11 @@ namespace Pilot
{
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Press Left Alt key to display the mouse cursor!");
}
else
{
ImGui::TextColored(
ImVec4(0.0f, 1.0f, 0.0f, 1.0f), "Current editor camera move speed: [%f]", m_camera_speed);
}

auto menu_bar_rect = ImGui::GetCurrentWindow()->MenuBarRect();

Expand Down Expand Up @@ -877,7 +883,7 @@ namespace Pilot

void EditorUI::processEditorCommand()
{
float camera_speed = 0.05f;
float camera_speed = m_camera_speed;
Quaternion camera_rotate = m_tmp_uistate->m_editor_camera->rotation().inverse();
Vector3 camera_relative_pos(0, 0, 0);

Expand Down Expand Up @@ -977,10 +983,25 @@ namespace Pilot
{
return;
}
// wheel scrolled up = zoom in by 2 extra degrees

if (isCursorInRect(m_engine_window_pos, m_engine_window_size))
{
m_tmp_uistate->m_editor_camera->zoom((float)yoffset * 2.0f);
if (m_io->isMouseButtonDown(GLFW_MOUSE_BUTTON_RIGHT))
{
if (yoffset > 0)
{
m_camera_speed *= 1.2f;
}
else
{
m_camera_speed *= 0.8f;
}
}
else
{
m_tmp_uistate->m_editor_camera->zoom((float)yoffset *
2.0f); // wheel scrolled up = zoom in by 2 extra degrees
}
}
}

Expand Down

0 comments on commit 78e37ad

Please sign in to comment.