291 lines
11 KiB
C++
291 lines
11 KiB
C++
#include "HydraPlanetActor.h"
|
|
#include "HydraPlanetQuadActor.h"
|
|
#include "../../engine/HydraEngine.h"
|
|
#include "../../actor/HydraActorManager.h"
|
|
#include "../../task/HydraTask.h"
|
|
#include "../../ecs/HydraECS.h"
|
|
#include "../../ecs/components/HydraPositionComponent.h"
|
|
#include "../../ecs/components/HydraMeshComponent.h"
|
|
#include "../../ecs/components/HydraRenderableComponent.h"
|
|
#include "../../ecs/components/HydraMaterialComponent.h"
|
|
#include "../../ecs/components/HydraTickComponent.h"
|
|
#include "../../buffer/HydraMaterialBufferManager.h"
|
|
#include "../../buffer/HydraTextureBufferManager.h"
|
|
#include "../../buffer/HydraMaterialBuffer.h"
|
|
#include "../../mesh/HydraMeshManager.h"
|
|
#include "../../mesh/HydraMesh.h"
|
|
|
|
void HydraPlanetActor::FixedTick(float delta_t)
|
|
{
|
|
HydraID player_id = GetEngine()->GetPossessedPlayer();
|
|
HydraPositionComponent pos_comp = GetEngine()->ECS()->GetComponent<HydraPositionComponent>(player_id);
|
|
HydraActorManager* actor_manager = GetEngine()->ActorManager();
|
|
HydraECS* ecs = GetEngine()->ECS();
|
|
|
|
HydraPlanetQuadActor* quad0 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[0]));
|
|
HydraPlanetQuadActor* quad1 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[1]));
|
|
HydraPlanetQuadActor* quad2 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[2]));
|
|
HydraPlanetQuadActor* quad3 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[3]));
|
|
HydraPlanetQuadActor* quad4 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[4]));
|
|
HydraPlanetQuadActor* quad5 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[5]));
|
|
|
|
quad0->CheckResolution(pos_comp.position);
|
|
quad1->CheckResolution(pos_comp.position);
|
|
quad2->CheckResolution(pos_comp.position);
|
|
quad3->CheckResolution(pos_comp.position);
|
|
quad4->CheckResolution(pos_comp.position);
|
|
quad5->CheckResolution(pos_comp.position);
|
|
}
|
|
|
|
void HydraPlanetActor::InitialiseComponents()
|
|
{
|
|
// HydraECS* ecs = GetEngine()->ECS();
|
|
// HydraID entity_id = ecs->CreateEntity();
|
|
_CreatePosition();
|
|
// _CreatePhysics();
|
|
|
|
//_CreateMaterial();
|
|
//_CreateMesh();
|
|
//_CreateRenderableComponent();
|
|
_CreateQuads();
|
|
_CreateTick();
|
|
}
|
|
|
|
void HydraPlanetActor::DeferredInitialiseComponents()
|
|
{
|
|
|
|
}
|
|
|
|
void HydraPlanetActor::_CreateTick()
|
|
{
|
|
HydraECS *ecs = GetEngine()->ECS();
|
|
HydraTickComponent tick_component;
|
|
tick_component.entity_id = GetID();
|
|
tick_component.fixed = true;
|
|
ecs->AddComponent<HydraTickComponent>(GetID(), tick_component);
|
|
}
|
|
void HydraPlanetActor::_CreatePosition()
|
|
{
|
|
HydraECS *ecs = GetEngine()->ECS();
|
|
HydraPositionComponent position_component;
|
|
|
|
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
|
|
}
|
|
|
|
void HydraPlanetActor::_CreateMesh()
|
|
{
|
|
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
|
HydraID mesh_id = mesh_manager->CreateMesh();
|
|
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
|
|
|
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
|
|
|
|
mesh->vertexes.resize(24);
|
|
mesh->indexes.resize(36);
|
|
|
|
float scale_x = 10000.0f;
|
|
float scale_y = 10000.0f;
|
|
float scale_z = 10000.0f;
|
|
|
|
float min_x = -0.5f * scale_x;
|
|
float min_y = -0.5f * scale_y;
|
|
float min_z = -0.5f * scale_z;
|
|
|
|
float max_x = 0.5f * scale_x;
|
|
float max_y = 0.5f * scale_y;
|
|
float max_z = 0.5f * scale_z;
|
|
|
|
float min_u = 100;
|
|
float min_v = 100;
|
|
|
|
float max_u = 0;
|
|
float max_v = 0;
|
|
|
|
// 1---2 5---6
|
|
//| / | | / |
|
|
// 0---3 4---7
|
|
|
|
HydraID actor_id = GetID();
|
|
mesh->vertexes[0] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
|
|
// Face 0
|
|
mesh->indexes[0] = 0;
|
|
mesh->indexes[1] = 1;
|
|
mesh->indexes[2] = 2;
|
|
|
|
mesh->indexes[3] = 0;
|
|
mesh->indexes[4] = 2;
|
|
mesh->indexes[5] = 3;
|
|
|
|
mesh->vertexes[4] = {max_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[5] = {max_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[6] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[7] = {max_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
|
|
mesh->indexes[6] = 4;
|
|
mesh->indexes[7] = 5;
|
|
mesh->indexes[8] = 6;
|
|
|
|
mesh->indexes[9] = 4;
|
|
mesh->indexes[10] = 6;
|
|
mesh->indexes[11] = 7;
|
|
|
|
// Back Face
|
|
mesh->vertexes[8] = {max_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[9] = {max_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[10] = {min_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[11] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
|
|
mesh->indexes[12] = 8;
|
|
mesh->indexes[13] = 9;
|
|
mesh->indexes[14] = 10;
|
|
|
|
mesh->indexes[15] = 8;
|
|
mesh->indexes[16] = 10;
|
|
mesh->indexes[17] = 11;
|
|
|
|
mesh->vertexes[12] = {min_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[13] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[14] = {min_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[15] = {min_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
|
|
mesh->indexes[18] = 12;
|
|
mesh->indexes[19] = 13;
|
|
mesh->indexes[20] = 14;
|
|
|
|
mesh->indexes[21] = 12;
|
|
mesh->indexes[22] = 14;
|
|
mesh->indexes[23] = 15;
|
|
|
|
mesh->vertexes[16] = {min_x, max_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[17] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[18] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[19] = {max_x, max_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
|
|
mesh->indexes[24] = 16;
|
|
mesh->indexes[25] = 17;
|
|
mesh->indexes[26] = 18;
|
|
|
|
mesh->indexes[27] = 16;
|
|
mesh->indexes[28] = 18;
|
|
mesh->indexes[29] = 19;
|
|
|
|
mesh->vertexes[20] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[21] = {max_x, min_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[22] = {max_x, min_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
|
mesh->vertexes[23] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
|
|
|
mesh->indexes[30] = 20;
|
|
mesh->indexes[31] = 21;
|
|
mesh->indexes[32] = 22;
|
|
|
|
mesh->indexes[33] = 20;
|
|
mesh->indexes[34] = 22;
|
|
mesh->indexes[35] = 23;
|
|
|
|
mesh_manager->CalculateNormals(mesh->mesh_id);
|
|
|
|
HydraECS *ecs = GetEngine()->ECS();
|
|
HydraMeshComponent mesh_comp;
|
|
|
|
mesh_comp.mesh_id = mesh_id;
|
|
mesh_comp.mesh_state = HYDRA_STATE::Waiting;
|
|
|
|
ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
|
|
}
|
|
|
|
void HydraPlanetActor::_CreateMaterial()
|
|
{
|
|
|
|
HydraEngine *engine = GetEngine();
|
|
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo_white.png");
|
|
|
|
HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
|
|
|
|
HydraMaterialBuffer material = {};
|
|
|
|
material.diffuse_texture_id = tex_id;
|
|
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
|
|
material.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
|
|
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
|
|
|
|
HydraMaterialComponent mat_comp = {};
|
|
mat_comp.material_id = mat_id;
|
|
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
|
|
}
|
|
|
|
void HydraPlanetActor::_CreatePhysics()
|
|
{
|
|
// HydraECSPhysicsComponent physics_component;
|
|
// physics_component.physics_state = Hydra_State::Waiting;
|
|
// physics_component.physics_definition.actor_id = GetID();
|
|
// physics_component.physics_definition.physics_type = HydraPhyicsType::Static;
|
|
// physics_component.physics_definition.physics_shape = HydraPhysicsShape::HydraBoxShape;
|
|
// physics_component.physics_definition.mass = 100000.0f;
|
|
// physics_component.physics_definition.extent_x = 1000.0f;
|
|
// physics_component.physics_definition.extent_y = 0.5f;
|
|
// physics_component.physics_definition.extent_z = 1000.0f;
|
|
// physics_component.physics_definition.dynamic_friction = 0.5f;
|
|
// physics_component.physics_definition.restitution = 0.5f;
|
|
|
|
// HydraECS* ecs = GetEngine()->ECS();
|
|
|
|
// ecs->AddComponent<HydraECSPhysicsComponent>(GetID(), physics_component);
|
|
}
|
|
void HydraPlanetActor::_CreateRenderableComponent()
|
|
{
|
|
HydraRenderableComponent render_comp;
|
|
HydraECS *ecs = GetEngine()->ECS();
|
|
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
|
|
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
|
|
}
|
|
|
|
void HydraPlanetActor::_CreateQuads()
|
|
{
|
|
uint32_t divisions = 64;
|
|
float diameter = 50000.0f;
|
|
float quad_size = 50000.0f;
|
|
float half_quad = quad_size / 2.0f;
|
|
float radius = diameter / 2.0f;
|
|
|
|
m_quads[0] = GetEngine()->ActorManager()->CreateActor<HydraPlanetQuadActor>();
|
|
HydraPlanetQuadActor* quad0 = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(m_quads[0]));
|
|
GetEngine()->ActorManager()->InitialiseActor(m_quads[0]);
|
|
quad0->InitialiseQuad(INVALID_HYDRA_ID, diameter, quad_size, divisions, glm::vec3(0,0,0), glm::vec3(0,0,0));
|
|
GetEngine()->ActorManager()->SetRelationship(GetID(), m_quads[0]);
|
|
|
|
m_quads[1] = GetEngine()->ActorManager()->CreateActor<HydraPlanetQuadActor>();
|
|
HydraPlanetQuadActor* quad1 = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(m_quads[1]));
|
|
GetEngine()->ActorManager()->InitialiseActor(m_quads[1]);
|
|
quad1->InitialiseQuad(INVALID_HYDRA_ID, diameter, quad_size, divisions, glm::vec3(0, 0, 0), glm::vec3(0,glm::radians(90.0f),0));
|
|
GetEngine()->ActorManager()->SetRelationship(GetID(), m_quads[1]);
|
|
|
|
m_quads[2] = GetEngine()->ActorManager()->CreateActor<HydraPlanetQuadActor>();
|
|
HydraPlanetQuadActor* quad2 = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(m_quads[2]));
|
|
GetEngine()->ActorManager()->InitialiseActor(m_quads[2]);
|
|
quad2->InitialiseQuad(INVALID_HYDRA_ID, diameter, quad_size, divisions, glm::vec3(0, 0, 0), glm::vec3(0,glm::radians(180.0f),0));
|
|
GetEngine()->ActorManager()->SetRelationship(GetID(), m_quads[2]);
|
|
|
|
m_quads[3] = GetEngine()->ActorManager()->CreateActor<HydraPlanetQuadActor>();
|
|
HydraPlanetQuadActor* quad3 = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(m_quads[3]));
|
|
GetEngine()->ActorManager()->InitialiseActor(m_quads[3]);
|
|
quad3->InitialiseQuad(INVALID_HYDRA_ID, diameter, quad_size, divisions, glm::vec3(0, 0, 0), glm::vec3(0,glm::radians(270.0f),0));
|
|
GetEngine()->ActorManager()->SetRelationship(GetID(), m_quads[3]);
|
|
|
|
m_quads[4] = GetEngine()->ActorManager()->CreateActor<HydraPlanetQuadActor>();
|
|
HydraPlanetQuadActor* quad4 = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(m_quads[4]));
|
|
GetEngine()->ActorManager()->InitialiseActor(m_quads[4]);
|
|
quad4->InitialiseQuad(INVALID_HYDRA_ID, diameter, quad_size, divisions, glm::vec3(0, 0, 0), glm::vec3(glm::radians(-90.0f), 0, 0));
|
|
GetEngine()->ActorManager()->SetRelationship(GetID(), m_quads[4]);
|
|
|
|
m_quads[5] = GetEngine()->ActorManager()->CreateActor<HydraPlanetQuadActor>();
|
|
HydraPlanetQuadActor* quad5 = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(m_quads[5]));
|
|
GetEngine()->ActorManager()->InitialiseActor(m_quads[5]);
|
|
quad5->InitialiseQuad(INVALID_HYDRA_ID, diameter, quad_size, divisions, glm::vec3(0, 0, 0), glm::vec3(glm::radians(90.0f), 0, 0));
|
|
GetEngine()->ActorManager()->SetRelationship(GetID(), m_quads[5]);
|
|
|
|
}
|