diff --git a/src/game.cpp b/src/game.cpp index 93ec755..4149af9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3646,6 +3646,17 @@ void Game::removeComponent(EntityID entity, ComponentType type) delete component; } +void Game::setTransform(EntityID entity, const Transform& transform) +{ + TransformComponent* component = componentManager->getComponent(entity); + if (!component) + { + return; + } + + component->transform = transform; +} + void Game::setTranslation(EntityID entity, const Vector3& translation) { TransformComponent* component = componentManager->getComponent(entity); @@ -3679,6 +3690,39 @@ void Game::setScale(EntityID entity, const Vector3& scale) component->transform.scale = scale; } +void Game::translate(EntityID entity, const Vector3& translation) +{ + TransformComponent* component = componentManager->getComponent(entity); + if (!component) + { + return; + } + + component->transform.translation += translation; +} + +void Game::rotate(EntityID entity, const Quaternion& rotation) +{ + TransformComponent* component = componentManager->getComponent(entity); + if (!component) + { + return; + } + + component->transform.rotation = component->transform.rotation * rotation; +} + +void Game::scale(EntityID entity, const Vector3& scale) +{ + TransformComponent* component = componentManager->getComponent(entity); + if (!component) + { + return; + } + + component->transform.scale *= scale; +} + void Game::setTerrainPatchPosition(EntityID entity, const std::tuple& position) { TerrainPatchComponent* component = componentManager->getComponent(entity); diff --git a/src/game.hpp b/src/game.hpp index 4f28b8e..1ce48b8 100644 --- a/src/game.hpp +++ b/src/game.hpp @@ -226,9 +226,13 @@ public: void destroyInstance(EntityID entity); void addComponent(EntityID entity, ComponentBase* component); void removeComponent(EntityID entity, ComponentType type); + void setTransform(EntityID entity, const Transform& transform); void setTranslation(EntityID entity, const Vector3& translation); void setRotation(EntityID entity, const Quaternion& rotation); void setScale(EntityID entity, const Vector3& scale); + void translate(EntityID entity, const Vector3& translation); + void rotate(EntityID entity, const Quaternion& rotation); + void scale(EntityID entity, const Vector3& scale); void setTerrainPatchPosition(EntityID entity, const std::tuple& position); void boxSelect(float x, float y, float w, float h);