Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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