diff --git a/main b/main index 10cb084..4d97121 100755 Binary files a/main and b/main differ diff --git a/run.sh b/make.sh similarity index 100% rename from run.sh rename to make.sh diff --git a/src/WoopWoop/ECS/Components/Graphics/CircleRenderer.cpp b/src/WoopWoop/ECS/Components/Graphics/CircleRenderer.cpp index 9a584e0..07c3760 100644 --- a/src/WoopWoop/ECS/Components/Graphics/CircleRenderer.cpp +++ b/src/WoopWoop/ECS/Components/Graphics/CircleRenderer.cpp @@ -4,17 +4,17 @@ namespace wpwp { void CircleRenderer::start() { - m_circleShape = sf::CircleShape(entity->transform->scale.x); + m_circleShape = sf::CircleShape(entity->transform->getScale()->x); material.color = sf::Color::White; } void CircleRenderer::update() { - sf::Vector2f pos(entity->transform->globalPosition.x, entity->transform->globalPosition.y); + sf::Vector2f pos(entity->transform->getPosition()->x, entity->transform->getPosition()->y); m_circleShape.setPosition(pos); m_circleShape.setRadius(1); - m_circleShape.setScale(sf::Vector2f(entity->transform->scale.x, entity->transform->scale.y)); - m_circleShape.setRotation(entity->transform->rotation.z); + m_circleShape.setScale(sf::Vector2f(entity->transform->getScale()->x, entity->transform->getScale()->y)); + m_circleShape.setRotation(entity->transform->getRotation()->z); m_circleShape.setFillColor(material.color); wpwp::Engine::getInstance()->draw(m_circleShape); } diff --git a/src/WoopWoop/ECS/Components/Graphics/SpriteRenderer.cpp b/src/WoopWoop/ECS/Components/Graphics/SpriteRenderer.cpp index 045c4d7..d06e0a3 100644 --- a/src/WoopWoop/ECS/Components/Graphics/SpriteRenderer.cpp +++ b/src/WoopWoop/ECS/Components/Graphics/SpriteRenderer.cpp @@ -22,14 +22,14 @@ namespace wpwp { if (sprite.getTexture()) { - sf::Vector2f pos(entity->transform->globalPosition.x, entity->transform->globalPosition.y); + sf::Vector2f pos(entity->transform->getPosition()->x, entity->transform->getPosition()->y); // Calculate origin based on unscaled texture size - sprite.setScale(sf::Vector2f(entity->transform->scale.x / m_texture.getSize().x, - entity->transform->scale.y / m_texture.getSize().y)); + sprite.setScale(sf::Vector2f(entity->transform->getScale()->x / m_texture.getSize().x, + entity->transform->getScale()->y / m_texture.getSize().y)); - sprite.setRotation(entity->transform->rotation.z); + sprite.setRotation(entity->transform->getRotation()->z); sprite.setColor(material.color); sprite.setPosition(pos); unsigned int scalar = 2; diff --git a/src/WoopWoop/ECS/Components/Transform.hpp b/src/WoopWoop/ECS/Components/Transform.hpp index b90d244..3152dcf 100644 --- a/src/WoopWoop/ECS/Components/Transform.hpp +++ b/src/WoopWoop/ECS/Components/Transform.hpp @@ -14,9 +14,47 @@ namespace wpwp struct Transform : public Component { public: - sf::Vector3f globalPosition; // Global position of the entity. - sf::Vector3f scale = sf::Vector3f(1, 1, 1); // Scale of the entity. - sf::Vector3f rotation = sf::Vector3f(0, 0, 0); // Rotation of the entity. + /** + * @brief Gets the position of the transform. + * + * @return A pointer to the position vector. + */ + sf::Vector3f *getPosition() { return &m_globalPosition; } + + /** + * @brief Sets the position of the transform. + * + * @param position The new position vector. + */ + void setPosition(const sf::Vector3f &position) { m_globalPosition = position; } + + /** + * @brief Gets the rotation of the transform. + * + * @return A pointer to the rotation vector. + */ + sf::Vector3f *getRotation() { return &m_rotation; } + + /** + * @brief Sets the rotation of the transform. + * + * @param rotation The new rotation vector. + */ + void setRotation(const sf::Vector3f &rotation) { m_rotation = rotation; } + + /** + * @brief Gets the scale of the transform. + * + * @return A pointer to the scale vector. + */ + sf::Vector3f *getScale() { return &m_scale; } + + /** + * @brief Sets the scale of the transform. + * + * @param scale The new scale vector. + */ + void setScale(const sf::Vector3f &scale) { m_scale = scale; } /** * @brief Gets the name of the component. @@ -24,7 +62,12 @@ namespace wpwp * @return The name of the component. */ std::string getName() const override { return "Transform"; } + + private: + sf::Vector3f m_globalPosition; // Global position of the entity. + sf::Vector3f m_scale = sf::Vector3f(1, 1, 1); // Scale of the entity. + sf::Vector3f m_rotation = sf::Vector3f(0, 0, 0); // Rotation of the entity. }; } // namespace wpwp -#endif // TRANSFORM_HPP +#endif // TRANSFORM_HPP \ No newline at end of file diff --git a/src/WoopWoop/ECS/Enitiy.cpp b/src/WoopWoop/ECS/Enitiy.cpp index 6aac6ce..08c8d8c 100644 --- a/src/WoopWoop/ECS/Enitiy.cpp +++ b/src/WoopWoop/ECS/Enitiy.cpp @@ -13,8 +13,8 @@ namespace wpwp Entity::Entity(sf::Vector3f initialPosition) : transform(new Transform()) { this->transform = new Transform(); - transform->globalPosition = initialPosition; - transform->rotation = sf::Vector3f(0, 0, 0); + transform->setPosition(initialPosition); + transform->setRotation(sf::Vector3f(0, 0, 0)); this->m_components = std::vector(); } diff --git a/src/WoopWoop/Editor/Editor.cpp b/src/WoopWoop/Editor/Editor.cpp index c5064e3..1123e46 100644 --- a/src/WoopWoop/Editor/Editor.cpp +++ b/src/WoopWoop/Editor/Editor.cpp @@ -67,19 +67,19 @@ namespace wpwp::Editor if (selectedEntity) { ImGui::Text("Position: "); - ImGui::InputFloat("X", &selectedEntity->transform->globalPosition.x); - ImGui::InputFloat("Y", &selectedEntity->transform->globalPosition.y); + ImGui::InputFloat("X", &selectedEntity->transform->getPosition()->x); + ImGui::InputFloat("Y", &selectedEntity->transform->getPosition()->y); ImGui::Dummy(ImVec2(0.0f, 20.0f)); ImGui::Text("Scale: "); - ImGui::InputFloat("X scale", &selectedEntity->transform->scale.x); - ImGui::InputFloat("Y scale", &selectedEntity->transform->scale.y); + ImGui::InputFloat("X scale", &selectedEntity->transform->getScale()->x); + ImGui::InputFloat("Y scale", &selectedEntity->transform->getScale()->y); ImGui::Dummy(ImVec2(0.0f, 20.0f)); - float rads = selectedEntity->transform->rotation.z * 3.14 / 180; + float rads = selectedEntity->transform->getScale()->z * 3.14 / 180; ImGui::SliderAngle("Angle", &rads, 0, 360); - selectedEntity->transform->rotation.z = rads * 180 / 3.14; + selectedEntity->transform->getScale()->z = rads * 180 / 3.14; for (auto i : comps) { diff --git a/src/demo/components/mouseController.cpp b/src/demo/components/mouseController.cpp index b24d92e..48fefcd 100644 --- a/src/demo/components/mouseController.cpp +++ b/src/demo/components/mouseController.cpp @@ -15,7 +15,7 @@ void MouseController::update() if (wpwp::Input::isKeyReleased(sf::Keyboard::C)) { sf::Vector2i mousePos = wpwp::Input::getMouseWorldPosition(); - entity->transform->globalPosition = sf::Vector3f(mousePos.x, mousePos.y, 0); + entity->transform->setPosition(sf::Vector3f(mousePos.x, mousePos.y, 0)); } if (rend) diff --git a/src/demo/components/mouseController.o b/src/demo/components/mouseController.o index 9869635..f2cb069 100644 Binary files a/src/demo/components/mouseController.o and b/src/demo/components/mouseController.o differ diff --git a/src/demo/demoScene.cpp b/src/demo/demoScene.cpp index 72781f1..4c5b8d1 100644 --- a/src/demo/demoScene.cpp +++ b/src/demo/demoScene.cpp @@ -8,13 +8,15 @@ namespace demo void MainScene::load() { + // TODO: figure out why it doesnt affect the scale e = wpwp::Entity(sf::Vector3f(30, 30, 0)); - e.transform->scale = sf::Vector3f(100, 100, 0); e.addComponent(new CircleRenderer()); + e.transform->setScale(sf::Vector3f(100, 100, 0)); + std::cout << e.transform->getScale()->x << std::endl; Entity::instantiate(&e); e1 = wpwp::Entity(sf::Vector3f(800, 30, 0)); - e1.transform->scale = sf::Vector3f(100, 100, 0); + e1.transform->setScale(sf::Vector3f(100, 100, 0)); e1.addComponent(new SpriteRenderer()); SpriteRenderer *sp = e1.getComponent(); e1.addComponent(new MouseController());