修复三维控件和模型出现偏移问题
This commit is contained in:
@ -41,11 +41,16 @@ namespace Hazel
|
|||||||
m_PlayIcon = Texture2D::Create("Resources/Icons/PlayButton.png");
|
m_PlayIcon = Texture2D::Create("Resources/Icons/PlayButton.png");
|
||||||
m_StopIcon = Texture2D::Create("Resources/Icons/PauseButton.png");
|
m_StopIcon = Texture2D::Create("Resources/Icons/PauseButton.png");
|
||||||
|
|
||||||
m_ActiveScene = CreateRef<Scene>();
|
m_EditorScene = CreateRef<Scene>();
|
||||||
|
m_EditorScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
||||||
|
m_ActiveScene = m_EditorScene;
|
||||||
|
|
||||||
m_EditorCamera = EditorCamera(45.0f, 1.667f, 0.1f, 1000.0f);
|
m_EditorCamera = EditorCamera(45.0f, 1.667f, 0.1f, 1000.0f);
|
||||||
|
|
||||||
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
||||||
|
|
||||||
|
m_GizmoType = ImGuizmo::OPERATION::TRANSLATE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorLayer::OnDetech()
|
void EditorLayer::OnDetech()
|
||||||
@ -159,7 +164,7 @@ namespace Hazel
|
|||||||
// any change of dockspace/settings would lead to windows being stuck in limbo and never being visible.
|
// any change of dockspace/settings would lead to windows being stuck in limbo and never being visible.
|
||||||
if (!opt_padding)
|
if (!opt_padding)
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||||
ImGui::Begin("DockSpace Demo", &dockspaceOpen, window_flags);
|
ImGui::Begin("DockSpace", &dockspaceOpen, window_flags);
|
||||||
if (!opt_padding)
|
if (!opt_padding)
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
@ -169,7 +174,7 @@ namespace Hazel
|
|||||||
// Submit the DockSpace
|
// Submit the DockSpace
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.WindowMinSize.x = 350.0f;
|
style.WindowMinSize.x = 364.0f;
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
|
if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
|
||||||
{
|
{
|
||||||
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
|
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
|
||||||
@ -189,6 +194,8 @@ namespace Hazel
|
|||||||
NewScene();
|
NewScene();
|
||||||
if (ImGui::MenuItem("Open...", "Ctrl+O"))
|
if (ImGui::MenuItem("Open...", "Ctrl+O"))
|
||||||
OpenScene();
|
OpenScene();
|
||||||
|
if (ImGui::MenuItem("Save", "Ctrl+S", false, m_ActiveScene ? true : false))
|
||||||
|
SaveScene();
|
||||||
if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S"))
|
if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S"))
|
||||||
SaveSceneAs();
|
SaveSceneAs();
|
||||||
|
|
||||||
@ -234,7 +241,7 @@ namespace Hazel
|
|||||||
// ViewPort
|
// ViewPort
|
||||||
{
|
{
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0.0f, 0.0f});
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0.0f, 0.0f});
|
||||||
ImGui::Begin("Viewport");
|
ImGui::Begin("Viewport", nullptr, ImGuiWindowFlags_NoCollapse);
|
||||||
auto viewportOffet = ImGui::GetCursorPos();
|
auto viewportOffet = ImGui::GetCursorPos();
|
||||||
m_ViewportFocused = ImGui::IsWindowFocused();
|
m_ViewportFocused = ImGui::IsWindowFocused();
|
||||||
m_ViewportHovered = ImGui::IsWindowHovered();
|
m_ViewportHovered = ImGui::IsWindowHovered();
|
||||||
@ -248,6 +255,8 @@ namespace Hazel
|
|||||||
// ImGui::Text("Viewport: (%.2f, %.2f)", viewPortPanelSize.x, viewPortPanelSize.y);
|
// ImGui::Text("Viewport: (%.2f, %.2f)", viewPortPanelSize.x, viewPortPanelSize.y);
|
||||||
ImGui::Image(m_FrameBuffer->GetColorAttachmentID(), {m_ViewPortSize.x, m_ViewPortSize.y}, {0, 1},
|
ImGui::Image(m_FrameBuffer->GetColorAttachmentID(), {m_ViewPortSize.x, m_ViewPortSize.y}, {0, 1},
|
||||||
{1, 0});
|
{1, 0});
|
||||||
|
const ImVec2 &viewPortMin = ImGui::GetItemRectMin(); // left-top pos
|
||||||
|
const ImVec2 &viewPortMax = ImGui::GetItemRectMax(); // right-buttom pos
|
||||||
|
|
||||||
if (ImGui::BeginDragDropTarget())
|
if (ImGui::BeginDragDropTarget())
|
||||||
{
|
{
|
||||||
@ -277,13 +286,8 @@ namespace Hazel
|
|||||||
ImGuizmo::SetOrthographic(false);
|
ImGuizmo::SetOrthographic(false);
|
||||||
ImGuizmo::SetDrawlist();
|
ImGuizmo::SetDrawlist();
|
||||||
|
|
||||||
const float windowWidth = ImGui::GetWindowWidth();
|
|
||||||
const float windowHeight = ImGui::GetWindowHeight();
|
|
||||||
|
|
||||||
ImVec2 windowPos = ImGui::GetWindowPos();
|
ImGuizmo::SetRect(viewPortMin.x, viewPortMin.y, viewPortMax.x - viewPortMin.x, viewPortMax.y - viewPortMin.y);
|
||||||
windowPos.y += m_ViewPortSize.y - windowsSize.y;
|
|
||||||
|
|
||||||
ImGuizmo::SetRect(windowPos.x, windowPos.y, windowWidth, windowHeight);
|
|
||||||
|
|
||||||
if (m_GizmoType != -1)
|
if (m_GizmoType != -1)
|
||||||
{
|
{
|
||||||
@ -418,7 +422,7 @@ namespace Hazel
|
|||||||
|
|
||||||
void EditorLayer::OnScenePlay()
|
void EditorLayer::OnScenePlay()
|
||||||
{
|
{
|
||||||
SaveScene();
|
// SaveScene();
|
||||||
m_SceneState = SceneState::Play;
|
m_SceneState = SceneState::Play;
|
||||||
|
|
||||||
m_ActiveScene = Scene::Copy(m_EditorScene);
|
m_ActiveScene = Scene::Copy(m_EditorScene);
|
||||||
|
|||||||
Reference in New Issue
Block a user