R-Type
R-Type project
Transform.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** gameEngine2
4 ** File description:
5 ** Transform
6 */
7 
8 #ifndef TRANSFORM_HPP_
9 #define TRANSFORM_HPP_
10 
11 #include "Component.hpp"
12 #include "Vectors.hpp"
13 #include <any>
14 
15 namespace KapEngine {
16  class Component;
17 }
18 
19 namespace KapEngine {
20 
28  class Transform : public Component {
29  public:
30  Transform(std::shared_ptr<GameObject> go);
31  ~Transform();
32 
33  void onAwake() override;
34  void onDisplay() override;
35 
41  void setPosition(Tools::Vector3 pos);
47  void setRotation(Tools::Vector3 rot);
53  void setScale(Tools::Vector3 scale);
54 
73 
92 
98  void setParent(std::size_t id);
104  void setParent(std::any val);
111  bool allParentIsActive();
117  std::size_t getParentId() const;
123  Entity getParentEntity() const;
124 
129  std::shared_ptr<GameObject> getParent() const;
130 
135  std::vector<std::shared_ptr<GameObject>> getChildren();
136 
144  bool parentContainsComponent(std::string const& componentName, bool recurcively = false);
145 
154  bool parentContainsComponents(std::vector<std::string> componentsName, bool recurcively = false);
155 
162  std::size_t getParentContainsComponent(std::string const& componentName);
163 
170  bool allParentsActive() const;
171 
177  bool hasChanged();
178 
179  void __addChild(std::size_t id);
180  void __removeChild(std::size_t id);
181 
182  protected:
183  //variables
184  private:
185  Tools::Vector3 _pos;
186  Tools::Vector3 _rot;
187  Tools::Vector3 _scale;
188 
189  //start values
190  Tools::Vector3 _startPos;
191  Tools::Vector3 _startRot;
192  Tools::Vector3 _startScale;
193 
194  //update values
195  Tools::Vector3 _updatePos;
196  Tools::Vector3 _updateRot;
197  Tools::Vector3 _updateScale;
198 
199  Tools::Vector3 getParentPos() const;
200  Tools::Vector3 getParentRot() const;
201  Tools::Vector3 getParentScale() const;
202 
203  std::size_t _parentId = 0;
204  std::vector<std::size_t> _children;
205  bool _awkaeTr = false;
206 
207  };
208 
209 }
210 
211 #endif /* !TRANSFORM_HPP_ */
KapEngine::Transform::setRotation
void setRotation(Tools::Vector3 rot)
Set the GameObject Rotation.
Definition: Transform.cpp:48
KapEngine::Transform::onDisplay
void onDisplay() override
use to display some things this function is call after all updates fucntion
Definition: Transform.cpp:31
KapEngine::Transform
Definition: Transform.hpp:28
KapEngine::Transform::getWorldScale
Tools::Vector3 getWorldScale() const
Get the World Scale of GameObject.
Definition: Transform.cpp:105
KapEngine::Transform::onAwake
void onAwake() override
call component awake
Definition: Transform.cpp:23
KapEngine::Transform::getWorldPosition
Tools::Vector3 getWorldPosition() const
Get the World Position of GameObject.
Definition: Transform.cpp:91
KapEngine::Transform::getChildren
std::vector< std::shared_ptr< GameObject > > getChildren()
Get the Children of gameObject.
Definition: Transform.cpp:237
KapEngine::Transform::allParentIsActive
bool allParentIsActive()
return if all parents are active
Definition: Transform.cpp:225
KapEngine::Transform::getParentEntity
Entity getParentEntity() const
Get the Parent Entity.
KapEngine::Transform::getLocalScale
Tools::Vector3 getLocalScale() const
Get the Local Scale of GameObject.
Definition: Transform.cpp:83
KapEngine::Transform::parentContainsComponents
bool parentContainsComponents(std::vector< std::string > componentsName, bool recurcively=false)
check parent contain specific components
Definition: Transform.cpp:292
KapEngine::Transform::getLocalRotation
Tools::Vector3 getLocalRotation() const
Get the Local Rotation of GameObject.
Definition: Transform.cpp:75
KapEngine::Component
Definition: Component.hpp:38
KapEngine::Transform::setScale
void setScale(Tools::Vector3 scale)
Set the GameObject Scale.
Definition: Transform.cpp:57
KapEngine::Transform::setPosition
void setPosition(Tools::Vector3 pos)
Set the GameObject Position.
Definition: Transform.cpp:39
KapEngine::Transform::setParent
void setParent(std::size_t id)
Set the Parent by it's id.
Definition: Transform.cpp:164
KapEngine::Transform::allParentsActive
bool allParentsActive() const
check if all parents are active
Definition: Transform.cpp:343
KapEngine
main namespace
Definition: Component.hpp:17
KapEngine::Transform::parentContainsComponent
bool parentContainsComponent(std::string const &componentName, bool recurcively=false)
check parent contain a specific component
Definition: Transform.cpp:267
KapEngine::Transform::hasChanged
bool hasChanged()
check if transform changed since last update
Definition: Transform.cpp:357
KapEngine::Transform::getParentId
std::size_t getParentId() const
Get the Parent GameObject Id.
Definition: Transform.cpp:253
KapEngine::Transform::getWorldRotation
Tools::Vector3 getWorldRotation() const
Get the World Rotation of GameObject.
Definition: Transform.cpp:97
KapEngine::Tools::Vector3
Definition: Vectors.hpp:251
KapEngine::Transform::getParent
std::shared_ptr< GameObject > getParent() const
Get the Parent GameObject.
Definition: Transform.cpp:257
KapEngine::Transform::getLocalPosition
Tools::Vector3 getLocalPosition() const
Get the Local Position of GameObject.
Definition: Transform.cpp:67
KapEngine::Entity
Definition: Entity.hpp:15
KapEngine::Transform::getParentContainsComponent
std::size_t getParentContainsComponent(std::string const &componentName)
Get the Parent Contains Component recurcively.
Definition: Transform.cpp:304