AnimationSystem working

This commit is contained in:
viktorljung
2016-01-24 18:31:23 +01:00
parent dd80323342
commit 8cf9caf7aa
7 changed files with 103 additions and 17 deletions
@@ -8,6 +8,7 @@
#include "Core/ResourceManager.h" #include "Core/ResourceManager.h"
#include "Rendering/Model.h" #include "Rendering/Model.h"
#include "Rendering/EAnimationComplete.h" #include "Rendering/EAnimationComplete.h"
#include "Rendering/Skeleton.h"
class AnimationSystem : public PureSystem class AnimationSystem : public PureSystem
{ {
+14
View File
@@ -13,6 +13,7 @@
#include "Camera.h" #include "Camera.h"
#include "../Core/World.h" #include "../Core/World.h"
#include "../Core/Transform.h" #include "../Core/Transform.h"
#include "Skeleton.h"
struct ModelJob : RenderJob struct ModelJob : RenderJob
{ {
@@ -37,6 +38,14 @@ struct ModelJob : RenderJob
glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1)); glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
Depth = worldpos.z; Depth = worldpos.z;
World = world; World = world;
Skeleton = Model->m_RawModel->m_Skeleton;
if (world->HasComponent(Entity, "Animation")) {
auto animationComponent = world->GetComponent(Entity, "Animation");
Animation = model->m_RawModel->m_Skeleton->GetAnimation(animationComponent["Name"]);
AnimationTime = (double)animationComponent["Time"];
}
}; };
unsigned int TextureID; unsigned int TextureID;
@@ -51,6 +60,11 @@ struct ModelJob : RenderJob
float Shininess = 0.f; float Shininess = 0.f;
glm::vec4 Color; glm::vec4 Color;
const ::Model* Model = nullptr; const ::Model* Model = nullptr;
::Skeleton* Skeleton = nullptr;
const ::Skeleton::Animation* Animation = nullptr;
float AnimationTime = 0.f;
glm::vec4 DiffuseColor; glm::vec4 DiffuseColor;
glm::vec4 SpecularColor; glm::vec4 SpecularColor;
glm::vec4 IncandescenceColor; glm::vec4 IncandescenceColor;
+66
View File
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="GotToGoFast" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform>
<Position X="0" Y="-0.00432979874" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="1" G="39.2156868" R="392.15686"/>
</c:Model>
<c:RaptorCopter>
<Axis X="1.50000012" Y="-2.20000005" Z="2.10000014"/>
</c:RaptorCopter>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Animation>
<Name>running</Name>
<Time>0.9981707605223491</Time>
<Speed>1</Speed>
</c:Animation>
<c:Model>
<Resource>Models/Animtest.mesh</Resource>
<Color A="1" B="392156.875" G="1" R="1"/>
</c:Model>
<c:Transform>
<Position X="0" Y="0.5" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity>
<Components>
<c:DirectionalLight/>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Text>
<Content>Got to Go FAST!!!!</Content>
<Resource>Fonts/DroidSans.ttf,60</Resource>
<Color A="0" B="0.972549021" G="3.92156863" R="39.2156868"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0.616941631" Z="0"/>
<Scale X="0.5" Y="0.5" Z="1"/>
<Orientation X="0" Y="4.47399998" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+7 -5
View File
@@ -64,6 +64,7 @@
<c:Text> <c:Text>
<Content>Welcome!</Content> <Content>Welcome!</Content>
<Resource>Fonts/DroidSans.ttf,1280</Resource> <Resource>Fonts/DroidSans.ttf,1280</Resource>
<Color A="0" B="1" G="7.84313726" R="1"/>
</c:Text> </c:Text>
<c:Transform> <c:Transform>
<Position X="0" Y="0" Z="0.700000048"/> <Position X="0" Y="0" Z="0.700000048"/>
@@ -79,7 +80,7 @@
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Position X="0" Y="2.37320328" Z="0"/> <Position X="0" Y="2.37320328" Z="0"/>
<Orientation X="0" Y="8903.9668" Z="0"/> <Orientation X="0" Y="9447.45117" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -261,7 +262,7 @@
<Components> <Components>
<c:Animation/> <c:Animation/>
<c:Model> <c:Model>
<Resource>Models/Arm.dae</Resource> <Resource>asd</Resource>
<Color A="1" B="1" G="3.92156863" R="1"/> <Color A="1" B="1" G="3.92156863" R="1"/>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
@@ -273,14 +274,15 @@
</Entity> </Entity>
<Entity> <Entity>
<Components> <Components>
<c:Animation/> <c:Animation>
<Name></Name>
</c:Animation>
<c:Model> <c:Model>
<Resource>Models/Sid_Flying.dae</Resource> <Resource>Models/Animtest.mesh</Resource>
<Color A="1" B="11.7647057" G="1" R="11.7647057"/> <Color A="1" B="11.7647057" G="1" R="11.7647057"/>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="-1.42184281" Y="1.71298718" Z="-6.31712198"/> <Position X="-1.42184281" Y="1.71298718" Z="-6.31712198"/>
<Orientation X="4.66500044" Y="3.14159203" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
+10 -6
View File
@@ -7,25 +7,29 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a
} }
Model* model = ResourceManager::Load<Model>(entity["Model"]["Resource"]); Model* model = ResourceManager::Load<Model>(entity["Model"]["Resource"]);
//Skeleton* skeleton = model->m_Skeleton; Skeleton* skeleton = model->m_RawModel->m_Skeleton;
//auto animation == skeleton->GetAnimation(animation["Name"]); const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["Name"]);
double animationSpeed = (double)animationComponent["Speed"]; double animationSpeed = (double)animationComponent["Speed"];
if( animationSpeed != 0.0) { if( animationSpeed != 0.0) {
double nextTime = (double)animationComponent["Time"] + animationSpeed * dt; double nextTime = (double)animationComponent["Time"] + animationSpeed * dt;
if (!animationComponent["Loop"] && glm::abs(nextTime) > animation->Duration) {
if (!(bool)animationComponent["Loop"] && glm::abs(nextTime) > animation->Duration) {
(double&)animationComponent["Time"] = glm::sign(nextTime) * animation->Duration; (double&)animationComponent["Time"] = glm::sign(nextTime) * animation->Duration;
(double&)animationComponent["Speed"] = 0.0; (double&)animationComponent["Speed"] = 0.0;
Events::AnimationComplete e; Events::AnimationComplete e;
e.Entity = entity; e.Entity = entity;
// e.Name = animationComponent->Name; e.Name = (std::string)animationComponent["Name"];
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} else { } else {
(double&)animationComponent["Time"] = nextTime; if (glm::abs(nextTime) > animation->Duration) {
(double&)animationComponent["Time"] = glm::abs(nextTime) - animation->Duration;
} else {
(double&)animationComponent["Time"] = nextTime;
}
} }
} }
} }
+3 -6
View File
@@ -96,12 +96,9 @@ void DrawFinalPass::Draw(RenderScene& scene)
//TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :) //TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :)
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running");
if (animation != nullptr) { if (modelJob->Animation != nullptr) {
std::vector<glm::mat4> frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones( std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones( *modelJob->Animation, modelJob->AnimationTime);
*animation,
0.0f
);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} }
} }
+2
View File
@@ -10,6 +10,7 @@
#include "Core/EntityFileWriter.h" #include "Core/EntityFileWriter.h"
#include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/CapturePointSystem.h"
#include "Game/Systems/WeaponSystem.h" #include "Game/Systems/WeaponSystem.h"
#include "../Engine/Rendering/AnimationSystem.h"
Game::Game(int argc, char* argv[]) Game::Game(int argc, char* argv[])
{ {
@@ -86,6 +87,7 @@ Game::Game(int argc, char* argv[])
// Populate Octree with collidables // Populate Octree with collidables
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision);
m_SystemPipeline->AddSystem<AnimationSystem>(updateOrderLevel);
// Collision and TriggerSystem should update after player. // Collision and TriggerSystem should update after player.
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);