Browse Source

Add setTransform, translate, rotate, and scale functions for entities

master
C. J. Howard 5 years ago
parent
commit
ef8c21ee2d
Signed by: cjhoward GPG Key ID: 03E1FABA9C3EC195
2 changed files with 48 additions and 0 deletions
  1. +44
    -0
      src/game.cpp
  2. +4
    -0
      src/game.hpp

+ 44
- 0
src/game.cpp View File

@ -3646,6 +3646,17 @@ void Game::removeComponent(EntityID entity, ComponentType type)
delete component; delete component;
} }
void Game::setTransform(EntityID entity, const Transform& transform)
{
TransformComponent* component = componentManager->getComponent<TransformComponent>(entity);
if (!component)
{
return;
}
component->transform = transform;
}
void Game::setTranslation(EntityID entity, const Vector3& translation) void Game::setTranslation(EntityID entity, const Vector3& translation)
{ {
TransformComponent* component = componentManager->getComponent<TransformComponent>(entity); TransformComponent* component = componentManager->getComponent<TransformComponent>(entity);
@ -3679,6 +3690,39 @@ void Game::setScale(EntityID entity, const Vector3& scale)
component->transform.scale = scale; component->transform.scale = scale;
} }
void Game::translate(EntityID entity, const Vector3& translation)
{
TransformComponent* component = componentManager->getComponent<TransformComponent>(entity);
if (!component)
{
return;
}
component->transform.translation += translation;
}
void Game::rotate(EntityID entity, const Quaternion& rotation)
{
TransformComponent* component = componentManager->getComponent<TransformComponent>(entity);
if (!component)
{
return;
}
component->transform.rotation = component->transform.rotation * rotation;
}
void Game::scale(EntityID entity, const Vector3& scale)
{
TransformComponent* component = componentManager->getComponent<TransformComponent>(entity);
if (!component)
{
return;
}
component->transform.scale *= scale;
}
void Game::setTerrainPatchPosition(EntityID entity, const std::tuple<int, int>& position) void Game::setTerrainPatchPosition(EntityID entity, const std::tuple<int, int>& position)
{ {
TerrainPatchComponent* component = componentManager->getComponent<TerrainPatchComponent>(entity); TerrainPatchComponent* component = componentManager->getComponent<TerrainPatchComponent>(entity);

+ 4
- 0
src/game.hpp View File

@ -226,9 +226,13 @@ public:
void destroyInstance(EntityID entity); void destroyInstance(EntityID entity);
void addComponent(EntityID entity, ComponentBase* component); void addComponent(EntityID entity, ComponentBase* component);
void removeComponent(EntityID entity, ComponentType type); void removeComponent(EntityID entity, ComponentType type);
void setTransform(EntityID entity, const Transform& transform);
void setTranslation(EntityID entity, const Vector3& translation); void setTranslation(EntityID entity, const Vector3& translation);
void setRotation(EntityID entity, const Quaternion& rotation); void setRotation(EntityID entity, const Quaternion& rotation);
void setScale(EntityID entity, const Vector3& scale); 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<int, int>& position); void setTerrainPatchPosition(EntityID entity, const std::tuple<int, int>& position);
void boxSelect(float x, float y, float w, float h); void boxSelect(float x, float y, float w, float h);

Loading…
Cancel
Save