添加box2d库
This commit is contained in:
@ -38,6 +38,9 @@ namespace Hazel
|
||||
m_LogoTexture = Texture2D::Create("assets/textures/iceLogo.png");
|
||||
m_CheckerBoardTexture = Texture2D::Create("assets/textures/Checkerboard.png");
|
||||
|
||||
m_PlayIcon = Texture2D::Create("Resources/Icons/PlayButton.png");
|
||||
m_StopIcon = Texture2D::Create("Resources/Icons/PauseButton.png");
|
||||
|
||||
m_ActiveScene = CreateRef<Scene>();
|
||||
|
||||
m_EditorCamera = EditorCamera(45.0f, 1.667f, 0.1f, 1000.0f);
|
||||
@ -66,11 +69,6 @@ namespace Hazel
|
||||
}
|
||||
|
||||
// update camera
|
||||
if (m_ViewportFocused)
|
||||
{
|
||||
m_CameraController.OnUpdate(ts);
|
||||
m_EditorCamera.OnUpdate(ts);
|
||||
}
|
||||
|
||||
// update Renderer
|
||||
m_FrameBuffer->Bind();
|
||||
@ -79,10 +77,21 @@ namespace Hazel
|
||||
|
||||
m_FrameBuffer->ClearAttachment(1, -1);
|
||||
|
||||
// Renderer2D::BeginScene(m_CameraController.GetCamera());
|
||||
switch (m_SceneState)
|
||||
{
|
||||
case SceneState::Play:
|
||||
m_ActiveScene->OnUpdateRuntime(ts);
|
||||
break;
|
||||
case SceneState::Edit:
|
||||
if (m_ViewportFocused)
|
||||
m_CameraController.OnUpdate(ts);
|
||||
|
||||
// update Scene
|
||||
m_ActiveScene->OnUpdateEditor(ts, m_EditorCamera);
|
||||
m_EditorCamera.OnUpdate(ts);
|
||||
m_ActiveScene->OnUpdateEditor(ts, m_EditorCamera);
|
||||
break;
|
||||
}
|
||||
|
||||
// Renderer2D::BeginScene(m_CameraController.GetCamera());
|
||||
|
||||
auto [mx, my] = ImGui::GetMousePos();
|
||||
mx -= m_ViewPortBounds[0].x;
|
||||
@ -275,17 +284,27 @@ namespace Hazel
|
||||
|
||||
ImGuizmo::SetRect(windowPos.x, windowPos.y, windowWidth, windowHeight);
|
||||
|
||||
// auto cameraEntity = m_ActiveScene->GetPrimaryCameraEntity();
|
||||
if (m_GizmoType != -1)
|
||||
{
|
||||
// const auto& camera = cameraEntity.GetComponent<CameraComponent>().Camera;
|
||||
|
||||
glm::mat4 cameraProjection;
|
||||
glm::mat4 cameraView;
|
||||
|
||||
if (m_SceneState == SceneState::Play)
|
||||
{
|
||||
auto cameraEntity = m_ActiveScene->GetPrimaryCameraEntity();
|
||||
const auto& camera = cameraEntity.GetComponent<CameraComponent>().Camera;
|
||||
|
||||
cameraProjection = camera.GetProjection();
|
||||
cameraView = glm::inverse(cameraEntity.GetComponent<TransformComponent>().GetTransform());
|
||||
}else if (m_SceneState == SceneState::Edit)
|
||||
{
|
||||
cameraProjection = m_EditorCamera.GetProjection();
|
||||
cameraView = m_EditorCamera.GetViewMatrix();
|
||||
}
|
||||
|
||||
auto& tc = selectedEntity.GetComponent<TransformComponent>();
|
||||
|
||||
|
||||
// const glm::mat4& cameraProjection = camera.GetProjection();
|
||||
// glm::mat4 cameraView = glm::inverse(cameraEntity.GetComponent<TransformComponent>().GetTransform());
|
||||
glm::mat4 cameraProjection = m_EditorCamera.GetProjection();
|
||||
glm::mat4 cameraView = m_EditorCamera.GetViewMatrix();
|
||||
glm::mat4 transform = tc.GetTransform();
|
||||
bool snap = SDL_GetModState() & SDL_KMOD_CTRL;
|
||||
float snapValue = 0.5f;
|
||||
@ -298,7 +317,7 @@ namespace Hazel
|
||||
|
||||
float snapValues[3] = {snapValue, snapValue, snapValue};
|
||||
if (ImGuizmo::Manipulate(glm::value_ptr(cameraView), glm::value_ptr(cameraProjection),
|
||||
ImGuizmo::OPERATION(m_GizmoType), ImGuizmo::LOCAL,
|
||||
static_cast<ImGuizmo::OPERATION>(m_GizmoType), ImGuizmo::WORLD,
|
||||
glm::value_ptr(transform), nullptr, snap ? snapValues : nullptr) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
|
||||
{
|
||||
if (ImGuizmo::IsUsing())
|
||||
@ -321,6 +340,9 @@ namespace Hazel
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
UI_ToolBar();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
@ -417,4 +439,51 @@ namespace Hazel
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::UI_ToolBar()
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 2));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0, 0));
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
||||
auto& colors = ImGui::GetStyle().Colors;
|
||||
auto& buttonHovered = colors[ImGuiCol_ButtonHovered];
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(buttonHovered.x, buttonHovered.y, buttonHovered.z, 0.5f));
|
||||
auto& buttonActive = colors[ImGuiCol_ButtonActive];
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(buttonActive.x, buttonActive.y, buttonActive.z, 0.5f));
|
||||
|
||||
|
||||
ImGui::Begin("##ToolBar", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
|
||||
// ImGui::Begin("##ToolBar", nullptr);
|
||||
|
||||
float size = ImGui::GetWindowHeight() - 10.0f;
|
||||
Ref<Texture2D> icon = m_SceneState == SceneState::Edit ? m_PlayIcon : m_StopIcon;
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x * 0.5f - size * 0.5f);
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x * 0.5f - (size * 0.5f));
|
||||
if (ImGui::ImageButton("toolbar", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||
{
|
||||
if (m_SceneState == SceneState::Edit)
|
||||
OnScenePlay();
|
||||
else if (m_SceneState == SceneState::Play)
|
||||
OnSceneStop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor(3);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void EditorLayer::OnScenePlay()
|
||||
{
|
||||
m_SceneState = SceneState::Play;
|
||||
m_ActiveScene->OnRuntimeStart();
|
||||
}
|
||||
|
||||
void EditorLayer::OnSceneStop()
|
||||
{
|
||||
m_SceneState = SceneState::Edit;
|
||||
m_ActiveScene->OnRuntimeStop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user