Skip to content

Commit

Permalink
fixed billboard not being deleted along with light
Browse files Browse the repository at this point in the history
  • Loading branch information
greeenlaser committed Feb 4, 2024
1 parent 2ad6c8b commit e95f820
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Engine/include/engine/graphics/shapes/gameobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ namespace Graphics::Shape
void SetParent(const shared_ptr<GameObject>& newParent) { parent = newParent; }
void SetChild(const shared_ptr<GameObject>& newChild) { child = newChild; }
void SetParentBillboardHolder(const shared_ptr<GameObject>& newParentBillboardHolder) { parentBillboardHolder = newParentBillboardHolder; }
void SetChildBillboard(const shared_ptr<GameObject>& newChildBillboard) { childBillboard = newChildBillboard; }

const bool& IsInitialized() const { return isInitialized; }
const string& GetName() const { return name; }
Expand All @@ -235,6 +236,7 @@ namespace Graphics::Shape
const shared_ptr<GameObject>& GetParent() const { return parent; }
const shared_ptr<GameObject>& GetChild() const { return child; }
const shared_ptr<GameObject>& GetParentBillboardHolder() const { return parentBillboardHolder; }
const shared_ptr<GameObject>& GetChildBillboard() const { return childBillboard; }
private:
bool isInitialized;
string name;
Expand All @@ -250,6 +252,7 @@ namespace Graphics::Shape
shared_ptr<GameObject> parent;
shared_ptr<GameObject> child;
shared_ptr<GameObject> parentBillboardHolder;
shared_ptr<GameObject> childBillboard;
};

class GameObjectManager
Expand Down
6 changes: 4 additions & 2 deletions Engine/src/engine/core/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion Engine/src/engine/graphics/shapes/billboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ namespace Graphics::Shape

mat4 model = mat4(1.0f);

shared_ptr<GameObject> parent = obj->GetParentBillboardHolder();
vec3 pos = obj->GetParentBillboardHolder()->GetTransform()->GetPosition();
obj->GetTransform()->SetPosition(pos);

Expand Down
34 changes: 24 additions & 10 deletions Engine/src/engine/graphics/shapes/gameobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,29 @@ namespace Graphics::Shape

void GameObjectManager::DestroyGameObject(const shared_ptr<GameObject>& 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;
}
}
}
1 change: 1 addition & 0 deletions Engine/src/engine/graphics/shapes/pointlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ namespace Graphics::Shape
textures);

billboard->SetParentBillboardHolder(obj);
obj->SetChildBillboard(billboard);

GameObjectManager::AddGameObject(obj);
GameObjectManager::AddPointLight(obj);
Expand Down
1 change: 1 addition & 0 deletions Engine/src/engine/graphics/shapes/spotlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ namespace Graphics::Shape
textures);

billboard->SetParentBillboardHolder(obj);
obj->SetChildBillboard(billboard);

GameObjectManager::AddGameObject(obj);
GameObjectManager::AddSpotLight(obj);
Expand Down

0 comments on commit e95f820

Please sign in to comment.