initial commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
#include "HydraActor.h"
|
||||
#include "HydraActorManager.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef HYDRAACTOR
|
||||
#define HYDRAACTOR
|
||||
|
||||
#include "../engine/HydraObject.h"
|
||||
//#include "HydraActorManager.h"
|
||||
#include <vector>
|
||||
|
||||
//class HydraComponent;
|
||||
|
||||
class CLASS_DEFINE HydraActor : public HydraObject
|
||||
{
|
||||
private:
|
||||
HYDRA_ACTOR_STATE m_status = HYDRA_ACTOR_STATE::WAITING_FOR_INIT;
|
||||
HydraID m_id = INVALID_HYDRA_ID;
|
||||
HydraID m_parent_id = INVALID_HYDRA_ID;
|
||||
std::vector<HydraID> m_children;
|
||||
std::vector<uint32_t> m_component_types;
|
||||
uint32_t m_components_waiting = 0;
|
||||
friend class HydraActorManager;
|
||||
friend class HydraDeleteActorTask;
|
||||
protected:
|
||||
bool m_fixed_tick =false;
|
||||
public:
|
||||
std::string Name;
|
||||
virtual ~HydraActor(){};
|
||||
virtual void InitialiseComponents() = 0;
|
||||
virtual void DeferredInitialiseComponents() {};
|
||||
HydraID GetID() {return m_id;}
|
||||
virtual void FixedTick(float delta_t) {};
|
||||
virtual void Destroy() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* HYDRAACTOR */
|
||||
@@ -0,0 +1,525 @@
|
||||
|
||||
//
|
||||
#include "HydraActorManager.h"
|
||||
#include "../actor/HydraActor.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
#include "../ecs/HydraEntityManager.h"
|
||||
#include "../ecs/HydraECS.h"
|
||||
#include "../ecs/components/HydraPositionComponent.h"
|
||||
#include "../ecs/systems/HydraTransformSystem.h"
|
||||
#include "../fileaccess/HydraGLTFLoader.h"
|
||||
#include "../task/actor/HydraLoadGLTFFileTask.hpp"
|
||||
#include "../scheduler/HydraTaskScheduler.h"
|
||||
#include <stdio.h>
|
||||
|
||||
HydraActor *const HydraActorManager::GetActor(HydraID actorID)
|
||||
{
|
||||
if (actorID < MAX_ACTORS)
|
||||
{
|
||||
return m_actors[actorID];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<HydraID> &HydraActorManager::GetChildren(HydraID actor_id)
|
||||
{
|
||||
return m_actors[actor_id]->m_children;
|
||||
}
|
||||
|
||||
void HydraActorManager::DeleteActor(HydraID actorID)
|
||||
{
|
||||
m_actors_waiting_for_delete.push_back(actorID);
|
||||
}
|
||||
|
||||
void HydraActorManager::_SetActorDeleted(HydraID actorID)
|
||||
{
|
||||
if (m_actors[actorID] != nullptr)
|
||||
{
|
||||
delete m_actors[actorID];
|
||||
}
|
||||
m_actors[actorID] = nullptr;
|
||||
m_available_actor_ids.push_back(actorID);
|
||||
}
|
||||
|
||||
|
||||
HydraID HydraActorManager::LoadActor(std::string filename)
|
||||
{
|
||||
HydraID actor_id = INVALID_HYDRA_ID;
|
||||
HydraTaskScheduler* task_scheduler = GetEngine()->TaskScheduler();
|
||||
HydraID load_task_id = task_scheduler->CreateTask<HydraLoadGLTFFileTask>(HydraThreadAffinity::Render);
|
||||
HydraLoadGLTFFileTask* load_task = static_cast<HydraLoadGLTFFileTask*>(task_scheduler->GetTask(load_task_id));
|
||||
load_task->Initialise(filename, &actor_id);
|
||||
task_scheduler->WaitForTask(load_task_id);
|
||||
return actor_id;
|
||||
}
|
||||
/*
|
||||
HydraID HydraActorManager::_ProcessGLTFNode(aiScene const *scene, aiNode *parent_node, std::vector<uint32_t>material_lookup)
|
||||
{
|
||||
HydraID parent_actor_id = CreateActor<HydraGLTFActor>();
|
||||
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraECSPositionComponent position_component;
|
||||
|
||||
aiVector3D tmp_scaling = {};
|
||||
aiQuaternion tmp_rotation = {};
|
||||
aiVector3D tmp_position = {};
|
||||
|
||||
parent_node->mTransformation.Decompose(tmp_scaling, tmp_rotation, tmp_position);
|
||||
|
||||
glm::dvec3 scaling = glm::dvec3(tmp_scaling.x, tmp_scaling.y, tmp_scaling.z);
|
||||
glm::quat rotation = glm::quat(tmp_rotation.w, tmp_rotation.x, tmp_rotation.y, tmp_rotation.z);
|
||||
glm::dvec3 position = glm::dvec3(tmp_position.x, tmp_position.y, tmp_position.z);
|
||||
|
||||
ecs->AddComponent<HydraECSPositionComponent>(parent_actor_id, position_component);
|
||||
|
||||
SetPosition(parent_actor_id, position, rotation, false);
|
||||
|
||||
for (uint32_t i_mesh = 0; i_mesh < parent_node->mNumMeshes; i_mesh++)
|
||||
{
|
||||
aiMesh *mesh = scene->mMeshes[parent_node->mMeshes[i_mesh]];
|
||||
_ProcessGLTFMesh(scene, parent_actor_id, mesh, material_lookup);
|
||||
}
|
||||
|
||||
for (uint32_t i_node = 0; i_node < parent_node->mNumChildren; i_node++)
|
||||
{
|
||||
HydraID child_actor_id = _ProcessGLTFNode(scene, parent_node->mChildren[i_node], material_lookup);
|
||||
SetRelationship(parent_actor_id, child_actor_id);
|
||||
}
|
||||
return parent_actor_id;
|
||||
}
|
||||
|
||||
void HydraActorManager::_ProcessGLTFMesh(aiScene const *scene, HydraID parent_actor_id, aiMesh *mesh, std::vector<uint32_t>material_lookup)
|
||||
{
|
||||
HydraID mesh_actor_id = CreateActor<HydraGLTFActor>();
|
||||
aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex];
|
||||
std::vector<StandardVertexStruct> vertexes;
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
HydraECSPositionComponent position_component = {};
|
||||
|
||||
ecs->AddComponent<HydraECSPositionComponent>(mesh_actor_id, position_component);
|
||||
|
||||
|
||||
for (uint32_t i_face = 0; i_face < mesh->mNumFaces; i_face++)
|
||||
{
|
||||
aiFace face = mesh->mFaces[i_face];
|
||||
for (uint32_t i_index = 0; i_index < face.mNumIndices; i_index++)
|
||||
{
|
||||
uint32_t current_idx = face.mIndices[i_index];
|
||||
StandardVertexStruct vert = {};
|
||||
if (mesh->HasPositions())
|
||||
{
|
||||
vert.vertex[0] = mesh->mVertices[current_idx].x;
|
||||
vert.vertex[1] = mesh->mVertices[current_idx].y;
|
||||
vert.vertex[2] = mesh->mVertices[current_idx].z;
|
||||
}
|
||||
if (mesh->HasNormals())
|
||||
{
|
||||
vert.normal[0] = mesh->mNormals[current_idx].x;
|
||||
vert.normal[1] = mesh->mNormals[current_idx].y;
|
||||
vert.normal[2] = mesh->mNormals[current_idx].z;
|
||||
}
|
||||
if (mesh->HasTextureCoords(0))
|
||||
{
|
||||
vert.uv[0] = mesh->mTextureCoords[0][current_idx].x;
|
||||
vert.uv[1] = mesh->mTextureCoords[0][current_idx].y;
|
||||
}
|
||||
vert.indexes[0] = mesh_actor_id;
|
||||
vertexes.push_back(vert);
|
||||
}
|
||||
}
|
||||
|
||||
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
||||
|
||||
HydraID mesh_id = mesh_manager->CreateMesh(mesh_actor_id);
|
||||
mesh_manager->SetVertexes(mesh_id, vertexes);
|
||||
mesh_manager->CalculateNormals(mesh_id);
|
||||
|
||||
|
||||
HydraECSMeshComponent mesh_comp;
|
||||
mesh_comp.mesh_id = mesh_id;
|
||||
ecs->AddComponent<HydraECSMeshComponent>(mesh_actor_id, mesh_comp);
|
||||
aiString mat_name;
|
||||
mat->Get(AI_MATKEY_NAME, mat_name);
|
||||
|
||||
HydraID material_id = material_lookup[mesh->mMaterialIndex];
|
||||
if(material_id != INVALID_HYDRA_ID)
|
||||
{
|
||||
HydraECSMaterialComponent mat_comp;
|
||||
mat_comp.material_id = material_id;
|
||||
ecs->AddComponent<HydraECSMaterialComponent>(mesh_actor_id, mat_comp);
|
||||
HydraMaterialStruct const * const mat_data = GetEngine()->MaterialManager()->GetMaterial(material_id);
|
||||
GetEngine()->BufferManager()->AddMaterial(mesh_actor_id, material_id, *mat_data);
|
||||
}
|
||||
|
||||
mesh_manager->SetMeshWaiting(mesh_id);
|
||||
//Add renderable component
|
||||
HydraPipelineManager* pipeline_manager = GetEngine()->PipelineManager();
|
||||
|
||||
uint32_t pipeline_id = pipeline_manager->GetPipelineID("FORWARD");
|
||||
uint32_t shadow_pipeline_id = pipeline_manager->GetPipelineID("SHADOW");
|
||||
uint32_t deferred_pipeline_id = pipeline_manager->GetPipelineID("DEFERRED");
|
||||
|
||||
HydraECSRenderableComponent render_comp;
|
||||
|
||||
if(pipeline_id != INVALID_HYDRA_ID)
|
||||
{
|
||||
render_comp.pipelines.set(pipeline_id);
|
||||
}
|
||||
render_comp.pipelines.set(shadow_pipeline_id);
|
||||
render_comp.pipelines.set(deferred_pipeline_id);
|
||||
|
||||
ecs->AddComponent<HydraECSRenderableComponent>(mesh_actor_id, render_comp);
|
||||
SetRelationship(parent_actor_id, mesh_actor_id);
|
||||
}
|
||||
|
||||
/// @brief Load all of the scene textures
|
||||
/// @param scene containing scene
|
||||
/// @param texture_lookup index of texture in the scene to the Hydra texture ID
|
||||
void HydraActorManager::_ProcessGLTFTextures(aiScene const *scene, std::vector<uint32_t> &texture_lookup)
|
||||
{
|
||||
HydraTextureManager *texture_manager = GetEngine()->TextureManager();
|
||||
// Make space for the texture lookups
|
||||
texture_lookup.resize(scene->mNumTextures);
|
||||
|
||||
for (uint32_t i_tex = 0; i_tex < scene->mNumTextures; i_tex++)
|
||||
{
|
||||
aiTexture *tex = scene->mTextures[i_tex];
|
||||
// Create a holder for the texture
|
||||
HydraID texture_id = texture_manager->CreateTexture(0, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false);
|
||||
// load the texture data from the scene texture
|
||||
texture_manager->FillTexture(texture_id, reinterpret_cast<unsigned char *>(tex->pcData), tex->mWidth);
|
||||
// store the texture id against the scene index for the texture. Materials will have *n where n is the index
|
||||
texture_lookup[i_tex] = texture_id;
|
||||
texture_manager->FinaliseTexture(texture_id);
|
||||
}
|
||||
}
|
||||
|
||||
void HydraActorManager::_ProcessGLTFMaterials(aiScene const *scene,
|
||||
std::vector<uint32_t>& texture_lookup,
|
||||
std::vector<uint32_t>& material_lookup,
|
||||
std::string filename)
|
||||
{
|
||||
material_lookup.resize(scene->mNumMaterials);
|
||||
HydraTextureManager *texture_manager = GetEngine()->TextureManager();
|
||||
for (uint32_t i_mat = 0; i_mat < scene->mNumMaterials; i_mat++)
|
||||
{
|
||||
HydraMaterialStruct material;
|
||||
aiMaterial *mat = scene->mMaterials[i_mat];
|
||||
|
||||
aiColor3D color(0.f, 0.f, 0.f);
|
||||
aiString name;
|
||||
|
||||
mat->Get(AI_MATKEY_COLOR_DIFFUSE, color);
|
||||
mat->Get(AI_MATKEY_NAME, name);
|
||||
std::string mat_name = filename + std::to_string(i_mat);
|
||||
aiTexture diffuse_tex;
|
||||
|
||||
uint32_t diffuse_tex_count = mat->GetTextureCount(aiTextureType::aiTextureType_DIFFUSE);
|
||||
|
||||
// have to do something here for multiple diffuse textures at some point.
|
||||
aiString texture_path;
|
||||
aiTextureMapping texture_mapping;
|
||||
uint32_t uv_index;
|
||||
if (diffuse_tex_count > 0)
|
||||
{
|
||||
mat->GetTexture(aiTextureType::aiTextureType_DIFFUSE, 0, &texture_path, &texture_mapping, &uv_index);
|
||||
std::string path = std::string(texture_path.C_Str());
|
||||
uint32_t texture_index = atoi(path.substr(1).c_str());
|
||||
HydraID texture_id = texture_lookup[texture_index];
|
||||
|
||||
material.diffuse_texture = texture_id;
|
||||
material.texture_types += static_cast<uint32_t>(HYDRA_TEXTURE_TYPE::DIFFUSE_TEXTURE);
|
||||
}
|
||||
|
||||
material.diffuse_colour = glm::vec4(color.r, color.g, color.b, 1);
|
||||
|
||||
HydraID material_id = GetEngine()->MaterialManager()->CreateMaterial(mat_name, material);
|
||||
material_lookup[i_mat] = material_id;
|
||||
if (material_id == INVALID_HYDRA_ID)
|
||||
{
|
||||
throw std::runtime_error("Could not create material");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
HydraID HydraActorManager::_SaveActor(HydraActor *actor)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
if (m_available_actor_ids.size() > 0)
|
||||
{
|
||||
HydraID id = m_available_actor_ids.front();
|
||||
m_available_actor_ids.pop_front();
|
||||
actor->m_id = id;
|
||||
m_actors[id] = actor;
|
||||
|
||||
return id;
|
||||
}
|
||||
delete actor;
|
||||
return INVALID_HYDRA_ID;
|
||||
}
|
||||
|
||||
void HydraActorManager::Initialise(size_t max_actors)
|
||||
{
|
||||
m_max_actors = max_actors;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
m_actors.resize(max_actors);
|
||||
|
||||
for (int i = 0; i < max_actors; i++)
|
||||
{
|
||||
m_available_actor_ids.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HydraActorManager::TickActors(float delta_t)
|
||||
{
|
||||
// std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
// // HydraID barrierID = GetEngine()->TaskScheduler()->CreateBarrier();
|
||||
// for (int i = 0; i < m_actors_to_tick_fixed.size(); i++)
|
||||
// {
|
||||
// HydraID tick_actors_task_id = GetEngine()->TaskScheduler()->CreateTask<HydraFixedTickActorTask>(HydraThreadAffinity::General);
|
||||
// if (tick_actors_task_id != INVALID_HYDRA_ID)
|
||||
// {
|
||||
// ((HydraFixedTickActorTask *)(GetEngine()->TaskScheduler()->GetTask(tick_actors_task_id)))->Initialise(m_actors_to_tick_fixed[i], delta_t);
|
||||
|
||||
// GetEngine()->TaskScheduler()->StartTask(tick_actors_task_id);
|
||||
// }
|
||||
// }
|
||||
// GetEngine()->TaskScheduler()->WaitForBarrier(barrierID);
|
||||
}
|
||||
void HydraActorManager::InitialiseActor(HydraID actorID)
|
||||
{
|
||||
HydraActor *actor = GetActor(actorID);
|
||||
if (actor != nullptr)
|
||||
{
|
||||
// actor->InitialiseComponents();
|
||||
m_actors_waiting_for_init.push_back(actorID);
|
||||
}
|
||||
}
|
||||
|
||||
void HydraActorManager::Shutdown()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
// for (HydraID actor_id = 0; actor_id < MAX_ACTORS; actor_id++)
|
||||
// {
|
||||
// if (m_actors[actor_id] != nullptr)
|
||||
// {
|
||||
// HydraActor *actor = m_actors[actor_id];
|
||||
|
||||
// m_actors[actor_id]->m_status = HydraActorStatus::WAITING_FOR_DELETE;
|
||||
// _RemoveActorFromTickFixed(actor_id);
|
||||
// _RemoveActorFromWaiting(actor_id);
|
||||
// actor->Destroy();
|
||||
// // for (int i = 0; i < m_actors[actor_id]->m_component_types.size(); i++)
|
||||
// // {
|
||||
// // GetEngine()->ComponentManager()->DeleteComponent(m_actors[actor_id]->m_component_types[i], actor_id);
|
||||
// // }
|
||||
|
||||
// // HydraID delete_task_id = GetEngine()->TaskScheduler()->CreateTask<HydraDeleteActorTask>(HydraThreadAffinity::General);
|
||||
// // HydraDeleteActorTask *task = (HydraDeleteActorTask *)GetEngine()->TaskScheduler()->GetTask(delete_task_id);
|
||||
// // task->Initialise(actor_id);
|
||||
// // GetEngine()->TaskScheduler()->WaitForTask(delete_task_id);
|
||||
// }
|
||||
// _SetActorDeleted(actor_id);
|
||||
// }
|
||||
}
|
||||
|
||||
void HydraActorManager::RotateActor(HydraID actorID, float euler_x, float euler_y, float euler_z)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
|
||||
|
||||
pos_comp.orientation[0] += euler_x;
|
||||
pos_comp.orientation[1] += euler_y;
|
||||
pos_comp.orientation[2] += euler_z;
|
||||
pos_comp.needs_update = true;
|
||||
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
|
||||
}
|
||||
|
||||
|
||||
void HydraActorManager::SetPosition(HydraID actorID, glm::dvec3 position)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
|
||||
pos_comp.position = position;
|
||||
|
||||
|
||||
// if (ecs->HasComponent<HydraECSPhysicsComponent>(actorID))
|
||||
// {
|
||||
// HydraECSPhysicsComponent &phys_comp = ecs->GetComponent<HydraECSPhysicsComponent>(actorID);
|
||||
// // const float* matrix = glm::value_ptr<float>(GetActorPose(actorID));
|
||||
|
||||
// phys_comp.physics_definition.pose = GetActorPose(actorID);
|
||||
// }
|
||||
if(!pos_comp.needs_update)
|
||||
{
|
||||
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
|
||||
}
|
||||
}
|
||||
|
||||
void HydraActorManager::SetOrientation(HydraID actorID, float x, float y, float z)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
|
||||
pos_comp.orientation = glm::vec3(x, y, z);
|
||||
if(!pos_comp.needs_update)
|
||||
{
|
||||
|
||||
// if (ecs->HasComponent<HydraECSPhysicsComponent>(actorID))
|
||||
// {
|
||||
// HydraECSPhysicsComponent &phys_comp = ecs->GetComponent<HydraECSPhysicsComponent>(actorID);
|
||||
// phys_comp.physics_definition.pose = GetActorPose(actorID);
|
||||
// }
|
||||
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
|
||||
}
|
||||
}
|
||||
|
||||
void HydraActorManager::SetScale(HydraID actor_id, glm::dvec3 scaling)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actor_id);
|
||||
pos_comp.scale = glm::vec3(scaling);
|
||||
|
||||
|
||||
// if (ecs->HasComponent<HydraECSPhysicsComponent>(actorID))
|
||||
// {
|
||||
// HydraECSPhysicsComponent &phys_comp = ecs->GetComponent<HydraECSPhysicsComponent>(actorID);
|
||||
// phys_comp.physics_definition.pose = GetActorPose(actorID);
|
||||
// }
|
||||
if(!pos_comp.needs_update)
|
||||
{
|
||||
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actor_id);
|
||||
}
|
||||
}
|
||||
|
||||
void HydraActorManager::SetRelationship(HydraID parent_id, HydraID child_id)
|
||||
{
|
||||
HydraActor *parent_actor = GetActor(parent_id);
|
||||
HydraActor *child_actor = GetActor(child_id);
|
||||
child_actor->m_parent_id = parent_id;
|
||||
parent_actor->m_children.push_back(child_id);
|
||||
}
|
||||
|
||||
void HydraActorManager::TranslateActor(HydraID actorID, glm::dvec3 translation)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
|
||||
|
||||
pos_comp.position = pos_comp.position + translation;
|
||||
|
||||
|
||||
// if (ecs->HasComponent<HydraECSPhysicsComponent>(actorID))
|
||||
// {
|
||||
// HydraECSPhysicsComponent &phys_comp = ecs->GetComponent<HydraECSPhysicsComponent>(actorID);
|
||||
// // const float* matrix = glm::value_ptr<float>(GetActorPose(actorID));
|
||||
|
||||
// // std::copy(matrix, matrix + 16, phys_comp.physics_definition.pose);
|
||||
// phys_comp.physics_definition.pose = GetActorPose(actorID);
|
||||
// }
|
||||
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
|
||||
}
|
||||
|
||||
void HydraActorManager::AddComponentType(HydraID actorID, uint32_t component_type)
|
||||
{
|
||||
if (actorID < m_actors.size())
|
||||
{
|
||||
HydraActor *actor = m_actors[actorID];
|
||||
if (actor != nullptr)
|
||||
{
|
||||
actor->m_component_types.push_back(component_type);
|
||||
actor->m_components_waiting++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 HydraActorManager::GetActorPose(HydraID actorID)
|
||||
{
|
||||
|
||||
HydraPositionComponent &pos = GetEngine()->ECS()->GetComponent<HydraPositionComponent>(actorID);
|
||||
glm::mat4 model_matrix = pos.transform;
|
||||
// if (pos.needs_update)
|
||||
// {
|
||||
// glm::mat4 trans_matrix = glm::translate(pos.position);
|
||||
// glm::mat4 rot_matrix = glm::toMat4(glm::quat(pos.orientation));
|
||||
// model_matrix = trans_matrix * rot_matrix;
|
||||
// }
|
||||
return model_matrix;
|
||||
}
|
||||
|
||||
glm::vec3 HydraActorManager::GetActorOrientation(HydraID actorID)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
|
||||
return pos_comp.orientation;
|
||||
}
|
||||
|
||||
glm::vec3 HydraActorManager::GetActorVelocity(HydraID actorID)
|
||||
{
|
||||
|
||||
return glm::dvec3(0, 0, 0);
|
||||
}
|
||||
glm::dvec3 HydraActorManager::GetActorPosition(HydraID actorID)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
|
||||
|
||||
return pos_comp.position;
|
||||
}
|
||||
|
||||
bool HydraActorManager::HasComponentType(HydraID actorID, uint32_t component_type)
|
||||
{
|
||||
if (actorID < m_actors.size())
|
||||
{
|
||||
HydraActor *actor = m_actors[actorID];
|
||||
if (actor != nullptr)
|
||||
{
|
||||
for (int i = 0; i < actor->m_component_types.size(); i++)
|
||||
{
|
||||
if (actor->m_component_types[i] == component_type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void HydraActorManager::RemoveComponentType(HydraID actorID, uint32_t component_type)
|
||||
{
|
||||
if (actorID < m_actors.size())
|
||||
{
|
||||
HydraActor *actor = m_actors[actorID];
|
||||
if (actor != nullptr)
|
||||
{
|
||||
uint32_t comp_type = static_cast<uint32_t>(component_type);
|
||||
if (actor->m_component_types.size() > comp_type)
|
||||
{
|
||||
actor->m_component_types.erase(actor->m_component_types.begin() + comp_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HydraID HydraActorManager::GetParent(HydraID actor_id)
|
||||
{
|
||||
return m_actors[actor_id]->m_parent_id;
|
||||
}
|
||||
|
||||
HydraID HydraActorManager::GetRoot(HydraID actor_id)
|
||||
{
|
||||
HydraID parent_id = GetParent(actor_id);
|
||||
if(parent_id == INVALID_HYDRA_ID)
|
||||
{
|
||||
return actor_id;
|
||||
}
|
||||
return GetRoot(parent_id);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#ifndef HYDRAACTORMANAGER
|
||||
#define HYDRAACTORMANAGER
|
||||
#include "../engine/HydraObject.h"
|
||||
|
||||
#include "../task/HydraTask.h"
|
||||
#include "HydraActor.h"
|
||||
#include <GLMIncludes.h>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
|
||||
|
||||
// #include <assimp/Importer.hpp> // C++ importer interface
|
||||
// #include <assimp/scene.h> // Output data structure
|
||||
// #include <assimp/postprocess.h> // Post processing flags
|
||||
|
||||
|
||||
class CLASS_DEFINE HydraActorManager : public HydraObject
|
||||
{
|
||||
private:
|
||||
std::mutex m_mutex;
|
||||
std::vector<HydraActor*> m_actors;
|
||||
std::deque<HydraID> m_available_actor_ids;
|
||||
std::deque<HydraID> m_actors_waiting_for_init;
|
||||
std::deque<HydraID> m_actors_waiting_for_delete;
|
||||
size_t m_max_actors;
|
||||
HydraID _SaveActor(HydraActor* actor);
|
||||
void _RemoveActorFromWaiting(HydraID actorID);
|
||||
void _RemoveActorFromTickFixed(HydraID actorID);
|
||||
void _SetActorDeleted(HydraID actorID);
|
||||
public:
|
||||
void Initialise(size_t max_actors);
|
||||
template<class T> HydraID CreateActor();
|
||||
HydraID LoadActor(std::string filename);
|
||||
|
||||
void DeleteActor(HydraID actorID);
|
||||
HydraActor* const GetActor(HydraID actorID);
|
||||
std::vector<HydraID>& GetChildren(HydraID actor_id);
|
||||
|
||||
void TickActors(float delta_t);
|
||||
void InitialiseActor(HydraID actorID);
|
||||
|
||||
void Shutdown();
|
||||
|
||||
void RotateActor(HydraID actorID, float euler_x, float euler_y, float euler_z);
|
||||
|
||||
void SetPosition(HydraID actorID, glm::dvec3 position);
|
||||
void SetOrientation(HydraID actorID, float x, float y, float z);
|
||||
void SetScale(HydraID actor_id, glm::dvec3 scaling);
|
||||
|
||||
void TranslateActor(HydraID actorID, glm::dvec3 translation);
|
||||
|
||||
void SetRelationship(HydraID parent_id, HydraID child_id);
|
||||
void AddComponentType(HydraID actorID, uint32_t component_type);
|
||||
bool HasComponentType(HydraID actorID, uint32_t component_type);
|
||||
void RemoveComponentType(HydraID actorID, uint32_t component_type);
|
||||
|
||||
HydraID GetParent(HydraID actor_id);
|
||||
HydraID GetRoot(HydraID actor_id);
|
||||
|
||||
glm::mat4 GetActorPose(HydraID actorID);
|
||||
glm::dvec3 GetActorPosition(HydraID actorID);
|
||||
glm::vec3 GetActorOrientation(HydraID actorID);
|
||||
glm::vec3 GetActorVelocity(HydraID actorID);
|
||||
|
||||
};
|
||||
|
||||
template<class T>
|
||||
inline HydraID HydraActorManager::CreateActor()
|
||||
{
|
||||
T* actorType = new T();
|
||||
HydraActor* actor = dynamic_cast<HydraActor*>(actorType);
|
||||
if (actor != nullptr)
|
||||
{
|
||||
HydraID actor_id = INVALID_HYDRA_ID;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
actor_id = _SaveActor(actor);
|
||||
}
|
||||
if(actor_id != INVALID_HYDRA_ID)
|
||||
{
|
||||
|
||||
actor->InitialiseComponents();
|
||||
}
|
||||
return actor_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return INVALID_HYDRA_ID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* HYDRAACTORMANAGER */
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "HydraDirectionalLightActor.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/HydraLightComponent.h"
|
||||
|
||||
#include "../buffer/HydraLightBufferManager.h"
|
||||
#include "../buffer/HydraLightBuffer.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void HydraDirectionalLightActor::InitialiseComponents()
|
||||
{
|
||||
HydraLightComponent light_comp = {};
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
// HydraLightBuffer light = {};
|
||||
// light.light_colour = glm::vec3(1,1,1);
|
||||
// light.light_direction = glm::vec3(0,0,0);
|
||||
// light.light_intensity = 1;
|
||||
// light.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_DIRECTIONAL);
|
||||
|
||||
//light_comp.light_id = GetEngine()->LightBufferManager()->CreateLight(light);
|
||||
|
||||
light_comp.light_colour = glm::vec4(1,1,1,1);
|
||||
light_comp.light_intensity = 100.0f;
|
||||
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_DIRECTIONAL);
|
||||
light_comp.entity_id = GetID();
|
||||
|
||||
ecs->AddComponent<HydraLightComponent>(GetID(), light_comp);
|
||||
|
||||
HydraPositionComponent position_component;
|
||||
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
|
||||
}
|
||||
|
||||
void HydraDirectionalLightActor::Destroy()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef HYDRALIGHTACTOR
|
||||
#define HYDRALIGHTACTOR
|
||||
#include "HydraActor.h"
|
||||
|
||||
class CLASS_DEFINE HydraDirectionalLightActor : public HydraActor
|
||||
{
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
virtual void InitialiseComponents() override;
|
||||
virtual void Destroy() override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRALIGHTACTOR */
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef HYDRAGLTFACTOR
|
||||
#define HYDRAGLTFACTOR
|
||||
|
||||
#include "HydraActor.h"
|
||||
|
||||
class CLASS_DEFINE HydraGLTFActor : public HydraActor
|
||||
{
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
virtual void InitialiseComponents() override {}
|
||||
virtual void Destroy() override {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRAGLTFACTOR */
|
||||
@@ -0,0 +1,135 @@
|
||||
#include "HydraOutputActor.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 "../buffer/HydraMaterialBufferManager.h"
|
||||
#include "../buffer/HydraTextureBufferManager.h"
|
||||
#include "../buffer/HydraMaterialBuffer.h"
|
||||
#include "../mesh/HydraMeshManager.h"
|
||||
#include "../mesh/HydraMesh.h"
|
||||
|
||||
void HydraOutputActor::_CreateMaterial()
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraRenderSettings render_settings = engine->RenderSettings();
|
||||
|
||||
HydraID buffer_0 = engine->TextureBufferManager()->CreateTexture("deferred_buffer_0",
|
||||
render_settings.DisplayWidth,
|
||||
render_settings.DisplayHeight,
|
||||
GL_RGBA8,
|
||||
GL_NEAREST,
|
||||
GL_NEAREST);
|
||||
HydraID depth = engine->TextureBufferManager()->CreateTexture("deferred_depth",
|
||||
render_settings.DisplayWidth,
|
||||
render_settings.DisplayHeight,
|
||||
GL_DEPTH_COMPONENT24,
|
||||
GL_NEAREST,
|
||||
GL_NEAREST);
|
||||
|
||||
HydraID metal_rough = engine->TextureBufferManager()->CreateTexture("deferred_metal_rough_buffer",
|
||||
render_settings.DisplayWidth,
|
||||
render_settings.DisplayHeight,
|
||||
GL_RGBA8,
|
||||
GL_NEAREST,
|
||||
GL_NEAREST);
|
||||
|
||||
HydraID normal = engine->TextureBufferManager()->CreateTexture("deferred_normal_buffer",
|
||||
render_settings.DisplayWidth,
|
||||
render_settings.DisplayHeight,
|
||||
GL_RGBA32F,
|
||||
GL_NEAREST,
|
||||
GL_NEAREST);
|
||||
|
||||
HydraID position = engine->TextureBufferManager()->CreateTexture("deferred_position_buffer",
|
||||
render_settings.DisplayWidth,
|
||||
render_settings.DisplayHeight,
|
||||
GL_RGBA32F,
|
||||
GL_NEAREST,
|
||||
GL_NEAREST);
|
||||
|
||||
// engine->TextureBufferManager()->BindTexture(depth);
|
||||
// engine->TextureBufferManager()->BindTexture(buffer_0);
|
||||
texture_buffers.resize(16);
|
||||
texture_buffers[0] = depth;
|
||||
texture_buffers[1] = buffer_0;
|
||||
texture_buffers[2] = metal_rough;
|
||||
texture_buffers[3] = normal;
|
||||
texture_buffers[4] = position;
|
||||
}
|
||||
|
||||
void HydraOutputActor::_CreateMesh()
|
||||
{
|
||||
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
||||
HydraID mesh_id = mesh_manager->CreateMesh();
|
||||
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
||||
|
||||
mesh->vertexes.resize(4);
|
||||
mesh->indexes.resize(6);
|
||||
|
||||
float scale_x = 1.0f;
|
||||
float scale_y = 1.0f;
|
||||
float scale_z = 1.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 = 0;
|
||||
float min_v = 0;
|
||||
|
||||
float max_u = 1;
|
||||
float max_v = 1;
|
||||
|
||||
// 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, 0, 0, 0,0,0,0,0,0,0,0,0};
|
||||
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, 0, 0, 0,0,0,0,0,0,0,0,0};
|
||||
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, 0, 0, 0,0,0,0,0,0,0,0,0};
|
||||
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, 0, 0, 0,0,0,0,0,0,0,0,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;
|
||||
|
||||
|
||||
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 HydraOutputActor::_CreateRenderableComponent()
|
||||
{
|
||||
HydraRenderableComponent render_comp;
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_OUTPUT, true);
|
||||
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
|
||||
}
|
||||
|
||||
|
||||
void HydraOutputActor::InitialiseComponents()
|
||||
{
|
||||
_CreateMaterial();
|
||||
_CreateMesh();
|
||||
_CreateRenderableComponent();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef HYDRAOUTPUTACTOR
|
||||
#define HYDRAOUTPUTACTOR
|
||||
#include "HydraActor.h"
|
||||
|
||||
class CLASS_DEFINE HydraOutputActor : public HydraActor
|
||||
{
|
||||
private:
|
||||
HydraID m_mesh_component = INVALID_HYDRA_ID;
|
||||
protected:
|
||||
void _CreateMaterial();
|
||||
void _CreateMesh();
|
||||
void _CreateRenderableComponent();
|
||||
public:
|
||||
virtual void InitialiseComponents();
|
||||
virtual void Destroy(){}
|
||||
std::vector<HydraID> texture_buffers;
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRAOUTPUTACTOR */
|
||||
@@ -0,0 +1,208 @@
|
||||
#include "HydraPlaneActor.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 "../buffer/HydraMaterialBufferManager.h"
|
||||
#include "../buffer/HydraTextureBufferManager.h"
|
||||
#include "../buffer/HydraMaterialBuffer.h"
|
||||
#include "../mesh/HydraMeshManager.h"
|
||||
#include "../mesh/HydraMesh.h"
|
||||
|
||||
void HydraPlaneActor::InitialiseComponents()
|
||||
{
|
||||
// HydraECS* ecs = GetEngine()->ECS();
|
||||
// HydraID entity_id = ecs->CreateEntity();
|
||||
_CreatePosition();
|
||||
// _CreatePhysics();
|
||||
|
||||
_CreateMaterial();
|
||||
_CreateMesh();
|
||||
_CreateRenderableComponent();
|
||||
}
|
||||
|
||||
void HydraPlaneActor::DeferredInitialiseComponents()
|
||||
{
|
||||
}
|
||||
|
||||
void HydraPlaneActor::_CreatePosition()
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraPositionComponent position_component;
|
||||
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
|
||||
}
|
||||
|
||||
void HydraPlaneActor::_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 = 1000.0f;
|
||||
float scale_y = 1.0f;
|
||||
float scale_z = 1000.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 = 1000;
|
||||
float min_v = 0;
|
||||
|
||||
float max_u = 0;
|
||||
float max_v = 1000;
|
||||
|
||||
// 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 HydraPlaneActor::_CreateMaterial()
|
||||
{
|
||||
|
||||
HydraEngine *engine = GetEngine();
|
||||
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo.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.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 HydraPlaneActor::_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 HydraPlaneActor::_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);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef HYDRAPLANEACTOR
|
||||
#define HYDRAPLANEACTOR
|
||||
#include "HydraActor.h"
|
||||
|
||||
class CLASS_DEFINE HydraPlaneActor : public HydraActor
|
||||
{
|
||||
private:
|
||||
double m_scale = 1.0;
|
||||
double m_widthscale = 1000.0f;
|
||||
HydraID m_material_component = INVALID_HYDRA_ID;
|
||||
HydraID m_position_component = INVALID_HYDRA_ID;
|
||||
HydraID m_mesh_component = INVALID_HYDRA_ID;
|
||||
protected:
|
||||
void _CreatePosition();
|
||||
void _CreateMesh();
|
||||
void _CreateMaterial();
|
||||
void _CreatePhysics();
|
||||
void _CreateRenderableComponent();
|
||||
public:
|
||||
virtual void InitialiseComponents();
|
||||
virtual void DeferredInitialiseComponents();
|
||||
virtual void Destroy(){}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRAPLANEACTOR */
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "HydraPlayerActor.h"
|
||||
#include "HydraActorManager.h"
|
||||
#include "../HydraDefines.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
|
||||
#include "../ecs/HydraECS.h"
|
||||
#include "../ecs/components/HydraPositionComponent.h"
|
||||
|
||||
|
||||
|
||||
void HydraPlayerActor::InitialiseComponents()
|
||||
{
|
||||
HydraECS* ecs = GetEngine()->ECS();
|
||||
//HydraID entity_id = ecs->CreateEntity();
|
||||
HydraPositionComponent position_component;
|
||||
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
|
||||
}
|
||||
|
||||
void HydraPlayerActor::DeferredInitialiseComponents()
|
||||
{
|
||||
//_CreatePhysics();
|
||||
}
|
||||
void HydraPlayerActor::_CreatePhysics()
|
||||
{
|
||||
// HydraPhysicsComponent* physics_component = static_cast<HydraPhysicsComponent*>(GetEngine()->ComponentManager()->CreateComponent((uint32_t)HYDRA_COMPONENT_TYPE::PHYSICS, GetID()));
|
||||
|
||||
// physics_component->physics_definition.PhysicsType = HydraPhyicsType::Dynamic;
|
||||
// physics_component->physics_definition.PhysicsShape = HydraPhysicsShape::HydraBoxShape;
|
||||
// physics_component->physics_definition.Mass = 10.0f;
|
||||
// physics_component->physics_definition.ExtentX = 0.5f;
|
||||
// physics_component->physics_definition.ExtentY = 0.5f;
|
||||
// physics_component->physics_definition.ExtentZ = 0.5f;
|
||||
// physics_component->physics_definition.DynamicFriction = 0.5f;
|
||||
// physics_component->physics_definition.Restitution = 0.5f;
|
||||
// physics_component->physics_definition.Velocity = GetEngine()->ActorManager()->GetActorVelocity(GetID());
|
||||
|
||||
}
|
||||
void HydraPlayerActor::HandleInput(float delta_t)
|
||||
{
|
||||
glm::vec2 change = GetEngine()->MouseChange();
|
||||
|
||||
bool move_forward = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_W);
|
||||
bool move_backward = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_S);
|
||||
bool move_fast = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_LEFT_SHIFT);
|
||||
|
||||
bool move_left = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_A);
|
||||
bool move_right = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_D);
|
||||
|
||||
HydraRenderSettings render_settings = GetEngine()->RenderSettings();
|
||||
float scale = 0.2f;
|
||||
|
||||
float x_angle = (change.x / render_settings.DisplayWidth) * -500 * delta_t * scale;
|
||||
float y_angle = (change.y / render_settings.DisplayHeight) * -500 * delta_t * scale;
|
||||
|
||||
float extra_speed = 1.0f;
|
||||
float speed = 5.0f;
|
||||
|
||||
if (move_fast)
|
||||
{
|
||||
extra_speed = 150;
|
||||
}
|
||||
|
||||
GetEngine()->ActorManager()->RotateActor(GetID(), y_angle, x_angle, 0.0f);
|
||||
|
||||
glm::dvec3 pos_vec = GetEngine()->ActorManager()->GetActorPosition(GetID());
|
||||
glm::vec3 rot_vec = GetEngine()->ActorManager()->GetActorOrientation(GetID());
|
||||
|
||||
glm::mat4 rot = glm::mat4(1);
|
||||
|
||||
rot = glm::eulerAngleXYZ(rot_vec.x, rot_vec.y, rot_vec.z);
|
||||
|
||||
glm::dvec3 forward = m_forward * rot;
|
||||
glm::dvec3 right = m_right * rot;
|
||||
glm::dvec3 up = m_up * rot;
|
||||
|
||||
glm::dvec3 trans = glm::dvec3(0, 0, 0);
|
||||
|
||||
double distance = (double)(speed * extra_speed * delta_t);
|
||||
bool moved = false;
|
||||
if (move_forward)
|
||||
{
|
||||
trans = trans - (forward * distance);
|
||||
moved = true;
|
||||
}
|
||||
if (move_backward)
|
||||
{
|
||||
trans = trans + (forward * distance);
|
||||
moved = true;
|
||||
}
|
||||
|
||||
if (move_right)
|
||||
{
|
||||
trans = trans - (right * distance);
|
||||
moved = true;
|
||||
}
|
||||
|
||||
if (move_left)
|
||||
{
|
||||
trans = trans + (right * distance);
|
||||
moved = true;
|
||||
}
|
||||
if (moved)
|
||||
{
|
||||
GetEngine()->ActorManager()->TranslateActor(GetID(), -trans);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef HYDRAPLAYERACTOR
|
||||
#define HYDRAPLAYERACTOR
|
||||
#include "HydraActor.h"
|
||||
#include <GLMIncludes.h>
|
||||
class HydraCamara;
|
||||
|
||||
class CLASS_DEFINE HydraPlayerActor : public HydraActor
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
glm::vec4 m_right = glm::vec4(1, 0, 0, 1);
|
||||
glm::vec4 m_up = glm::vec4(0, -1, 0, 1);
|
||||
glm::vec4 m_forward = glm::vec4(0, 0, -1 , 1);
|
||||
void _CreatePhysics();
|
||||
public:
|
||||
virtual void InitialiseComponents();
|
||||
virtual void DeferredInitialiseComponents();
|
||||
virtual void HandleInput(float delta_t);
|
||||
virtual void Destroy() {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRAPLAYERACTOR */
|
||||
Reference in New Issue
Block a user