10#include <glm/gtc/type_ptr.hpp>
19void Elevate::Editor::ScenePanel::OnImGuiRender()
21 ImGui::Begin(
"Scene View",
nullptr, ImGuiWindowFlags_MenuBar);
23 if (ImGui::BeginMenuBar())
28 ImGui::RadioButton(
"Translate", &m_CurrentEditorTool, 7);
29 ImGui::RadioButton(
"Rotate", &m_CurrentEditorTool, 120);
30 ImGui::RadioButton(
"Scale", &m_CurrentEditorTool, 896);
31 ImGui::RadioButton(
"Universal", &m_CurrentEditorTool, 14463);
36 if (ImGui::Button(
"Edit"))
42 ImGui::Dummy(ImVec2(ImGui::GetWindowSize().x - ImGui::CalcTextSize(
"XXX:XXX").x - ImGui::GetCursorPos().x - 10.0f, 0.0f));
45 if (ImGui::BeginMenu(GetAspectRatioText(s_AspectRatioSettings[m_AspectRatioValue]).c_str()))
47 for (
int i = 0; i <
sizeof(s_AspectRatioSettings) /
sizeof(s_AspectRatioSettings[0]); i++)
49 if (ImGui::RadioButton(GetAspectRatioText(s_AspectRatioSettings[i]).c_str(), &m_AspectRatioValue, i)) { UpdateViewportAspectRatio(); }
57 uint32_t window_width = (uint32_t) ImGui::GetContentRegionAvail().x;
58 uint32_t window_height = (uint32_t) ImGui::GetContentRegionAvail().y;
61 const glm::ivec2 aspect = s_AspectRatioSettings[m_AspectRatioValue];
62 const float arX = (float)aspect.x;
63 const float arY = (float)aspect.y;
64 const float qtX = window_width / arX;
65 const float qtY = window_height / arY;
67 window_height = (uint32_t)(qtX * arY);
69 window_width = (uint32_t)(qtY * arX);
72 Application::Get().FrameBuffer->Rescale(window_width, window_height);
73 Renderer::SetViewport(0, 0, window_width, window_height);
76 ImVec2 pos = ImGui::GetCursorScreenPos();
77 ImGui::Image((ImTextureID)Application::Get().FrameBuffer->GetNativeTextureHandle(), ImVec2((
float)window_width, (
float)window_height), ImVec2(0, 1), ImVec2(1, 0));
80 if (Application::GetGameState() == EditorMode)
82 std::weak_ptr<GameObject> selected = EditorLayer::Get().GetSelectedObject();
83 Camera* cam = EditorLayer::Get().GetCamera();
86 std::shared_ptr<GameObject> selectedShared = selected.lock();
87 ImGuizmo::SetDrawlist(ImGui::GetWindowDrawList());
88 ImGuizmo::SetOrthographic(
false);
89 ImGuizmo::SetRect(pos.x, pos.y, (
float)window_width, (
float)window_height);
91 glm::mat4 cameraProjection = cam->GetProjectionMatrix();
92 glm::mat4 cameraView = cam->GenViewMatrix();
93 glm::mat4 entityMatrix = selectedShared->GenGlobalMatrix();
97 glm::value_ptr(cameraView),
98 glm::value_ptr(cameraProjection),
99 (ImGuizmo::OPERATION)m_CurrentEditorTool,
101 glm::value_ptr(entityMatrix)
104 if (ImGuizmo::IsUsingAny())
106 selectedShared->SetFromGlobalMatrix(entityMatrix);
114void Elevate::Editor::ScenePanel::UpdateViewportAspectRatio()
116 Camera* cam = EditorLayer::Get().GetCamera();
117 const glm::ivec2 values = s_AspectRatioSettings[m_AspectRatioValue];
118 const float ratio = (float)values.x / (
float)values.y;
119 cam->UpdateAspectRatio(ratio);
122std::string Elevate::Editor::ScenePanel::GetAspectRatioText(glm::ivec2 ar)
124 return (std::to_string(ar.x) +
":" + std::to_string(ar.y));
std::string GuizmoOperationToString(int tool)