CG-Project2
Loading...
Searching...
No Matches
System.hpp
1#pragma once
2
3#include <functional>
4#include <string>
5#include <utility>
6#include <vector>
7
8#include "../../../Opengl-Core/include/Core.hpp"
9#include "Component.hpp"
10
17 unsigned int nspheres = 0;
19 std::vector<unsigned int> spheresIds{};
21 std::vector<glm::vec4> spheresColor{};
23 std::vector<glm::mat4> spheresModel{};
24} inline data;
25
31namespace systems {
32
39 namespace ecs {
47 bool removeEntityFromManager(const unsigned int &id);
48
55 void removeEntityFromScene(const unsigned int &id);
56
63 bool removeEntityFromAll(const unsigned int &id);
64
69 void cleanAll();
70
77 std::string getEntityName(const unsigned int &id);
78
85 void updateEntityName(const unsigned int &id, const std::string &name);
86 } // namespace ecs
87
95 namespace transform {
102 void updatePosition(const unsigned int &id, const glm::vec3 &position);
103
110 void updateScale(const unsigned int &id, const glm::vec3 &scale);
111
121 void updateRotation(const unsigned int &id, const glm::vec3 &rotation);
122
129 void addPosition(const unsigned int &id, const glm::vec3 &offset);
130
137 void addScale(const unsigned int &id, const glm::vec3 &offset);
138
148 void addRotation(const unsigned int &id, const glm::vec3 &offset);
149
156 glm::vec3 getPosition(const unsigned int &id);
157
164
165 glm::vec3 getScale(const unsigned int &id);
166
173 glm::vec3 getRotation(const unsigned int &id);
174
183 glm::mat4 getModelMatrix(const unsigned int &id);
184
193 void updateModelMatrix(const unsigned int &id);
194
199 } // namespace transform
200
208 namespace collision {
217 void updateParentCollider(const unsigned int &id);
218
231 void updateCollider(const unsigned int &id);
232
236 void updateAllColliders();
237
244 ColliderType getColliderType(const unsigned int &id);
245
252 void updateColliderType(const unsigned int &id, const ColliderType &type);
253
262 void updateSimulated(const unsigned int &id, const bool &simulated);
263
268 void compressBoundingBox();
269
276 Pair<glm::vec3> getCollider(const unsigned int &id);
277
285 bool isColliding(const unsigned int &first, const unsigned int &second);
286
293 std::vector<Pair<unsigned int>> getCollisions();
294 } // namespace collision
295
300 namespace camera {
307 Shared<ogl::Camera> getCamera(const unsigned int &id);
308
316 void updateCameraCollider(const unsigned int &id, const glm::vec3 &position, const glm::vec3 &size);
317 } // namespace camera
318
323 namespace parent {
330 void addChild(const unsigned int &parent, const unsigned int &child);
331
338 void removeChild(const unsigned int &parent, const unsigned int &child);
339 } // namespace parent
340
346 namespace input {
354 std::vector<std::pair<unsigned int, std::function<void()>>> getKeysCallback(const unsigned int &id);
355
363 void setKeyCallback(const unsigned int &id, const unsigned int &key, std::function<void()> func);
364 } // namespace input
365
370 namespace animation {
380 void executeNextFrame(const float &currentTime);
381 } // namespace animation
382
389 namespace texture {
397 ogl::Texture getTexture(const unsigned int &id);
398
405 void setTexture(const unsigned int &id, const ogl::Texture &texture);
406
413 std::string getTexturePath(const unsigned int &id);
414
421 void updateTexturePath(const unsigned int &id, const std::string &path);
422
430 bool isMeshReflective(const unsigned int &id);
431
438 void setMeshReflective(const unsigned int &id, const bool &val);
439 } // namespace texture
440
447 namespace material {
454 Material getMaterial(const unsigned int &id);
455
462 std::string getMaterialName(const unsigned int &id);
463
470 void updateAmbient(const unsigned int &id, const glm::vec3 &val);
471
478 void updateDiffuse(const unsigned int &id, const glm::vec3 &val);
479
486 void updateSpecular(const unsigned int &id, const glm::vec3 &val);
487
494 void updateShininess(const unsigned int &id, const float &val);
495
502 void updateMaterial(const unsigned int &id, const Material &material);
503 } // namespace material
504
509 namespace light {
517 LightShaderBlock getLightInfo(const unsigned int &id);
518
525 void updateColor(const unsigned int &id, const glm::vec3 &color);
526
533 void updateIntensity(const unsigned int &id, const float &intensity);
534
541 void updateAmbient(const unsigned int &id, const glm::vec3 &ambient);
542
549 void updateDiffuse(const unsigned int &id, const glm::vec3 &diffuse);
550
557 void updateSpecular(const unsigned int &id, const glm::vec3 &specular);
558
565 void updateDirection(const unsigned int &id, const glm::vec3 &direction);
566
573 void updatePosition(const unsigned int &id, const glm::vec3 &position);
574
581 void updateConstant(const unsigned int &id, const float &constant);
582
589 void updateLinear(const unsigned int &id, const float &linear);
590
597 void updateQuadratic(const unsigned int &id, const float &quadratic);
598
605 void updateCutoff(const unsigned int &id, const float &cutoff);
606
613 void updateOuterCutoff(const unsigned int &id, const float &outerCutoff);
614
621 void setLightComputation(const unsigned int &id, const LightComputation &comp);
622
629 LightComputation getLightComputation(const unsigned int &id);
630 } // namespace light
631
636 namespace render {
640 void initStencilShader();
641
652 void prepareInstancedMesh(const std::vector<glm::mat4> &models, const std::vector<glm::vec4> &colors);
653
662 void getOtherLightData(LightShaderBlock &block, const Shared<LightComponent> &light);
663
670 std::array<LightShaderBlock, SHADER_MAX_LIGHTS> prepareLightData();
671
685 void sendOtherLightData(const Shared<ogl::ShaderProgram> &shader, LightShaderBlock &data, size_t &index);
686
698 void sendLightDataShader(const Shared<ogl::ShaderProgram> &shader, std::array<LightShaderBlock, SHADER_MAX_LIGHTS> data);
699
706 void renderSkybox(const unsigned int &id, const Shared<ogl::ShaderProgram> &shader);
707
713 void renderAllMeshes();
714
719
727 std::vector<glm::vec3> getBoxLines(glm::vec3 &botLeft, glm::vec3 &topRight);
728
732 void renderBoundingBox();
733 } // namespace render
734} // namespace systems
Basic class to store material information for texturing and light computation.
Definition Component.hpp:635
Definition Texture.hpp:8
Definition Component.hpp:552
All utilities to handle animations.
void executeNextFrame(const float &currentTime)
This method updates all the TimeAnimation components, it needs the curren time in seconds.
Definition System.cpp:414
All utilities to manage the world camera.
Shared< ogl::Camera > getCamera(const unsigned int &id)
Retrieves a pointer to the camera given.
Definition System.cpp:361
void updateCameraCollider(const unsigned int &id, const glm::vec3 &position, const glm::vec3 &size)
Updates the collider of the camera given.
Definition System.cpp:367
It contains all utilities to retrieve, handle and update mesh ColliderComponent.
void updateParentCollider(const unsigned int &id)
Updates the collider of a parent mesh.
Definition System.cpp:206
void updateSimulated(const unsigned int &id, const bool &simulated)
Updates the simulation of the entity in a PhysicWorld.
Definition System.cpp:273
void updateColliderType(const unsigned int &id, const ColliderType &type)
Updates the collider type of the given entity.
Definition System.cpp:266
Pair< glm::vec3 > getCollider(const unsigned int &id)
Retrieves the collider corners of the entity given.
Definition System.cpp:252
void compressBoundingBox()
This method optimize children bounding box of all parent entities in a single square/cube bounding bo...
Definition System.cpp:280
ColliderType getColliderType(const unsigned int &id)
Retrieves the type of the entity collider.
Definition System.cpp:259
void updateAllColliders()
Updates all the entities collider by calling systems::collision::updateCollider().
Definition System.cpp:234
std::vector< Pair< unsigned int > > getCollisions()
Retrieves all entities overlapping each other using simple AABB detection.
Definition System.cpp:328
bool isColliding(const unsigned int &first, const unsigned int &second)
Calculate if two entities are colliding or not.
Definition System.cpp:241
void updateCollider(const unsigned int &id)
Updates the collider of the given entity. If this entity is a parent entity (an entity with a ParentC...
Definition System.cpp:215
All utilities to manage the entities in the EntityManager.
std::string getEntityName(const unsigned int &id)
Retrieves the name of the given entity.
Definition System.cpp:80
void cleanAll()
Clean the EntityManager from all entities and Components and from the BasicScene too.
Definition System.cpp:71
bool removeEntityFromAll(const unsigned int &id)
Removes an entity from the EntityManager and from the BasicScene.
Definition System.cpp:66
void updateEntityName(const unsigned int &id, const std::string &name)
Updates the name of the given entity.
Definition System.cpp:84
bool removeEntityFromManager(const unsigned int &id)
Removes an entity from the EntityManager, if the entity has children they will be removed too.
Definition System.cpp:46
void removeEntityFromScene(const unsigned int &id)
Removes the given entity from the BasicScene, if entity has children they will be removed too.
Definition System.cpp:56
All utilities to manage user input to interact whith meshes.
void setKeyCallback(const unsigned int &id, const unsigned int &key, std::function< void()> func)
Sets a callback for the entity.
Definition System.cpp:404
std::vector< std::pair< unsigned int, std::function< void()> > > getKeysCallback(const unsigned int &id)
Retrieves all the callback of a mesh to be called when the key is pressed.
Definition System.cpp:392
void updateAmbient(const unsigned int &id, const glm::vec3 &ambient)
Updates the light ambient vector.
Definition System.cpp:563
void updateIntensity(const unsigned int &id, const float &intensity)
Updates the light intensity value.
Definition System.cpp:557
void updateSpecular(const unsigned int &id, const glm::vec3 &specular)
Updates the light specular vector.
Definition System.cpp:575
void updateConstant(const unsigned int &id, const float &constant)
Updates the light constant value.
Definition System.cpp:593
void updateDirection(const unsigned int &id, const glm::vec3 &direction)
Updates the light direction vector.
Definition System.cpp:581
void updatePosition(const unsigned int &id, const glm::vec3 &position)
Updates the light position vector.
Definition System.cpp:587
void updateOuterCutoff(const unsigned int &id, const float &outerCutoff)
Updates the light outer cutoff value.
Definition System.cpp:617
void updateCutoff(const unsigned int &id, const float &cutoff)
Updates the light cutoff value.
Definition System.cpp:611
LightComputation getLightComputation(const unsigned int &id)
Retrieves the light computation of an entity.
Definition System.cpp:629
void updateDiffuse(const unsigned int &id, const glm::vec3 &diffuse)
Updates the light diffuse vector.
Definition System.cpp:569
void setLightComputation(const unsigned int &id, const LightComputation &comp)
Updates the light computaion of an entity.
Definition System.cpp:623
LightShaderBlock getLightInfo(const unsigned int &id)
Retrieves a block (struct data) that will be sent to a shader program. The block will contain all the...
Definition System.cpp:532
void updateColor(const unsigned int &id, const glm::vec3 &color)
Updates the light color vector.
Definition System.cpp:551
void updateQuadratic(const unsigned int &id, const float &quadratic)
Updates the light quadratic value.
Definition System.cpp:605
void updateLinear(const unsigned int &id, const float &linear)
Updates the light linear value.
Definition System.cpp:599
void updateMaterial(const unsigned int &id, const Material &material)
Updates the material of the entity given.
Definition System.cpp:522
Material getMaterial(const unsigned int &id)
Retrieves the material of the given entity.
Definition System.cpp:480
std::string getMaterialName(const unsigned int &id)
Retrieves the material name of the entity given.
Definition System.cpp:487
void updateDiffuse(const unsigned int &id, const glm::vec3 &val)
Updates the diffuse vector of a material.
Definition System.cpp:501
void updateShininess(const unsigned int &id, const float &val)
Updates the shininess value of a material.
Definition System.cpp:515
void updateSpecular(const unsigned int &id, const glm::vec3 &val)
Updates the specular vector of a material.
Definition System.cpp:508
void updateAmbient(const unsigned int &id, const glm::vec3 &val)
Updates the ambient vector of a material.
Definition System.cpp:494
All utilities for a parent entity.
void addChild(const unsigned int &parent, const unsigned int &child)
Adds a child to the parent entity.
Definition System.cpp:375
void removeChild(const unsigned int &parent, const unsigned int &child)
Removes the given child from the parent entity.
Definition System.cpp:382
All utilities for rendering entities.
void renderSkybox(const unsigned int &id, const Shared< ogl::ShaderProgram > &shader)
This method draws the Skybox of the scene.
Definition System.cpp:737
void getOtherLightData(LightShaderBlock &block, const Shared< LightComponent > &light)
Retrieves all the light data and stores them in a shader block.
Definition System.cpp:645
std::array< LightShaderBlock, SHADER_MAX_LIGHTS > prepareLightData()
Prepares data of all lights in the scene and put them in an array with defined size.
Definition System.cpp:673
std::vector< glm::vec3 > getBoxLines(glm::vec3 &botLeft, glm::vec3 &topRight)
This method calculates the lines to be drawn from two corners of a ColliderComponent.
Definition System.cpp:856
void renderInstancedMeshes()
Renders all entities with instanced rendering available.
Definition System.cpp:852
void prepareInstancedMesh(const std::vector< glm::mat4 > &models, const std::vector< glm::vec4 > &colors)
This methods calls the renderer and prepares the buffers with the model matrixes and colors.
Definition System.cpp:641
void initStencilShader()
Initialize the stencil shader.
Definition System.cpp:637
void renderBoundingBox()
Renders all bounding box of the entities with a ColliderComponent.
Definition System.cpp:891
void sendOtherLightData(const Shared< ogl::ShaderProgram > &shader, LightShaderBlock &data, size_t &index)
This method sends to the used shader program the specific data for that light caster.
Definition System.cpp:692
void renderAllMeshes()
Renders all the entities in the scene.
Definition System.cpp:749
void sendLightDataShader(const Shared< ogl::ShaderProgram > &shader, std::array< LightShaderBlock, SHADER_MAX_LIGHTS > data)
This method sends to the used shader program the common lights data.
Definition System.cpp:720
All utilities to manage entities texture.
void setTexture(const unsigned int &id, const ogl::Texture &texture)
Sets the texture for the given entity.
Definition System.cpp:440
void setMeshReflective(const unsigned int &id, const bool &val)
Sets the reflectiveness of an entity.
Definition System.cpp:471
std::string getTexturePath(const unsigned int &id)
Retrieves the entity texture path.
Definition System.cpp:447
ogl::Texture getTexture(const unsigned int &id)
Retrieves the texture of the given entity.
Definition System.cpp:434
void updateTexturePath(const unsigned int &id, const std::string &path)
Updates the entity texture path.
Definition System.cpp:453
bool isMeshReflective(const unsigned int &id)
This method sets the reflection of an entity. If the entity is reflective it will reflect the skybox ...
Definition System.cpp:465
All the methods to manipulate the Transform component.
void addScale(const unsigned int &id, const glm::vec3 &offset)
Adds an offset to the scale of the given entity.
Definition System.cpp:145
void updateScale(const unsigned int &id, const glm::vec3 &scale)
Updates the scale of the given entity.
Definition System.cpp:107
void addRotation(const unsigned int &id, const glm::vec3 &offset)
Adds an offset to the rotation of the given entity.
Definition System.cpp:152
glm::vec3 getPosition(const unsigned int &id)
Retrieves the position of the given entity.
Definition System.cpp:159
void updateRotation(const unsigned int &id, const glm::vec3 &rotation)
Updates the rotation of the given entity.
Definition System.cpp:114
void updateModelMatrix(const unsigned int &id)
Updates the model matrix of the given entity.
Definition System.cpp:189
glm::vec3 getScale(const unsigned int &id)
Retrieves the scale of the given entity.
Definition System.cpp:166
void addPosition(const unsigned int &id, const glm::vec3 &offset)
Adds an offset to the position of the given entity.
Definition System.cpp:128
glm::mat4 getModelMatrix(const unsigned int &id)
Retrieves the model matrix of the given entity.
Definition System.cpp:180
void updateAllModelMatrix()
Updates all model matrix of each entity with the Transform component.
Definition System.cpp:198
void updatePosition(const unsigned int &id, const glm::vec3 &position)
Updates the position of the given entity.
Definition System.cpp:90
glm::vec3 getRotation(const unsigned int &id)
Retrieves the rotation of the given entity.
Definition System.cpp:173
It contains all the ECS systems.
Data structure for instanced mesh rendering. It stores for each primitive its color and model matrix.
Definition System.hpp:15
std::vector< unsigned int > spheresIds
spheres id
Definition System.hpp:19
std::vector< glm::mat4 > spheresModel
spheres model matrix
Definition System.hpp:23
std::vector< glm::vec4 > spheresColor
spheres color
Definition System.hpp:21
unsigned int nspheres
spheres counter
Definition System.hpp:17
Definition Utils.hpp:55
Definition Utils.hpp:4