diff --git a/Engine/include/engine/graphics/shapes/gameobject.hpp b/Engine/include/engine/graphics/shapes/gameobject.hpp index 847d3a16..503980e5 100644 --- a/Engine/include/engine/graphics/shapes/gameobject.hpp +++ b/Engine/include/engine/graphics/shapes/gameobject.hpp @@ -220,6 +220,7 @@ namespace Graphics::Shape void SetParent(const shared_ptr& newParent) { parent = newParent; } void SetChild(const shared_ptr& newChild) { child = newChild; } void SetParentBillboardHolder(const shared_ptr& newParentBillboardHolder) { parentBillboardHolder = newParentBillboardHolder; } + void SetChildBillboard(const shared_ptr& newChildBillboard) { childBillboard = newChildBillboard; } const bool& IsInitialized() const { return isInitialized; } const string& GetName() const { return name; } @@ -235,6 +236,7 @@ namespace Graphics::Shape const shared_ptr& GetParent() const { return parent; } const shared_ptr& GetChild() const { return child; } const shared_ptr& GetParentBillboardHolder() const { return parentBillboardHolder; } + const shared_ptr& GetChildBillboard() const { return childBillboard; } private: bool isInitialized; string name; @@ -250,6 +252,7 @@ namespace Graphics::Shape shared_ptr parent; shared_ptr child; shared_ptr parentBillboardHolder; + shared_ptr childBillboard; }; class GameObjectManager diff --git a/Engine/src/engine/core/input.cpp b/Engine/src/engine/core/input.cpp index f331f139..b61ff137 100644 --- a/Engine/src/engine/core/input.cpp +++ b/Engine/src/engine/core/input.cpp @@ -160,13 +160,15 @@ namespace Core Render::camera.cameraPos += inputSettings.cameraSpeed * currentSpeed * right); } //camera up - if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) + if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS + || glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { Render::camera.SetCameraPosition( Render::camera.cameraPos += inputSettings.cameraUp * inputSettings.cameraSpeed * currentSpeed); } //camera down - if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) + if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS + || glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) { Render::camera.SetCameraPosition( Render::camera.cameraPos -= inputSettings.cameraUp * inputSettings.cameraSpeed * currentSpeed); diff --git a/Engine/src/engine/graphics/shapes/billboard.cpp b/Engine/src/engine/graphics/shapes/billboard.cpp index c0387181..2b9c4826 100644 --- a/Engine/src/engine/graphics/shapes/billboard.cpp +++ b/Engine/src/engine/graphics/shapes/billboard.cpp @@ -130,7 +130,6 @@ namespace Graphics::Shape mat4 model = mat4(1.0f); - shared_ptr parent = obj->GetParentBillboardHolder(); vec3 pos = obj->GetParentBillboardHolder()->GetTransform()->GetPosition(); obj->GetTransform()->SetPosition(pos); diff --git a/Engine/src/engine/graphics/shapes/gameobject.cpp b/Engine/src/engine/graphics/shapes/gameobject.cpp index 5dbb8c46..4a1424b0 100644 --- a/Engine/src/engine/graphics/shapes/gameobject.cpp +++ b/Engine/src/engine/graphics/shapes/gameobject.cpp @@ -252,15 +252,29 @@ namespace Graphics::Shape void GameObjectManager::DestroyGameObject(const shared_ptr& obj) { - auto gameobject = remove(objects.begin(), objects.end(), obj); - objects.erase(gameobject, objects.end()); - - //if gameobject is in pointlights vector - auto pointLight = remove(pointLights.begin(), pointLights.end(), obj); - pointLights.erase(pointLight, pointLights.end()); - - //if gameobject is in spotlights vector - auto spotLight = remove(spotLights.begin(), spotLights.end(), obj); - spotLights.erase(spotLight, spotLights.end()); + Type type = obj->GetMesh()->GetMeshType(); + switch (type) + { + case Type::cube: + objects.erase(remove(objects.begin(), objects.end(), obj), objects.end()); + break; + case Type::point_light: + DestroyGameObject(obj->GetChildBillboard()); + obj->SetChildBillboard(nullptr); + objects.erase(remove(objects.begin(), objects.end(), obj), objects.end()); + pointLights.erase(remove(pointLights.begin(), pointLights.end(), obj), pointLights.end()); + break; + case Type::spot_light: + DestroyGameObject(obj->GetChildBillboard()); + obj->SetChildBillboard(nullptr); + objects.erase(remove(objects.begin(), objects.end(), obj), objects.end()); + spotLights.erase(remove(spotLights.begin(), spotLights.end(), obj), spotLights.end()); + break; + case Type::billboard: + obj->SetParentBillboardHolder(nullptr); + objects.erase(remove(objects.begin(), objects.end(), obj), objects.end()); + billboards.erase(remove(billboards.begin(), billboards.end(), obj), billboards.end()); + break; + } } } \ No newline at end of file diff --git a/Engine/src/engine/graphics/shapes/pointlight.cpp b/Engine/src/engine/graphics/shapes/pointlight.cpp index 3e54a637..29a726af 100644 --- a/Engine/src/engine/graphics/shapes/pointlight.cpp +++ b/Engine/src/engine/graphics/shapes/pointlight.cpp @@ -135,6 +135,7 @@ namespace Graphics::Shape textures); billboard->SetParentBillboardHolder(obj); + obj->SetChildBillboard(billboard); GameObjectManager::AddGameObject(obj); GameObjectManager::AddPointLight(obj); diff --git a/Engine/src/engine/graphics/shapes/spotlight.cpp b/Engine/src/engine/graphics/shapes/spotlight.cpp index a5b442f4..616c7bc8 100644 --- a/Engine/src/engine/graphics/shapes/spotlight.cpp +++ b/Engine/src/engine/graphics/shapes/spotlight.cpp @@ -127,6 +127,7 @@ namespace Graphics::Shape textures); billboard->SetParentBillboardHolder(obj); + obj->SetChildBillboard(billboard); GameObjectManager::AddGameObject(obj); GameObjectManager::AddSpotLight(obj);