Point lights

This commit is contained in:
Confideo-IOM
2026-08-28 16:36:25 +01:00
parent 30538ae7ab
commit e3d37e3f8a
60 changed files with 458 additions and 184 deletions
-5
View File
@@ -2,8 +2,3 @@
#include "HydraActorManager.h"
#include "../engine/HydraEngine.h"
#include "../ecs/HydraECS.h"
void HydraActor::Delete()
{
GetEngine()->ECS()->DestroyEntity(GetID());
}
+1 -1
View File
@@ -16,7 +16,7 @@ class CLASS_DEFINE HydraActor : public HydraObject
std::vector<HydraID> m_children;
std::vector<uint32_t> m_component_types;
uint32_t m_components_waiting = 0;
void Delete();
friend class HydraActorManager;
friend class HydraDeleteActorTask;
protected:
+15 -8
View File
@@ -35,7 +35,7 @@ void HydraActorManager::DeleteActor(HydraID actorID)
if(m_actors[actorID] != nullptr)
{
m_actors[actorID]->Delete();
GetEngine()->ECS()->DestroyEntity(actorID);
_SetActorDeleted(actorID);
}
@@ -194,15 +194,22 @@ void HydraActorManager::SetLinearVelocity(HydraID actor_id, glm::vec3 velocity)
void HydraActorManager::SetPositionAndOrientation(HydraID actorID, glm::dvec3 position, glm::vec3 euler_angles, bool ignore_physics)
{
HydraECS *ecs = GetEngine()->ECS();
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
pos_comp.position = position;
pos_comp.orientation = glm::vec3(euler_angles.x,euler_angles.y,euler_angles.z);
if(!pos_comp.needs_update)
if(ecs->HasComponent<HydraPositionComponent>(actorID))
{
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID, ignore_physics);
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
pos_comp.position = position;
pos_comp.orientation = glm::vec3(euler_angles.x,euler_angles.y,euler_angles.z);
if(!pos_comp.needs_update)
{
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID, ignore_physics);
}
}
else
{
std::cout << "HERE";
}
}
void HydraActorManager::SetScale(HydraID actor_id, glm::dvec3 scaling)
@@ -21,8 +21,8 @@ void HydraDirectionalLightActor::InitialiseComponents()
HydraLightComponent light_comp = {};
HydraECS *ecs = GetEngine()->ECS();
light_comp.diffuse = glm::vec4(1.0,0.8,0.6,1);
light_comp.intensity = 100000.0f;
light_comp.diffuse = glm::vec4(1.0f, 1.0f, 1.0f ,1.0f);
light_comp.intensity = 1000.0f;
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_DIRECTIONAL);
light_comp.entity_id = GetID();
light_comp.shadow_caster =1;
+1 -1
View File
@@ -175,7 +175,7 @@ void HydraPlaneActor::_CreateMaterial()
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
material.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
@@ -47,7 +47,7 @@ void HydraPlayerActor::HandleInput(float delta_t)
bool move_right = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_D);
HydraRenderSettings render_settings = GetEngine()->RenderSettings();
float scale = 0.2f;
float scale = 1.0f;
float x_angle = (change.x / render_settings.DisplayWidth) * -500 * delta_t * scale;
float y_angle = (change.y / render_settings.DisplayHeight) * -500 * delta_t * scale;
@@ -8,6 +8,8 @@
#include "../ecs/components/HydraRenderableComponent.h"
#include "../ecs/components/HydraMaterialComponent.h"
#include "../ecs/components/HydraPhysicsComponent.h"
#include "../ecs/components/HydraShadowCasterComponent.h"
#include "../ecs/components/HydraLightComponent.h"
#include "../buffer/HydraMaterialBufferManager.h"
#include "../buffer/HydraTextureBufferManager.h"
#include "../buffer/HydraMaterialBuffer.h"
@@ -24,6 +26,7 @@ void HydraTestCubeActor::InitialiseComponents()
_CreateMaterial();
_CreateMesh();
_CreateRenderableComponent();
_CreateLightComponent();
}
void HydraTestCubeActor::DeferredInitialiseComponents()
@@ -174,7 +177,8 @@ void HydraTestCubeActor::_CreateMaterial()
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
material.emmissive_metalic_rough = glm::vec4(0.0f, 0.5f, 0.3f, 1.0f);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
@@ -199,7 +203,23 @@ void HydraTestCubeActor::_CreatePhysics()
void HydraTestCubeActor::_CreateRenderableComponent()
{
HydraRenderableComponent render_comp;
HydraShadowCasterComponent shad_caster;
HydraECS *ecs = GetEngine()->ECS();
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_SHADOW_CASTER, true);
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
ecs->AddComponent<HydraShadowCasterComponent>(GetID(), shad_caster);
}
void HydraTestCubeActor::_CreateLightComponent()
{
HydraLightComponent light_comp = {};
HydraECS *ecs = GetEngine()->ECS();
light_comp.diffuse = glm::vec4(1,1,1,1);
light_comp.intensity = 1000.0f;
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_POINT);
light_comp.entity_id = GetID();
ecs->AddComponent<HydraLightComponent>(GetID(), light_comp);
}
@@ -18,6 +18,7 @@ class CLASS_DEFINE HydraTestCubeActor : public HydraActor
void _CreateMaterial();
void _CreatePhysics();
void _CreateRenderableComponent();
void _CreateLightComponent();
public:
virtual void InitialiseComponents();
virtual void DeferredInitialiseComponents();
@@ -7,6 +7,7 @@
#include "../ecs/components/HydraMeshComponent.h"
#include "../ecs/components/HydraRenderableComponent.h"
#include "../ecs/components/HydraMaterialComponent.h"
#include "../ecs/components/HydraLightComponent.h"
#include "../buffer/HydraMaterialBufferManager.h"
#include "../buffer/HydraTextureBufferManager.h"
#include "../buffer/HydraMaterialBuffer.h"
@@ -23,6 +24,7 @@ void HydraTestLightActor::InitialiseComponents()
_CreateMaterial();
_CreateMesh();
_CreateRenderableComponent();
}
void HydraTestLightActor::DeferredInitialiseComponents()
@@ -173,7 +175,7 @@ void HydraTestLightActor::_CreateMaterial()
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
material.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
@@ -181,7 +183,6 @@ void HydraTestLightActor::_CreateMaterial()
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
}
void HydraTestLightActor::_CreateRenderableComponent()
{
HydraRenderableComponent render_comp;
@@ -189,3 +190,4 @@ void HydraTestLightActor::_CreateRenderableComponent()
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
}
@@ -18,6 +18,7 @@ class CLASS_DEFINE HydraTestLightActor : public HydraActor
void _CreateMesh();
void _CreateMaterial();
void _CreateRenderableComponent();
public:
virtual void InitialiseComponents();
virtual void DeferredInitialiseComponents();
@@ -24,11 +24,26 @@ void HydraLightSpawnerActor::FixedTick(float delta_t)
actor_manager->InitialiseActor(actor_id);
actor_manager->SetPosition(actor_id, pos_comp.position);
actor_manager->SetLinearVelocity(actor_id, m_spawn_direction * m_spawn_velocity);
m_last_tick = current_tick;
SpawnedActor actor = {};
actor.actor_id = actor_id;
actor.spawned_time = current_tick;
m_spawned_actors.push(actor);
m_last_tick = current_tick;
}
if(m_spawned_actors.size() > 0)
{
SpawnedActor actor = m_spawned_actors.front();
long actor_spawned_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(current_tick - actor.spawned_time).count();
if(actor_spawned_time_ms > (m_spawn_duration * 1000.0f ))
{
GetEngine()->ActorManager()->DeleteActor(actor.actor_id);
m_spawned_actors.pop();
}
}
}
}
void HydraLightSpawnerActor::_CreatePosition()
@@ -5,6 +5,13 @@
#include <chrono>
#include <queue>
#include <GLMIncludes.h>
struct SpawnedActor
{
HydraID actor_id;
std::chrono::time_point<std::chrono::steady_clock> spawned_time;
};
class CLASS_DEFINE HydraLightSpawnerActor : public HydraActor
{
public:
@@ -30,7 +37,7 @@ class CLASS_DEFINE HydraLightSpawnerActor : public HydraActor
float m_interval = 0.0f;
bool m_enabled = false;
std::chrono::time_point<std::chrono::steady_clock> m_last_tick;
std::queue<HydraID> m_spawned_actors;
std::queue<SpawnedActor> m_spawned_actors;
};
@@ -8,6 +8,7 @@
#include "../../ecs/components/HydraRenderableComponent.h"
#include "../../ecs/components/HydraMaterialComponent.h"
#include "../../ecs/components/HydraPhysicsComponent.h"
#include "../../ecs/components/HydraLightComponent.h"
#include "../../buffer/HydraMaterialBufferManager.h"
#include "../../buffer/HydraTextureBufferManager.h"
#include "../../buffer/HydraMaterialBuffer.h"
@@ -22,6 +23,7 @@ void HydraSpawnedLightActor::InitialiseComponents()
_CreateMaterial();
_CreateMesh();
_CreateRenderableComponent();
_CreateLightComponent();
}
void HydraSpawnedLightActor::DeferredInitialiseComponents()
@@ -46,9 +48,9 @@ void HydraSpawnedLightActor::_CreateMesh()
mesh->vertexes.resize(24);
mesh->indexes.resize(36);
float scale_x = 0.3f;
float scale_y = 0.3f;
float scale_z = 0.3f;
float scale_x = 0.1f;
float scale_y = 0.1f;
float scale_z = 0.1f;
float min_x = -0.5f * scale_x;
float min_y = -0.5f * scale_y;
@@ -158,26 +160,41 @@ void HydraSpawnedLightActor::_CreateMesh()
mesh_comp.mesh_state = HYDRA_STATE::Waiting;
ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
}
void HydraSpawnedLightActor::_CreateMaterial()
{
HydraEngine *engine = GetEngine();
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo.png");
//std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo.png");
HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
//HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
HydraMaterialBuffer material = {};
std::srand(std::time({})); // use current time as seed for random generator
const float red = static_cast<float>(std::rand() % 2) + 0.1f;
const float green = static_cast<float>(std::rand() % 2)+ 0.1f;
const float blue = static_cast<float>(std::rand() % 2)+ 0.1f;
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
//material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(glm::normalize(glm::vec3(red, green, blue)), 1) * 10.0f;
material.emmissive_metalic_rough = glm::vec4(10.0f, 0.5f, 0.2f, 1.0f);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
mat_comp.material_id = mat_id;
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
HydraLightComponent light_comp = {};
HydraECS *ecs = GetEngine()->ECS();
light_comp.diffuse = glm::vec4(glm::normalize(glm::vec3(red, green, blue)), 1);
light_comp.intensity = 100.0f;
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_POINT);
light_comp.entity_id = GetID();
ecs->AddComponent<HydraLightComponent>(GetID(), light_comp);
}
void HydraSpawnedLightActor::_CreatePhysics()
@@ -188,9 +205,9 @@ void HydraSpawnedLightActor::_CreatePhysics()
phys_comp.phyics_type = HYDRA_PHYSICS_TYPE::HYDRA_RIGID_BODY;
phys_comp.physics_shape = HYDRA_PHYSICS_SHAPE::HYDRA_PHYSICS_BOX;
phys_comp.depth = 0.3f;
phys_comp.height = 0.3f;
phys_comp.width = 0.3f;
phys_comp.depth = 0.1f;
phys_comp.height = 0.1f;
phys_comp.width = 0.1f;
engine->ECS()->AddComponent<HydraPhysicsComponent>(GetID(), phys_comp);
}
@@ -198,6 +215,12 @@ void HydraSpawnedLightActor::_CreateRenderableComponent()
{
HydraRenderableComponent render_comp;
HydraECS *ecs = GetEngine()->ECS();
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
}
void HydraSpawnedLightActor::_CreateLightComponent()
{
}
@@ -16,6 +16,7 @@ class CLASS_DEFINE HydraSpawnedLightActor : public HydraActor
void _CreateMaterial();
void _CreatePhysics();
void _CreateRenderableComponent();
void _CreateLightComponent();
public:
void InitialiseComponents() override;
void DeferredInitialiseComponents() override;
@@ -174,7 +174,7 @@ void HydraPlanetActor::_CreateMaterial()
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
material.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
@@ -173,7 +173,7 @@ void HydraPlanetQuadActor::_CreateMaterial()
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
material.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};