CG-Project2
Loading...
Searching...
No Matches
Component.hpp
1#pragma once
2
3#include "../../../Opengl-Core/include/Core.hpp"
4
5#include <glm/ext/matrix_transform.hpp>
6#include <glm/ext/vector_float3.hpp>
7#include <glm/geometric.hpp>
8#include <glm/gtx/quaternion.hpp>
9
10#include "../Utils.hpp"
11
12#include <functional>
13#include <glm/trigonometric.hpp>
14#include <utility>
15#include <vector>
16
25class Component {
26public:
27 Component() = default;
28
29 virtual ~Component() = default;
30};
31
32// REMOVE ALL SET AND GET METHODS - USE SYSTEMS
36class Transform : public Component {
37public:
43 inline bool isModelMatrixEnable() const { return this->enableModel; }
44
50 inline void enableModelMatrix(const bool &flag) { this->enableModel = flag; }
51
61 inline const bool &isDirty() const { return this->dirty; }
62
71 inline void setDirty(const bool &dirty) { this->dirty = true; }
72
73 /* // BETTER DON'T FORCE MODEL MATRIX
74 inline void setModelMatrix(const glm::mat4 &matrix) {
75 this->model = matrix;
76 this->dirty = false;
77 }
78 */
79
85 inline const glm::vec3 &getPosition() const { return this->position; }
86
94 inline void setPosition(const glm::vec3 &pos) {
95 this->position = pos;
96 this->dirty = true;
97 }
98
106 inline void addPosition(const glm::vec3 &offset) {
107 this->position += offset;
108 this->dirty = true;
109 }
110
116 inline glm::vec3 getScale() const { return this->scale; }
117
125 inline void setScale(const glm::vec3 &scale) {
126 this->scale = scale;
127 this->dirty = true;
128 }
129
137 inline void addScale(const glm::vec3 &offset) {
138 this->scale += offset;
139 this->dirty = true;
140 }
141
147 inline glm::vec3 getRotation() const { return this->rotation; }
148
155 inline void setRotation(glm::vec3 rot) {
156 if (rot.x >= MAX_DEGREE_ANGLE || rot.x <= -MAX_DEGREE_ANGLE) {
157 rot.x -= 2 * MAX_DEGREE_ANGLE * (rot.x > 0 ? 1.f : -1.f);
158 }
159 if (rot.y >= MAX_DEGREE_ANGLE || rot.y <= -MAX_DEGREE_ANGLE) {
160 rot.y -= 2 * MAX_DEGREE_ANGLE * (rot.y > 0 ? 1.f : -1.f);
161 }
162 if (rot.z >= MAX_DEGREE_ANGLE || rot.z <= -MAX_DEGREE_ANGLE) {
163 rot.z -= 2 * MAX_DEGREE_ANGLE * (rot.z > 0 ? 1.f : -1.f);
164 }
165 this->rotation = glm::radians(rot);
166 this->dirty = true;
167 }
168
175 inline void addRotation(const glm::vec3 &offset) {
176 auto rot = glm::degrees(this->rotation + glm::radians(offset));
177 if (rot.x >= MAX_DEGREE_ANGLE || rot.x <= -MAX_DEGREE_ANGLE) {
178 rot.x -= 2 * MAX_DEGREE_ANGLE * (rot.x > 0 ? 1.f : -1.f);
179 }
180 if (rot.y >= MAX_DEGREE_ANGLE || rot.y <= -MAX_DEGREE_ANGLE) {
181 rot.y -= 2 * MAX_DEGREE_ANGLE * (rot.y > 0 ? 1.f : -1.f);
182 }
183 if (rot.z >= MAX_DEGREE_ANGLE || rot.z <= -MAX_DEGREE_ANGLE) {
184 rot.z -= 2 * MAX_DEGREE_ANGLE * (rot.z > 0 ? 1.f : -1.f);
185 }
186 this->rotation = glm::radians(rot);
187 this->dirty = true;
188 }
189
190 /*
191 inline glm::quat getQuaternion() const { return this->quaternion; }
192
193 inline void setQuaternion(const glm::quat &quaternion) {
194 this->quaternion = quaternion;
195 this->dirty = true;
196 }
197 */
202 Component() {
203 }
204
205 virtual ~Transform() override = default;
206
212 if (!this->dirty)
213 return;
214
215 glm::mat4 base{1};
216 auto t = glm::translate(base, this->position);
217 auto s = glm::scale(base, this->scale);
218
219 this->quaternion = glm::quat(this->rotation);
220 auto r = glm::toMat4(this->quaternion);
221
222 this->model = t * s * r;
223 this->dirty = false;
224 }
225
227 glm::vec3 position{};
229 glm::vec3 scale{1, 1, 1};
231 glm::vec3 rotation{};
233 glm::quat quaternion{};
234
236 glm::mat4 model{1};
238 bool dirty = true;
240 bool enableModel = true;
241
245 float MAX_DEGREE_ANGLE = 180;
246};
247
253class MultiMesh : public Component {
254public:
255 MultiMesh() :
256 Component() {
257 }
258
259 virtual ~MultiMesh() override = default;
260
262 std::vector<unsigned int> entities{};
264 unsigned int anchor = 0;
265};
266
272class BufferComponent : public Component {
273public:
274 BufferComponent() = default;
275
276 virtual ~BufferComponent() override = default;
277
290
295};
296
300class VertexComponent : public Component {
301public:
308 inline std::vector<glm::vec3> getVertexCoords() const { return this->m_vertex; }
309
315 inline void setVertexCoords(const std::vector<glm::vec3> &vertex) { this->m_vertex = vertex; }
316
322 inline void appendVertex(const std::vector<glm::vec3> &vertex) {
323 for (auto e : vertex)
324 this->m_vertex.push_back(e);
325 }
326
333 inline std::vector<glm::vec3> getNormalsCoords() const { return this->m_normals; }
334
340 inline void setNormalsCoords(const std::vector<glm::vec3> &normals) { this->m_normals = normals; }
341
347 inline void appendNormal(const std::vector<glm::vec3> &normal) {
348 for (auto e : normal)
349 this->m_normals.push_back(e);
350 }
351
358 inline std::vector<glm::vec4> getColorsCoords() const { return this->m_colors; }
359
365 inline void setColorsCoords(const std::vector<glm::vec4> &colors) { this->m_colors = colors; }
366
372 inline void appendColor(const std::vector<glm::vec4> &colors) {
373 for (auto e : colors)
374 this->m_colors.push_back(e);
375 }
376
383 inline std::vector<glm::vec2> getTexCoords() const { return this->m_texCoords; }
384
390 inline void setTexCoords(const std::vector<glm::vec2> &texCoords) { this->m_texCoords = texCoords; }
391
397 inline void appendTexCoords(const std::vector<glm::vec2> &coords) {
398 for (auto e : coords)
399 this->m_texCoords.push_back(e);
400 }
401
408 inline std::vector<unsigned int> getIndexCoords() const { return this->m_index; }
409
415 inline void setIndexCoords(const std::vector<unsigned int> &index) { this->m_index = index; }
416
422 inline void appendIndex(const std::vector<unsigned int> &index) {
423 for (auto e : index)
424 this->m_index.push_back(e);
425 }
426
434 VertexComponent(const std::vector<glm::vec3> &vertex, const std::vector<glm::vec4> &colors, const std::vector<unsigned int> &indices) :
435 Component() {
436 this->m_vertex = vertex;
437 this->m_colors = colors;
438 this->m_index = indices;
439 }
440
441 virtual ~VertexComponent() = default;
442
443private:
444 // vertices coords vector
445 std::vector<glm::vec3> m_vertex{};
446 // colors values vector
447 std::vector<glm::vec4> m_colors{};
448 // texture coords vector
449 std::vector<glm::vec2> m_texCoords{};
450 // indives vector
451 std::vector<unsigned int> m_index{};
452 // normals coords vector
453 std::vector<glm::vec3> m_normals{};
454};
455
461class TextureComponent : public Component {
462public:
467 Component() {
468 }
469
475 TextureComponent(std::string path) :
476 Component(), path(std::move(path)) {
477 }
478
479 virtual ~TextureComponent() override = default;
480
484 std::string path{};
485};
486
497class ParentComponent : public Component {
498public:
503 Component() {
504 }
505
506 virtual ~ParentComponent() = default;
507
509 std::vector<unsigned int> children{};
510};
511
516class ShaderComponent : public Component {
517public:
519 ShaderComponent() = delete;
520
535 ShaderComponent(const LightComputation &comp, const std::string &vert, const std::string &frag, const bool &reflective = false, const std::string &geom = "") :
536 computation(comp), vert(std::move(vert)), frag(std::move(vert)), reflective(reflective), geom(std::move(geom)), Component() {}
537
538 virtual ~ShaderComponent() override = default;
539
541 LightComputation computation = LightComputation::PHONG;
543 bool reflective = false;
545 std::string vert{};
547 std::string frag{};
549 std::string geom{};
550};
551
552namespace light {
554 inline std::vector<LightComputation> lightCompsEnm{NONE, PHONG, BLINN_PHONG, INT_PHONG, INT_BLINN_PHONG};
556 inline std::vector<std::string> lightCompStr = {"None", "Phong", "Blinn-Phong", "Int Phong", "Int Blinn-Phong"};
557} // namespace light
558
563class RenderComponent : public Component {
564public:
570 void setRenderCall(const std::function<void()> &func) { this->m_renderCall = std::move(func); }
571
575 void call() {
576 if (this->m_renderCall != nullptr)
577 this->m_renderCall();
578 }
579
584 Component() {
585 }
586
587 virtual ~RenderComponent() override = default;
588
589private:
591 std::function<void()> m_renderCall = nullptr;
592};
593
598class InstancedComponent : public Component {
599public:
607 InstancedComponent(const ogl::RenderPrimitiveType &type) :
608 type(type), Component() {}
609
610 virtual ~InstancedComponent() override = default;
611
613 ogl::RenderPrimitiveType type;
614};
615
620class Outlined : public Component {
621public:
626 Component() {
627 }
628
629 virtual ~Outlined() = default;
630};
631
635class Material {
636public:
638 glm::vec3 ambient{0.f};
640 glm::vec3 diffuse{0.55f};
642 glm::vec3 specular{0.7f};
644 float shininess = 32.f;
646 std::string name{"New Material"};
647
651 Material() = default;
652
662 Material(const glm::vec3 &ambient, const glm::vec3 &diffuse, const glm::vec3 &specular, const float shininess, const std::string &name) :
664
671 bool operator==(const Material &other) {
672 return this->name == other.name;
673 }
674};
675
681namespace material {
682
689 enum MaterialType : unsigned int {
690 MATERIAL_NONE = 0,
691 MATERIAL_RPLASTIC,
692 MATERIAL_YPLASTIC,
693 MATERIAL_SLATE,
694 MATERIAL_BRASS,
695 MATERIAL_EMERALD,
696 };
697
699 inline std::vector<unsigned int> materialTypes{MATERIAL_NONE, MATERIAL_RPLASTIC, MATERIAL_YPLASTIC, MATERIAL_SLATE, MATERIAL_BRASS, MATERIAL_EMERALD};
700
702 inline std::vector<Material> defaultMaterials = {
703 Material(glm::vec3(1.0f), glm::vec3(1.0f), glm::vec3(1.0f), 32.0f, "None"),
704 Material(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.0f, 0.0f), glm::vec3(0.7f, 0.6f, 0.6f), 32.0f, "Red Plastic"),
705 Material(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.0f), glm::vec3(0.60f, 0.60f, 0.50f), 32.0f, "Yellow Plastic"),
706 Material(glm::vec3(0.02f, 0.02f, 0.02f), glm::vec3(0.1f, 0.1f, 0.1f), glm::vec3(0.4f, 0.4f, 0.4f), 1.78125f, "Slate"),
707 Material(glm::vec3(0.329412f, 0.223529f, 0.027451f), glm::vec3(0.780392f, 0.568627f, 0.113725f), glm::vec3(0.992157f, 0.941176f, 0.807843f), 27.8974f, "Brass"),
708 Material(glm::vec3(0.0215f, 0.1745f, 0.0215f), glm::vec3(0.07568f, 0.61424f, 0.07568f), glm::vec3(0.633f, 0.727811f, 0.633f), 76.8f, "Emerald"),
709 };
710
719 inline Material getMaterialFromPool(const MaterialType &index) { return defaultMaterials[index]; }
720
721} // namespace material
722
729class MaterialComponent : public Component {
730public:
739
750 Component(), material(material::getMaterialFromPool(type)) {
751 }
752
753 virtual ~MaterialComponent() = default;
754
757};
758
763class LightComponent : public Component {
764public:
765 LightComponent() = delete;
766
772 LightComponent(const glm::vec3 &direction) :
773 type(LightType::LIGHT_DIRECTIONAL), direction(direction), Component() {
774 }
775
784 LightComponent(const glm::vec3 &position, const LightConstraint &constraint) :
785 type(LightType::LIGHT_POINT), position(position), attenuation(constraint), Component() {
786 }
787
800 LightComponent(const glm::vec3 &position, const glm::vec3 &direction, const LightConstraint &constraint, const float &cutOff = 12.5f, const float &outerCutoff = 17.5f) :
801 type(LightType::LIGHT_SPOT), position(position), direction(direction), attenuation(constraint), cutOff(cutOff), outerCutoff(outerCutoff), Component() {
802 }
803
804 virtual ~LightComponent() override = default;
805
807 glm::vec3 color{1, 1, 1};
809 float intensity = 1.f;
816 LightType type = LightType::LIGHT_DIRECTIONAL;
823
825 glm::vec3 direction{1, -1, -1};
826
828 glm::vec3 position{};
831
833 float cutOff = 12.5f;
835 float outerCutoff = 17.5f;
836
838 bool caster = true;
839};
840
849class InputComponent : public Component {
850public:
857 inline void registerAction(const unsigned int &key, const std::function<void()> &callback) {
858 this->callbacks.emplace(key, std::move(callback));
859 }
860
866 inline void call(const unsigned int &key) {
867 this->callbacks.at(key)();
868 }
869
875 inline std::vector<unsigned int> getAllKeys() const {
876 std::vector<unsigned int> keys{};
877 for (auto [key, _] : this->callbacks) {
878 keys.push_back(key);
879 }
880 return keys;
881 // C++20
882 // auto kv = std::views::keys(this->callbacks);
883 // return std::vector<unsigned int>{kv.begin(), kv.end()};
884 }
885
889 InputComponent() = default;
890
891 ~InputComponent() override = default;
892
894 std::map<unsigned int, std::function<void()>> callbacks;
895};
896
902class TimeAnimation : public Component {
903public:
911 void updateTick(const float &currentTime) {
912 if (this->startTime + this->timeToLive >= currentTime)
913 this->func();
914 else
915 this->dead = true;
916 }
917
918 TimeAnimation() = delete;
919
928 TimeAnimation(const float &startTime, const float &timeToLive, std::function<void()> &&func) :
930 }
931
932 virtual ~TimeAnimation() override = default;
933
935 std::function<void()> func{};
941 bool dead = false;
942};
943
948class BehaviourComponent : public Component {
949public:
955 Component() {
956 }
957
958 virtual ~BehaviourComponent() = default;
959
961 std::function<void()> func = nullptr;
962};
963
971class CameraComponent : public Component {
972public:
974 Shared<ogl::Camera> camera{};
975
979 CameraComponent() = default;
980 virtual ~CameraComponent() override = default;
981};
982
992class PhysicComponent : public Component {
993public:
995 glm::vec3 velocity{};
997 glm::vec3 a{};
999 glm::vec3 force{};
1000
1002 float mass = 1;
1004 float restitution = 1;
1005
1010 Component() {}
1011
1012 virtual ~PhysicComponent() override = default;
1013};
1014
1015// TODO: put it in a namespace
1025enum ColliderType : unsigned int {
1026 COLLIDER_SPHERE = 0,
1027 COLLIDER_CUBE,
1028};
1029
1038class ColliderComponent : public Component {
1039public:
1041 ColliderType type = COLLIDER_CUBE;
1043 glm::vec3 position{};
1045 glm::vec3 normal{};
1049 glm::vec3 size{};
1051 glm::vec3 botLeft{};
1053 glm::vec3 topRight{};
1054
1056 bool isStatic = false;
1057
1069 void updateCollider(const std::vector<glm::vec3> &coords, const glm::mat4 &model) {
1070 auto bot = glm::vec3(0);
1071 bool first = true;
1072
1073 for (auto i = 0; i < coords.size(); i++) {
1074 auto elem = model * glm::vec4(coords[i], 1);
1075 if (first) {
1076 bot = elem;
1077 first = false;
1078 }
1079 bot.x = bot.x >= elem.x ? elem.x : bot.x;
1080 bot.y = bot.y >= elem.y ? elem.y : bot.y;
1081 bot.z = bot.z >= elem.z ? elem.z : bot.z;
1082 }
1083
1084 auto top = glm::vec3(1);
1085 first = true;
1086 for (auto i = 0; i < coords.size(); i++) {
1087 auto elem = model * glm::vec4(coords[i], 1);
1088 if (first) {
1089 top = elem;
1090 first = false;
1091 }
1092 top.x = top.x <= elem.x ? elem.x : top.x;
1093 top.y = top.y <= elem.y ? elem.y : top.y;
1094 top.z = top.z <= elem.z ? elem.z : top.z;
1095 }
1096
1097 this->botLeft = bot;
1098 this->topRight = top;
1099 this->position = model[3];
1100 }
1101
1113 void updateCollider(const glm::vec3 &position, const glm::vec3 &size) {
1114 this->botLeft = position - size;
1115 this->topRight = position + size;
1116 }
1117
1125 bool isColliding(const ColliderComponent &other) const {
1126 return (this->botLeft.x <= other.topRight.x && this->topRight.x >= other.botLeft.x) &&
1127 (this->botLeft.y <= other.topRight.y && this->topRight.y >= other.botLeft.y) &&
1128 (this->botLeft.z <= other.topRight.z && this->topRight.z >= other.botLeft.z);
1129 }
1130
1135
1142 ColliderComponent(const glm::vec3 &position, const glm::vec3 &size) {
1143 this->botLeft = position - size;
1144 this->topRight = position + size;
1145 this->position = position;
1146 this->size = size;
1147 }
1148
1149 virtual ~ColliderComponent() override = default;
1150};
1151
1161class SkyboxComponent : public Component {
1162public:
1163 SkyboxComponent() = delete;
1164
1170 SkyboxComponent(const unsigned int &textureId) :
1171 textureId(textureId), Component() {}
1172
1173 virtual ~SkyboxComponent() override = default;
1174
1176 unsigned int textureId;
1177};
1178
1184 unsigned int id;
1186 std::string type{};
1188 std::string path{};
1189};
1190
1194class ImportedMeshTextures : public Component {
1195public:
1197 std::vector<ImportedTexture> textures{};
1198
1203 virtual ~ImportedMeshTextures() override = default;
1204};
1205
1212class HideTreeComponent : public Component {
1213public:
1218 virtual ~HideTreeComponent() override = default;
1219};
This Component is very similar to TimeAnimation, the only difference is that this "animation" has not...
Definition Component.hpp:948
BehaviourComponent()
Instances basic Component to query the ECS when it needs to update a mesh position or color or scale ...
Definition Component.hpp:954
std::function< void()> func
function called every frame to update the mesh
Definition Component.hpp:961
ogl::VertexArray vao
vertex array object
Definition Component.hpp:279
ogl::VertexBuffer vbo_n
normal coords vertex buffer object
Definition Component.hpp:289
ogl::VertexBuffer vbo_mo
model matrix offset vertex buffer
Definition Component.hpp:294
ogl::VertexBuffer vbo_co
color offset vertex buffer
Definition Component.hpp:292
ogl::VertexBuffer vbo_t
texture coords vertex buffer object
Definition Component.hpp:283
ogl::VertexBuffer vbo_c
color coords vertex buffer object
Definition Component.hpp:285
ogl::ElementBuffer ebo
index element buffer object
Definition Component.hpp:287
ogl::VertexBuffer vbo_g
geometry vertex buffer object
Definition Component.hpp:281
Shared< ogl::Camera > camera
shared pointer to the ogl::Camera object
Definition Component.hpp:974
CameraComponent()=default
Instances basic Component to query the ECS when needed.
Component to store mesh collider data to solve collision in a PhysicWorld.
Definition Component.hpp:1038
void updateCollider(const std::vector< glm::vec3 > &coords, const glm::mat4 &model)
This method updates the collider cornders coords by iterating over all mesh vertices....
Definition Component.hpp:1069
bool isStatic
define if the mesh is simulated in the PhsyicWorld or not
Definition Component.hpp:1056
glm::vec3 topRight
top right corner coords
Definition Component.hpp:1053
glm::vec3 position
collider center position
Definition Component.hpp:1043
ColliderComponent()=default
Instances a basic Component.
void updateCollider(const glm::vec3 &position, const glm::vec3 &size)
This method update a non Optimized Bounding Box by summing the given size with the given position....
Definition Component.hpp:1113
bool isColliding(const ColliderComponent &other) const
Checks if the given collider is overlapping with the current one.
Definition Component.hpp:1125
ColliderType type
collider type
Definition Component.hpp:1041
glm::vec3 normal
collider normal vector (in case is a plane)
Definition Component.hpp:1045
glm::vec3 botLeft
bottom left corner coords
Definition Component.hpp:1051
ColliderComponent(const glm::vec3 &position, const glm::vec3 &size)
Instances a non Optimized Bounding Box collider.
Definition Component.hpp:1142
glm::vec3 size
Definition Component.hpp:1049
HideTreeComponent()=default
Instances basic Component to query the ECS.
std::vector< ImportedTexture > textures
imported texture list of the mesh
Definition Component.hpp:1197
ImportedMeshTextures()=default
Instances basic Component to query the ECS.
InputComponent()=default
Instances basic Component.
std::vector< unsigned int > getAllKeys() const
Retrieves all the key that are linked to a callback.
Definition Component.hpp:875
std::map< unsigned int, std::function< void()> > callbacks
map containing a callback for a specified key
Definition Component.hpp:894
void registerAction(const unsigned int &key, const std::function< void()> &callback)
Registers a callback to a specific key.
Definition Component.hpp:857
void call(const unsigned int &key)
Calls the function in the map at key index.
Definition Component.hpp:866
This component is used to query the ECS for all primitives that are rendered using instanced renderin...
Definition Component.hpp:598
ogl::RenderPrimitiveType type
primitive type of the mesh
Definition Component.hpp:613
InstancedComponent(const ogl::RenderPrimitiveType &type)
Instance a Component that will render the given primitive type.
Definition Component.hpp:607
Component to store light data. A light is an emitting mesh, rendered or not, that for each ogl::Shade...
Definition Component.hpp:763
float cutOff
light cutoff
Definition Component.hpp:833
LightComponent(const glm::vec3 &position, const LightConstraint &constraint)
Instances a point light with the given position and LightConstraint.
Definition Component.hpp:784
float outerCutoff
light outer cutoff
Definition Component.hpp:835
glm::vec3 position
light position
Definition Component.hpp:828
LightVectors vectors
Light components vectors.
Definition Component.hpp:822
bool caster
light caster
Definition Component.hpp:838
LightComponent(const glm::vec3 &direction)
Instances a directional light with the given direction.
Definition Component.hpp:772
LightType type
Light type for shader programs. This member is mainly used to create shader data blocks.
Definition Component.hpp:816
float intensity
light intensity
Definition Component.hpp:809
glm::vec3 color
light color, default white
Definition Component.hpp:807
glm::vec3 direction
light direction
Definition Component.hpp:825
LightComponent(const glm::vec3 &position, const glm::vec3 &direction, const LightConstraint &constraint, const float &cutOff=12.5f, const float &outerCutoff=17.5f)
Instances a spot light with the given position, direction, LightConstraint, light cutoff and outer cu...
Definition Component.hpp:800
LightConstraint attenuation
light attenuation
Definition Component.hpp:830
Component to store the mesh Material data.
Definition Component.hpp:729
MaterialComponent(const Material &material=material::defaultMaterials[0])
Instances a Component with the given material.
Definition Component.hpp:736
MaterialComponent(const material::MaterialType &type)
Instances a Component by using the given material type to retrieve the Material object.
Definition Component.hpp:749
Basic class to store material information for texturing and light computation.
Definition Component.hpp:635
glm::vec3 diffuse
diffuse vector
Definition Component.hpp:640
Material()=default
Instances basic material.
float shininess
material shininess
Definition Component.hpp:644
glm::vec3 specular
specular vector
Definition Component.hpp:642
bool operator==(const Material &other)
Overrides the equal operator, two materials are equal if they have the same name.
Definition Component.hpp:671
Material(const glm::vec3 &ambient, const glm::vec3 &diffuse, const glm::vec3 &specular, const float shininess, const std::string &name)
Instances a material with the given data.
Definition Component.hpp:662
glm::vec3 ambient
ambient vector
Definition Component.hpp:638
std::string name
material name
Definition Component.hpp:646
unsigned int anchor
index of the achor entity
Definition Component.hpp:264
std::vector< unsigned int > entities
list of child entities
Definition Component.hpp:262
Component used to query all meshes that needs to be outlined using a simple stencil buffer.
Definition Component.hpp:620
Outlined()
Instances basic Component.
Definition Component.hpp:625
This Component is used like MultiMesh, but it create a sort of tree structure where each mesh has chi...
Definition Component.hpp:497
ParentComponent()
Instance basic Component.
Definition Component.hpp:502
std::vector< unsigned int > children
vector containing children ids.
Definition Component.hpp:509
This Component stores all the mesh data regarding basic physics like velocity, force,...
Definition Component.hpp:992
glm::vec3 velocity
mesh velocity
Definition Component.hpp:995
glm::vec3 force
mesh force
Definition Component.hpp:999
glm::vec3 a
mesh acceleration
Definition Component.hpp:997
PhysicComponent()
Instances basic Component to query the ECS.
Definition Component.hpp:1009
float restitution
mesh restitution factor
Definition Component.hpp:1004
float mass
mesh mass
Definition Component.hpp:1002
This Component is used to render a mesh in the ogl::Window. It stores the render call that will be ca...
Definition Component.hpp:563
RenderComponent()
Instance basic Component.
Definition Component.hpp:583
void setRenderCall(const std::function< void()> &func)
Sets the render call that will be used.
Definition Component.hpp:570
void call()
This method calls the render callback if is defined.
Definition Component.hpp:575
Component to store mesh shader data and some mesh information like light computation and the capabili...
Definition Component.hpp:516
std::string frag
fragment shader path
Definition Component.hpp:547
std::string vert
vertex shader path
Definition Component.hpp:545
ShaderComponent(const LightComputation &comp, const std::string &vert, const std::string &frag, const bool &reflective=false, const std::string &geom="")
Instances the Component by giving shaders path and light computation. The light computation might be ...
Definition Component.hpp:535
bool reflective
mesh reflectiveness
Definition Component.hpp:543
LightComputation computation
mesh light computation
Definition Component.hpp:541
std::string geom
geometry shader path
Definition Component.hpp:549
ShaderComponent()=delete
Can't use an empty constructor.
Component to store SkyBox texture data.
Definition Component.hpp:1161
SkyboxComponent(const unsigned int &textureId)
Instances basic Component and stores the texture id of the skybox.
Definition Component.hpp:1170
unsigned int textureId
skybox texture id
Definition Component.hpp:1176
Component to store mesh ogl::Texture data.
Definition Component.hpp:461
TextureComponent()
Instance an empty Component.
Definition Component.hpp:466
std::string path
texture file path
Definition Component.hpp:484
TextureComponent(std::string path)
Instance a Component with the given path.
Definition Component.hpp:475
ogl::Texture texture
texture object
Definition Component.hpp:482
This Component allow to execute an action at every frame for a specified time.
Definition Component.hpp:902
void updateTick(const float &currentTime)
Updates the current state of the animation by calling the callback. It uses a startTime and a current...
Definition Component.hpp:911
TimeAnimation(const float &startTime, const float &timeToLive, std::function< void()> &&func)
Instances an animation that will live timeToLive seconds after it has been created startTime and at e...
Definition Component.hpp:928
std::function< void()> func
callback function
Definition Component.hpp:935
float startTime
start time of the animation
Definition Component.hpp:937
float timeToLive
duration of the animation
Definition Component.hpp:939
bool dead
determines if the animation is finished, if it's true the callback will be called
Definition Component.hpp:941
Component to store mesh position, rotation, scale data.
Definition Component.hpp:36
glm::quat quaternion
mesh quaternion
Definition Component.hpp:233
bool dirty
model matrix dirty flag
Definition Component.hpp:238
bool isModelMatrixEnable() const
Retrieves if the model matrix is enable.
Definition Component.hpp:43
glm::vec3 getRotation() const
Retrieves the mesh position.
Definition Component.hpp:147
void setRotation(glm::vec3 rot)
Sets the mesh rotation, it works using MAX_DEGREE_ANGLE to avoid angle value more then 360 or less th...
Definition Component.hpp:155
void addRotation(const glm::vec3 &offset)
Adds to the current rotation value the given offset. It works with the same behaviour of Transform::s...
Definition Component.hpp:175
glm::mat4 model
mesh model matrix
Definition Component.hpp:236
void enableModelMatrix(const bool &flag)
Enable/disable the model matrix.
Definition Component.hpp:50
const bool & isDirty() const
This method is used to avoid regenerating model matrix if data aren't changed.
Definition Component.hpp:61
void addScale(const glm::vec3 &offset)
Adds to the current scale the offset given.
Definition Component.hpp:137
void updateModelMatrix()
This method updates the model matrix only if the dirty flag is activated.
Definition Component.hpp:211
void setPosition(const glm::vec3 &pos)
Sets the mesh position.
Definition Component.hpp:94
const glm::vec3 & getPosition() const
Retrieves the mesh position.
Definition Component.hpp:85
Transform()
Default constructor.
Definition Component.hpp:201
glm::vec3 position
mesh position vector
Definition Component.hpp:227
void setScale(const glm::vec3 &scale)
Sets the mesh scale.
Definition Component.hpp:125
void addPosition(const glm::vec3 &offset)
Adds an offset to the current position.
Definition Component.hpp:106
glm::vec3 scale
mesh scale
Definition Component.hpp:229
glm::vec3 getScale() const
Retrieves the mesh position.
Definition Component.hpp:116
void setDirty(const bool &dirty)
Sets the model matrix dirty flag.
Definition Component.hpp:71
float MAX_DEGREE_ANGLE
Definition Component.hpp:245
glm::vec3 rotation
mesh rotation
Definition Component.hpp:231
bool enableModel
model matrix enable flag
Definition Component.hpp:240
Component to store vertices coords data.
Definition Component.hpp:300
VertexComponent(const std::vector< glm::vec3 > &vertex, const std::vector< glm::vec4 > &colors, const std::vector< unsigned int > &indices)
Instances the VertexComponent object with the given data.
Definition Component.hpp:434
void appendTexCoords(const std::vector< glm::vec2 > &coords)
Add at the end of the texture coords vector the given texture coords.
Definition Component.hpp:397
void appendIndex(const std::vector< unsigned int > &index)
Add at the end of the indives vector the given indices.
Definition Component.hpp:422
void appendVertex(const std::vector< glm::vec3 > &vertex)
Add at the end of the vertices vector the given vertex.
Definition Component.hpp:322
std::vector< glm::vec3 > getNormalsCoords() const
Retrieves all mesh normals coords.
Definition Component.hpp:333
std::vector< glm::vec4 > getColorsCoords() const
Retrieves all mesh color values.
Definition Component.hpp:358
void setVertexCoords(const std::vector< glm::vec3 > &vertex)
Sets the vertices coords vector.
Definition Component.hpp:315
std::vector< glm::vec3 > getVertexCoords() const
Retrieves all mesh vertices coords.
Definition Component.hpp:308
std::vector< unsigned int > getIndexCoords() const
Retrieves all mesh indices.
Definition Component.hpp:408
std::vector< glm::vec2 > getTexCoords() const
Retrieves all mesh texture coords.
Definition Component.hpp:383
void setIndexCoords(const std::vector< unsigned int > &index)
Sets the indices coords vector.
Definition Component.hpp:415
void appendColor(const std::vector< glm::vec4 > &colors)
Add at the end of the colors vector the given colors.
Definition Component.hpp:372
void appendNormal(const std::vector< glm::vec3 > &normal)
Add at the end of the normal vector the given normal.
Definition Component.hpp:347
void setColorsCoords(const std::vector< glm::vec4 > &colors)
Sets the colors values vector.
Definition Component.hpp:365
void setTexCoords(const std::vector< glm::vec2 > &texCoords)
Sets the texture coords vector.
Definition Component.hpp:390
void setNormalsCoords(const std::vector< glm::vec3 > &normals)
Sets the vertices coords vector.
Definition Component.hpp:340
Definition ElementBuffer.hpp:7
Definition Texture.hpp:8
Definition VertexArray.hpp:6
Definition VertexBuffer.hpp:7
Definition Component.hpp:552
std::vector< std::string > lightCompStr
list of strings for each LightComputation
Definition Component.hpp:556
LightType
Lights type used in shader programs.
Definition Utils.hpp:19
std::vector< LightComputation > lightCompsEnm
list of light algorithms for shader programs
Definition Component.hpp:554
Material getMaterialFromPool(const MaterialType &index)
Retrieves the material by the given type or from a simple index from the defaultMaterials vector.
Definition Component.hpp:719
std::vector< Material > defaultMaterials
vector containing default start materials
Definition Component.hpp:702
MaterialType
Enum for materials declared as unsigned int.
Definition Component.hpp:689
std::vector< unsigned int > materialTypes
initial material types
Definition Component.hpp:699
This structure stores data from an imported mesh texture.
Definition Component.hpp:1182
std::string type
texture type (diffuse, normal, specular, etc.)
Definition Component.hpp:1186
std::string path
texture file path
Definition Component.hpp:1188
unsigned int id
texture id
Definition Component.hpp:1184
Lights attenuation data structure.
Definition Utils.hpp:34
Light vectors for light component.
Definition Utils.hpp:46