3#include "../../../Opengl-Core/include/Core.hpp"
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>
10#include "../Utils.hpp"
13#include <glm/trigonometric.hpp>
27 Component() =
default;
29 virtual ~Component() =
default;
138 this->
scale += offset;
176 auto rot = glm::degrees(this->
rotation + glm::radians(offset));
216 auto t = glm::translate(base, this->
position);
217 auto s = glm::scale(base, this->
scale);
222 this->
model = t * s * r;
253class MultiMesh :
public Component {
259 virtual ~MultiMesh()
override =
default;
272class BufferComponent :
public Component {
274 BufferComponent() =
default;
276 virtual ~BufferComponent()
override =
default;
315 inline void setVertexCoords(
const std::vector<glm::vec3> &vertex) { this->m_vertex = vertex; }
323 for (
auto e : vertex)
324 this->m_vertex.push_back(e);
340 inline void setNormalsCoords(
const std::vector<glm::vec3> &normals) { this->m_normals = normals; }
348 for (
auto e : normal)
349 this->m_normals.push_back(e);
365 inline void setColorsCoords(
const std::vector<glm::vec4> &colors) { this->m_colors = colors; }
373 for (
auto e : colors)
374 this->m_colors.push_back(e);
383 inline std::vector<glm::vec2>
getTexCoords()
const {
return this->m_texCoords; }
390 inline void setTexCoords(
const std::vector<glm::vec2> &texCoords) { this->m_texCoords = texCoords; }
398 for (
auto e : coords)
399 this->m_texCoords.push_back(e);
408 inline std::vector<unsigned int>
getIndexCoords()
const {
return this->m_index; }
415 inline void setIndexCoords(
const std::vector<unsigned int> &index) { this->m_index = index; }
424 this->m_index.push_back(e);
434 VertexComponent(
const std::vector<glm::vec3> &vertex,
const std::vector<glm::vec4> &colors,
const std::vector<unsigned int> &indices) :
436 this->m_vertex = vertex;
437 this->m_colors = colors;
438 this->m_index = indices;
445 std::vector<glm::vec3> m_vertex{};
447 std::vector<glm::vec4> m_colors{};
449 std::vector<glm::vec2> m_texCoords{};
451 std::vector<unsigned int> m_index{};
453 std::vector<glm::vec3> m_normals{};
476 Component(),
path(std::move(
path)) {
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"};
570 void setRenderCall(
const std::function<
void()> &func) { this->m_renderCall = std::move(func); }
576 if (this->m_renderCall !=
nullptr)
577 this->m_renderCall();
591 std::function<void()> m_renderCall =
nullptr;
646 std::string
name{
"New Material"};
672 return this->name == other.
name;
699 inline std::vector<unsigned int>
materialTypes{MATERIAL_NONE, MATERIAL_RPLASTIC, MATERIAL_YPLASTIC, MATERIAL_SLATE, MATERIAL_BRASS, MATERIAL_EMERALD};
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"),
763class LightComponent :
public Component {
765 LightComponent() =
delete;
857 inline void registerAction(
const unsigned int &key,
const std::function<
void()> &callback) {
858 this->
callbacks.emplace(key, std::move(callback));
866 inline void call(
const unsigned int &key) {
876 std::vector<unsigned int> keys{};
894 std::map<
unsigned int, std::function<void()>>
callbacks;
902class TimeAnimation :
public Component {
961 std::function<void()>
func =
nullptr;
1025enum ColliderType :
unsigned int {
1026 COLLIDER_SPHERE = 0,
1070 auto bot = glm::vec3(0);
1073 for (
auto i = 0; i < coords.size(); i++) {
1074 auto elem = model * glm::vec4(coords[i], 1);
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;
1084 auto top = glm::vec3(1);
1086 for (
auto i = 0; i < coords.size(); i++) {
1087 auto elem = model * glm::vec4(coords[i], 1);
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;
1097 this->botLeft = bot;
1098 this->topRight = top;
1099 this->position = model[3];
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);
1161class SkyboxComponent :
public Component {
1163 SkyboxComponent() =
delete;
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.
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 ¤tTime)
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 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 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