Commit cb84c27f authored by Mehdi BENHARRATS's avatar Mehdi BENHARRATS

WIP

parent 7c05b0d0
#include "simple_debug_tools.hpp"
#include <iostream>
using namespace vcl;
void printHierarchy(hierarchy_mesh_drawable const& h)
{
for(auto const& elem : h.name_map)
std::cout << elem.first << ' ';
std::cout << std::endl;
}
#ifndef SIMPLE_DEBUG_TOOLS_HPP_INCLUDED
#define SIMPLE_DEBUG_TOOLS_HPP_INCLUDED
#include "vcl/vcl.hpp"
void printHierarchy(vcl::hierarchy_mesh_drawable const& h);
#endif // !SIMPLE_DEBUG_TOOLS_HPP_INCLUDED
\ No newline at end of file
......@@ -272,7 +272,6 @@ void scene_model::setupPlayerEntity()
acceleration,
maxSpeed,
jumpImpulsion,
createPlayerMeshHierarchy()
};
setupPlayerAnimation();
......
......@@ -26,8 +26,6 @@ struct CharacterDescription
float acceleration;
float maxSpeed;
float jumpImpulsion;
CompletedMeshHierarchy meshHierarchy;
};
struct CommonSceneResources
......
#include "entity_builder.hpp"
#include "../debugging/simple_debug_tools.hpp"
using namespace vcl;
EntityBuilder::EntityBuilder(MyEcs& ecs, CommonSceneResources& resources)
......@@ -55,7 +57,7 @@ ecs::Entity EntityBuilder::buildGrassBillboard(vcl::vec3 const& position, std::m
return billboard;
}
ecs::Entity EntityBuilder::buildCharacter(CharacterDescription& characterInfo, vcl::vec3 const& position, std::map<std::string,GLuint>& shaders)
ecs::Entity EntityBuilder::buildCharacter(CharacterDescription& characterInfo, CompletedMeshHierarchy& meshHierarchy, vcl::vec3 const& position, std::map<std::string,GLuint>& shaders)
{
auto character = m_ecs.createEntity();
m_ecs.add<TransformComponent>(character, position);
......@@ -63,9 +65,9 @@ ecs::Entity EntityBuilder::buildCharacter(CharacterDescription& characterInfo, v
m_ecs.add<PhysicsComponent>(character, characterInfo.mass);
m_ecs.add<ForceComponent>(character);
auto& hierarchyBoxComponent = m_ecs.add<HierarchyCollisionBoxComponent>(character);
hierarchyBoxComponent.boundaries = characterInfo.meshHierarchy.boundaries;
m_ecs.add<ArticulatedHierarchyComponent>(character, characterInfo.meshHierarchy.rootName, characterInfo.meshHierarchy.hierarchy, shaders["mesh"]);
auto& playerMeshHierarchy = characterInfo.meshHierarchy.hierarchy;
hierarchyBoxComponent.boundaries = meshHierarchy.boundaries;
m_ecs.add<ArticulatedHierarchyComponent>(character, meshHierarchy.rootName, meshHierarchy.hierarchy, shaders["mesh"]);
auto& playerMeshHierarchy = meshHierarchy.hierarchy;
playerMeshHierarchy.update_local_to_global_coordinates();
auto const& legNode = playerMeshHierarchy["right_leg"];
m_ecs.add<CollisionComponent>(character, CollisionShape { std::vector<CollisionCylinder>{ m_resources.collisionBoxes["player"] }, { 0, 0, 2 * legNode.global_transform.translation.z } }, CollisionMaterial::Character);
......@@ -84,27 +86,22 @@ ecs::Entity EntityBuilder::buildCharacter(CharacterDescription& characterInfo, v
ecs::Entity EntityBuilder::buildPlayer(vcl::vec3 const& position, std::map<std::string,GLuint>& shaders)
{
return buildCharacter(m_resources.standardCharacter, position, shaders);
auto& hierarchy = m_resources.AIHierarchyPool.getFreeElement().first;
return buildCharacter(m_resources.standardCharacter, hierarchy, position, shaders);
}
ecs::Entity EntityBuilder::buildAICharacter(ecs::Entity const target, vcl::vec3 const& position, std::map<std::string,GLuint>& shaders)
{
CharacterDescription AIDescription;
AIDescription.acceleration = m_resources.standardCharacter.acceleration;
AIDescription.maxSpeed = m_resources.standardCharacter.maxSpeed;
AIDescription.jumpImpulsion = m_resources.standardCharacter.jumpImpulsion;
AIDescription.mass = m_resources.standardCharacter.mass;
auto& hierarchy = m_resources.AIHierarchyPool.getFreeElement().first;
AIDescription.meshHierarchy = hierarchy;
ecs::Entity m_ai = buildCharacter(AIDescription, position, shaders);
m_ecs.add<AIPlayerComponent>(m_ai, target);
return m_ai;
ecs::Entity ai = buildCharacter(m_resources.standardCharacter, hierarchy, position, shaders);
m_ecs.add<AIPlayerComponent>(ai, target);
return ai;
}
static void createPlayerMeshHierarchyWrapper(CompletedMeshHierarchy& hierarchy) { hierarchy = createPlayerMeshHierarchy(); }
void EntityBuilder::buildAIHierarchyPool()
{
m_resources.AIHierarchyPool.map(createPlayerMeshHierarchyWrapper);
//m_resources.AIHierarchyPool.map([](CompletedMeshHierarchy const& h) { printHierarchy(h.hierarchy); });
}
......@@ -15,7 +15,7 @@ public:
ecs::Entity buildMushroom(vcl::vec3 const& position, std::map<std::string,GLuint>& shaders);
ecs::Entity buildGrassBillboard(vcl::vec3 const& position, std::map<std::string,GLuint>& shaders);
ecs::Entity buildCharacter(CharacterDescription& characterInfo, vcl::vec3 const& position, std::map<std::string,GLuint>& shaders);
ecs::Entity buildCharacter(CharacterDescription& characterInfo, CompletedMeshHierarchy& meshHierarchy, vcl::vec3 const& position, std::map<std::string,GLuint>& shaders);
ecs::Entity buildPlayer(vcl::vec3 const& position, std::map<std::string,GLuint>& shaders);
ecs::Entity buildAICharacter(ecs::Entity const target, vcl::vec3 const& position, std::map<std::string,GLuint>& shaders);
void buildAIHierarchyPool();
......
......@@ -6,6 +6,9 @@ void AnimationApplier::update(ArticulatedHierarchyComponent& hierarchyComponent,
{
for(auto const& angle : animationComponent.angles)
{
std::cout << "Bla" << std::endl;
std::cout << angle.first << std::endl;
std::cout << "Blou" << std::endl;
hierarchyComponent.hierarchy.get()[angle.first].transform.rotation = vcl::rotation_from_axis_angle_mat3({1,0,0}, angle.second);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment