Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add skeletal animation to cmake and fix errors #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ else()
set(LIBS )
endif(WIN32)

set(CMAKE_CXX_STANDARD 14)

set(CHAPTERS
1.getting_started
2.lighting
Expand All @@ -62,6 +64,7 @@ set(CHAPTERS
5.advanced_lighting
6.pbr
7.in_practice
8.guest
)

set(1.getting_started
Expand Down Expand Up @@ -166,6 +169,10 @@ set(7.in_practice
#3.2d_game
)

set(8.guest
skeletal_animation
)



configure_file(configuration/root_directory.h.in configuration/root_directory.h)
Expand Down
10 changes: 5 additions & 5 deletions includes/learnopengl/animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Animator
{
public:
Animator::Animator(Animation* current)
Animator(Animation* current)
{
m_CurrentAnimation = current;
m_CurrentTime = 0.0;
Expand All @@ -20,7 +20,7 @@ class Animator
m_Transforms.push_back(glm::mat4(1.0f));
}

void Animator::UpdateAnimation(float dt)
void UpdateAnimation(float dt)
{
m_DeltaTime = dt;
if (m_CurrentAnimation)
Expand All @@ -31,13 +31,13 @@ class Animator
}
}

void Animator::PlayAnimation(Animation* pAnimation)
void PlayAnimation(Animation* pAnimation)
{
m_CurrentAnimation = pAnimation;
m_CurrentTime = 0.0f;
}

void Animator::CalculateBoneTransform(const AssimpNodeData* node, glm::mat4 parentTransform)
void CalculateBoneTransform(const AssimpNodeData* node, glm::mat4 parentTransform)
{
std::string nodeName = node->name;
glm::mat4 nodeTransform = node->transformation;
Expand Down Expand Up @@ -75,4 +75,4 @@ class Animator
float m_CurrentTime;
float m_DeltaTime;

};
};
4 changes: 2 additions & 2 deletions includes/learnopengl/assimp_glm_helpers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include<assimp/Quaternion.h>
#include<assimp/quaternion.h>
#include<assimp/vector3.h>
#include<assimp/matrix4x4.h>
#include<glm/glm.hpp>
Expand Down Expand Up @@ -31,4 +31,4 @@ class AssimpGLMHelpers
{
return glm::quat(pOrientation.w, pOrientation.x, pOrientation.y, pOrientation.z);
}
};
};
2 changes: 1 addition & 1 deletion includes/learnopengl/bone.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Bone

}

glm::mat4 Bone::InterpolateScaling(float animationTime)
glm::mat4 InterpolateScaling(float animationTime)
{
if (1 == m_NumScalings)
return glm::scale(glm::mat4(1.0f), m_Scales[0].scale);
Expand Down
8 changes: 8 additions & 0 deletions includes/learnopengl/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <vector>
using namespace std;

#define MAX_BONE_INFLUENCE 4

struct Vertex {
// position
glm::vec3 Position;
Expand All @@ -23,6 +25,12 @@ struct Vertex {
glm::vec3 Tangent;
// bitangent
glm::vec3 Bitangent;

//bone indexes which will influence this vertex
int m_BoneIDs[MAX_BONE_INFLUENCE];

//weights from each bone
float m_Weights[MAX_BONE_INFLUENCE];
};

struct Texture {
Expand Down
4 changes: 2 additions & 2 deletions includes/learnopengl/model_animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Model

void SetVertexBoneDataToDefault(Vertex& vertex)
{
for (int i = 0; i < MAX_BONE_WEIGHTS; i++)
for (int i = 0; i < AI_MAX_BONE_WEIGHTS; i++)
{
vertex.m_BoneIDs[i] = -1;
vertex.m_Weights[i] = 0.0f;
Expand Down Expand Up @@ -154,7 +154,7 @@ class Model

void SetVertexBoneData(Vertex& vertex, int boneID, float weight)
{
for (int i = 0; i < MAX_BONE_WEIGHTS; ++i)
for (int i = 0; i < AI_MAX_BONE_WEIGHTS; ++i)
{
if (vertex.m_BoneIDs[i] < 0)
{
Expand Down