Point lights
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user