Basic input handling, Editor camera Movement
This commit is contained in:
		| @ -7,7 +7,6 @@ | ||||
| std::vector<Asset> AssetManager::assets; | ||||
| std::filesystem::path AssetManager::currentPath; | ||||
|  | ||||
|  | ||||
| void AssetManager::Init()  | ||||
| {  | ||||
| 	assets = std::vector<Asset>(); | ||||
| @ -38,7 +37,6 @@ void AssetManager::setAssetPath(std::filesystem::path path) | ||||
| 	currentPath = path;  | ||||
| } | ||||
|  | ||||
|  | ||||
| YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path assetPath) | ||||
| { | ||||
| 	YoggieEngine::Mesh* imported = nullptr; | ||||
| @ -147,4 +145,4 @@ YoggieEngine::Renderable* AssetManager::LoadFromSource(const std::filesystem::pa | ||||
|  | ||||
| 	return model->renderable; | ||||
|  | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -6,9 +6,6 @@ class EditorWindow { | ||||
|  | ||||
| public: | ||||
| 	EditorWindow(const std::string& name, ImGuiWindowFlags_ flags = ImGuiWindowFlags_None ) { ImGui::Begin(name.c_str(), false ,flags); } | ||||
| 	 | ||||
| 	 | ||||
|  | ||||
| 	~EditorWindow() { ImGui::End(); } | ||||
|  | ||||
| }; | ||||
| @ -16,7 +16,6 @@ public: | ||||
| 		io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable; | ||||
| 		io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18); | ||||
|  | ||||
|  | ||||
| 		ImGui::StyleColorsDark(); | ||||
|  | ||||
| 		ImGui_ImplGlfw_InitForOpenGL(window.GetGLFWHandle(), true); | ||||
|  | ||||
| @ -151,14 +151,25 @@ public: | ||||
|          | ||||
|         glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix); | ||||
|          | ||||
|         ImGuizmo::ViewManipulate(glm::value_ptr(transposed_view), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC); | ||||
|         ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f); | ||||
|        | ||||
|         ImGuizmo::ViewManipulate(glm::value_ptr(transposed_view), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC); | ||||
|         | ||||
|         // Matrix is the model matrix we would want to manipulate | ||||
|         //ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix)); | ||||
|  | ||||
|         if (ImGui::IsWindowFocused() )  | ||||
|         { | ||||
|             isFocused = true; | ||||
|  | ||||
|         } | ||||
|         else { | ||||
|             isFocused = false; | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     bool isFocused = false; | ||||
|  | ||||
| }; | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -22,9 +22,10 @@ RendererConfig EditorSceneRendererConfig{ | ||||
|     glm::vec3{0,0,0}, // Clear Color | ||||
|     true // Depth testing   | ||||
| }; | ||||
|  | ||||
| glm::vec3 temp = glm::vec3(0); | ||||
| Camera cam = Camera(glm::vec3(14.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90); | ||||
|  | ||||
|  | ||||
| class Editor : public Application { | ||||
| public: | ||||
|     Editor()  | ||||
| @ -35,6 +36,8 @@ public: | ||||
|         EditorGUIRenderer(AppWindow), | ||||
|         Selected((entt::entity)-1) | ||||
|     { | ||||
|  | ||||
|         init_inputSystem(&AppWindow); | ||||
|         viewportRenderer.setCurrentFrameBuffer(*framebuffer); | ||||
|     } | ||||
|  | ||||
| @ -71,6 +74,74 @@ public: | ||||
|  | ||||
|         { | ||||
|             Viewport sceneview = Viewport(*framebuffer, viewportRenderer.getCamera()); | ||||
|             if (sceneview.isFocused)  | ||||
|             { | ||||
|                 const float movement_speed = 0.1f; | ||||
|                 static float lastX = 400, lastY = 300; | ||||
|                 const float sensitivity = 0.1; | ||||
|                 static bool firstMouse = true; | ||||
|  | ||||
|  | ||||
|                 if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_MIDDLE) ){ | ||||
|             | ||||
|  | ||||
|                     auto newX = getCursorPosX(&AppWindow); | ||||
|                     auto newY = getCursorPosY(&AppWindow); | ||||
|  | ||||
|  | ||||
|                     if (firstMouse) | ||||
|                     { | ||||
|                         lastX = newX; | ||||
|                         lastY = newY; | ||||
|                         firstMouse = false; | ||||
|                     } | ||||
|  | ||||
|  | ||||
|                     float xoffset = newX - lastX; | ||||
|                     float yoffset = newY - lastY; | ||||
|  | ||||
|                     lastX = newX; | ||||
|                     lastY = newY; | ||||
|  | ||||
|                     xoffset *= sensitivity; | ||||
|                     yoffset *= sensitivity; | ||||
|  | ||||
|                     cam.yaw += xoffset; | ||||
|                     cam.pitch += yoffset; | ||||
|  | ||||
|                     if (cam.pitch > 89.0f) | ||||
|                         cam.pitch = 89.0f; | ||||
|                     if (cam.pitch < -89.0f) | ||||
|                         cam.pitch = -89.0f; | ||||
|  | ||||
|                 } | ||||
|                  | ||||
|  | ||||
|                 // Check for Camara movement input here! | ||||
|                 if (keyIsPressed(YOGGIE_KEY_W)) { | ||||
|                     cam.Position += cam.Front * movement_speed; | ||||
|                 } | ||||
|  | ||||
|                 if (keyIsPressed(YOGGIE_KEY_A)) | ||||
|                 { | ||||
|                     cam.Position -= cam.Right * movement_speed; | ||||
|  | ||||
|                 } | ||||
|  | ||||
|                 if (keyIsPressed(YOGGIE_KEY_S)) { | ||||
|                     cam.Position -= cam.Front * movement_speed; | ||||
|  | ||||
|                 } | ||||
|  | ||||
|                 if (keyIsPressed(YOGGIE_KEY_D)) { | ||||
|                     cam.Position += cam.Right * movement_speed; | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|             } | ||||
|  | ||||
|         } | ||||
|  | ||||
|         { | ||||
| @ -136,7 +207,7 @@ public: | ||||
|             lag += elapsed; | ||||
|  | ||||
|             AppWindow.Poll(); | ||||
|  | ||||
|             cam.Update(); | ||||
|              | ||||
|             Physics.Step(elapsed); | ||||
|             ActiveScene.Update(); | ||||
| @ -170,6 +241,8 @@ private: | ||||
|     bool SimulatePhysics = true; | ||||
|     entt::entity  Selected; | ||||
|  | ||||
|  | ||||
|  | ||||
|     std::unique_ptr<Project> CurrentProject; | ||||
|     Scene ActiveScene; | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user