diff options
author | rtk0c <[email protected]> | 2022-05-06 19:52:12 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-05-06 19:52:12 -0700 |
commit | cde94efdd44553f3f6575ce84b44c6799e1a1425 (patch) | |
tree | 593b9f280f2e223268f8d5c73f5d1dd1aba50c36 /source/App.cpp | |
parent | 4c9f5ee706faa1435b7dc2f3b6d4753e1289c351 (diff) |
Changeset: 22 Improved camera and various cleanups
Diffstat (limited to 'source/App.cpp')
-rw-r--r-- | source/App.cpp | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/source/App.cpp b/source/App.cpp index 9c18fea..421adb5 100644 --- a/source/App.cpp +++ b/source/App.cpp @@ -1,8 +1,12 @@ #include "App.hpp" +#include <string> #include <utility> -App::App() { +using namespace std::literals; + +App::App() + : mActiveCamera{ &mMainCamera } { auto& worldRoot = mWorld.GetRoot(); constexpr int kPlayerCount = 2; @@ -19,18 +23,27 @@ App::App() { SetGameRunning(true); #endif - // TODO this renders nothing, fix - mGameCamera.Move(glm::vec3(0, 0, 1)); - mGameCamera.LookAt(glm::vec3(0, 0, 0)); - mGameCamera.SetHasPerspective(false); - mEditorCamera.Move(glm::vec3(0, 0, 1)); - mEditorCamera.LookAt(glm::vec3(0, 0, 0)); - mEditorCamera.SetHasPerspective(false); + mMainCamera.name = "Main Camera"s; + mMainCamera.Move(glm::vec3(0, 0, 1)); + mMainCamera.LookAt(glm::vec3(0, 0, 0)); + mMainCamera.SetHasPerspective(false); } App::~App() { } +Camera* App::GetActiveCamera() const { + return mActiveCamera; +} + +void App::BindActiveCamera(Camera* camera) { + mActiveCamera = camera; +} + +void App::UnbindActiveCamera() { + mActiveCamera = &mMainCamera; +} + bool App::IsGameRunning() const { return mGameRunning; } @@ -70,18 +83,11 @@ void App::Show() { void App::Update() { if (IsGameRunning()) { mWorld.Update(); - mEditor->OnUpdate(); } } void App::Draw(float currentTime, float deltaTime) { - Camera* camera; - if (IsGameRunning()) { - camera = &mGameCamera; - } else { - camera = &mEditorCamera; - } - mRenderer.BeginFrame(*camera, currentTime, deltaTime); + mWorldRenderer.BeginFrame(*mActiveCamera, currentTime, deltaTime); PodVector<GameObject*> stack; stack.push_back(&mWorld.GetRoot()); @@ -95,12 +101,10 @@ void App::Draw(float currentTime, float deltaTime) { } auto renderObjects = obj->GetRenderObjects(); - mRenderer.Draw(renderObjects.data(), renderObjects.size()); + mWorldRenderer.Draw(renderObjects.data(), renderObjects.size()); } - mRenderer.EndFrame(); - // TODO pass camera info to editor without strong coupling to Renderer - mEditor->OnDraw(mRenderer.GetLastFrameInfo()); + mWorldRenderer.EndFrame(); } void App::HandleMouse(int button, int action) { |