Raftel Engine
 
Loading...
Searching...
No Matches
components.hpp
1#ifndef __LIGHT_COMPONENTS_HPP__
2#define __LIGHT_COMPONENTS_HPP__ 1
3#pragma once
4#include <glm/glm.hpp>
5#include <glm/gtc/matrix_transform.hpp>
6#include <glm/gtx/quaternion.hpp>
7#include <glm/gtc/matrix_access.hpp>
8#include <raftel/mesh.hpp>
9#include "raftel/shadow.hpp"
10#include <lua.hpp>
11
12
13namespace Raftel {
14
19 {
23 BasicComponent(): name(std::string(" ")) {}
28 void SetName(std::string n_) { name = n_; }
29
30 std::string name;
31 };
32
37 glm::vec3 position;
38 glm::vec3 rotation;
39 glm::vec3 scale;
40 glm::mat4 transform;
41
46 glm::vec3 GetUpVector() const{
47 return glm::normalize(glm::column(transform, 1));
48 }
49
53 glm::vec3 GetRightVector() const
54 {
55 return glm::normalize(glm::column(transform, 0));
56 }
57
61 glm::vec3 GetForwardVector() const
62 {
63 return glm::normalize(glm::column(transform, 2));
64 }
65
68 TransformComponent() : position(1.0f), rotation(1.0f), scale(1.0f), transform(1.0f) {}
75 TransformComponent(const glm::vec3& pos, const glm::vec3& rot, const glm::vec3& sca)
76 : position(pos), rotation(rot), scale(sca), transform(1.0f) {}
77
80 void Update() {
81 transform = glm::mat4(1.0f);
82 glm::mat4 translationMatrix = glm::translate(transform, position);
83 //solucion gymball lock
84 auto quat = glm::quat(glm::radians(rotation));
85 glm::mat4 rotationMatrix = glm::mat4_cast(quat);
86 glm::mat4 scaleMatrix = glm::scale(transform, scale);
87 transform = translationMatrix * rotationMatrix * scaleMatrix;
88 }
89 };
90
95 std::weak_ptr<Mesh> mesh;
96 };
97
107 RenderComponent(bool vis) : visible(vis) {}
108 };
109
114 public:
119 ScriptComponent(const std::string& script);
124 MOVABLE_BUT_NOT_COPYABLE(ScriptComponent)
125
126
130 void ExecuteFunction(const std::string& functionName);
131
132 lua_State* luaState;
133 std::string scriptCode;
134 bool enabled = true;
135 bool pause = true;
136 };
137
151
152 glm::vec3 color;
153 float intensity;
154 float range;
155 float innerCone;
156 float outerCone;
157 float near;
158 float far;
159 std::unique_ptr<ShadowMap> shadowMap;
160
166 void CalculateShadowMatrix(const TransformComponent& tr, const class Camera& cam);
167
172 void move(LightComponent& other);
173
174 float fov;
175 std::vector<glm::mat4> lightSpaceMatrix;
176
187 LightComponent(LightType lt, glm::vec3 color_, float intensity_, float range_, float inner_, float outer_, glm::ivec2 screenSize);
188 MOVABLE_BUT_NOT_COPYABLE(LightComponent)
189
190 };
191
192}
193
194#endif
Camera class for handling movement and view transformations.
Definition camera.hpp:27
ScriptComponent(const std::string &script)
Constructs a script component with the given script code.
~ScriptComponent()
Destructor that cleans up the Lua state.
void ExecuteFunction(const std::string &functionName)
Executes a Lua function within the script.
Defines the Vertex, Mesh, and MeshFactory for handling and rendering 3D mesh data.
Header file for managing the shadow map in OpenGL.
BasicComponent()
Default constructor.
void SetName(std::string n_)
Sets the name of the component.
std::unique_ptr< ShadowMap > shadowMap
void move(LightComponent &other)
Moves the attributes of another LightComponent instance.
std::vector< glm::mat4 > lightSpaceMatrix
void CalculateShadowMatrix(const TransformComponent &tr, const class Camera &cam)
Calculates the shadow matrix for the light.
LightComponent(LightType lt, glm::vec3 color_, float intensity_, float range_, float inner_, float outer_, glm::ivec2 screenSize)
Constructs a light component with given parameters.
LightType
Enumeration of light types.
Represents a mesh component.
std::weak_ptr< Mesh > mesh
RenderComponent(bool vis)
Constructor for render component.
Represents the transformation component of an entity.
TransformComponent()
Default constructor initializing transformation parameters.
void Update()
Updates the transformation matrix.
TransformComponent(const glm::vec3 &pos, const glm::vec3 &rot, const glm::vec3 &sca)
Constructor initializing with position, rotation, and scale.
glm::vec3 GetRightVector() const
Gets the right vector of the transformation.
glm::vec3 GetUpVector() const
Gets the up vector of the transformation.
glm::vec3 GetForwardVector() const
Gets the forward vector of the transformation.