Skip to content

Commit

Permalink
feat: #45 update skeleton animation
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Jan 11, 2020
1 parent 9b81053 commit 2b7ae8e
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 190 deletions.
4 changes: 2 additions & 2 deletions Projects/Skylicht/Engine/Source/Animation/CAnimationClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ namespace Skylicht
return (int)AnimInfo.size();
}

SEntityAnim* getAnimOfSceneNode(int i)
SEntityAnim* getAnimOfEntity(int i)
{
return AnimInfo[i];
}

SEntityAnim* getAnimOfSceneNode(const std::string &sceneNodeName)
SEntityAnim* getAnimOfEntity(const std::string &sceneNodeName)
{
return AnimNameToInfo[sceneNodeName];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ This file is part of the "Skylicht Engine".

namespace Skylicht
{
CAnimationController::CAnimationController()
CAnimationController::CAnimationController() :
m_output(NULL)
{

}
Expand All @@ -54,6 +55,9 @@ namespace Skylicht
skeleton->update();
}
}

if (m_output != NULL)
m_output->applyTransform();
}

CSkeleton* CAnimationController::createSkeleton()
Expand All @@ -67,6 +71,10 @@ namespace Skylicht
skeleton->initSkeleton(renderMesh->getEntities());

m_skeletons.push_back(skeleton);

if (m_output == NULL)
m_output = skeleton;

return skeleton;
}

Expand All @@ -77,5 +85,6 @@ namespace Skylicht
delete skeleton;
}
m_skeletons.clear();
m_output = NULL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace Skylicht
protected:
std::vector<CSkeleton*> m_skeletons;

CSkeleton *m_output;

public:
CAnimationController();

Expand All @@ -48,5 +50,10 @@ namespace Skylicht
CSkeleton* createSkeleton();

void releaseAllSkeleton();

inline void setOutput(CSkeleton *skeleton)
{
m_output = skeleton;
}
};
}
44 changes: 19 additions & 25 deletions Projects/Skylicht/Engine/Source/Animation/CAnimationTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ namespace Skylicht
m_posHint(0),
m_scaleHint(0),
m_rotHint(0),
Enable(false),
TrackID(0)
HaveAnimation(false)
{
}

Expand Down Expand Up @@ -75,15 +74,15 @@ namespace Skylicht
{
foundPositionIndex = -1;

//Test the Hints...
// Test the Hints...
if (positionHint >= 0 && positionHint < numPositionKey)
{
//check this hint
// check this hint
if (positionHint > 0 && pPositionKey[positionHint].frame >= frame && pPositionKey[positionHint - 1].frame < frame)
foundPositionIndex = positionHint;
else if (positionHint + 1 < numPositionKey)
{
//check the next index
// check the next index
if (pPositionKey[positionHint + 1].frame >= frame && pPositionKey[positionHint + 0].frame < frame)
{
positionHint++;
Expand All @@ -92,12 +91,12 @@ namespace Skylicht
}
}

//The hint test failed, do a full scan...
// The hint test failed, do a full scan...
if (foundPositionIndex == -1)
{
for (s32 i = 0; i < numPositionKey; ++i)
{
if (pPositionKey[i].frame >= frame) //Keys should to be sorted by frame
if (pPositionKey[i].frame >= frame) // Keys should to be sorted by frame
{
foundPositionIndex = i;
positionHint = i;
Expand All @@ -106,7 +105,7 @@ namespace Skylicht
}
}

//Do interpolation...
// Do interpolation...
if (foundPositionIndex == 0)
{
position.X = pPositionKey[0].position.X;
Expand Down Expand Up @@ -153,15 +152,15 @@ namespace Skylicht
{
foundScaleIndex = -1;

//Test the Hints...
// Test the Hints...
if (scaleHint >= 0 && scaleHint < numScaleKey)
{
//check this hint
// check this hint
if (scaleHint > 0 && pScaleKey[scaleHint].frame >= frame && pScaleKey[scaleHint - 1].frame < frame)
foundScaleIndex = scaleHint;
else if (scaleHint + 1 < numScaleKey)
{
//check the next index
// check the next index
if (pScaleKey[scaleHint + 1].frame >= frame && pScaleKey[scaleHint].frame < frame)
{
scaleHint++;
Expand All @@ -171,12 +170,12 @@ namespace Skylicht
}


//The hint test failed, do a full scan...
// The hint test failed, do a full scan...
if (foundScaleIndex == -1)
{
for (s32 i = 0; i < numScaleKey; ++i)
{
if (pScaleKey[i].frame >= frame) //Keys should to be sorted by frame
if (pScaleKey[i].frame >= frame) // Keys should to be sorted by frame
{
foundScaleIndex = i;
scaleHint = i;
Expand All @@ -185,7 +184,7 @@ namespace Skylicht
}
}

//Do interpolation...
// Do interpolation...
if (foundScaleIndex == 0)
{
scale.X = pScaleKey[0].scale.X;
Expand Down Expand Up @@ -231,15 +230,15 @@ namespace Skylicht
{
foundRotationIndex = -1;

//Test the Hints...
// Test the Hints...
if (rotationHint >= 0 && rotationHint < numRotKey)
{
//check this hint
// check this hint
if (rotationHint > 0 && pRotKey[rotationHint].frame >= frame && pRotKey[rotationHint - 1].frame < frame)
foundRotationIndex = rotationHint;
else if (rotationHint + 1 < numRotKey)
{
//check the next index
// check the next index
if (pRotKey[rotationHint + 1].frame >= frame && pRotKey[rotationHint].frame < frame)
{
rotationHint++;
Expand All @@ -249,12 +248,12 @@ namespace Skylicht
}


//The hint test failed, do a full scan...
// The hint test failed, do a full scan...
if (foundRotationIndex == -1)
{
for (s32 i = 0; i < numRotKey; ++i)
{
if (pRotKey[i].frame >= frame) //Keys should be sorted by frame
if (pRotKey[i].frame >= frame) // Keys should be sorted by frame
{
foundRotationIndex = i;
rotationHint = i;
Expand All @@ -263,7 +262,7 @@ namespace Skylicht
}
}

//Do interpolation...
// Do interpolation...
if (foundRotationIndex == 0)
{
rotation.X = pRotKey[0].rotation.X;
Expand Down Expand Up @@ -356,9 +355,4 @@ namespace Skylicht
result.Z = q1.Z*scale + q2.Z*invscale;
result.W = q1.W*scale + q2.W*invscale;
}

void CAnimationTrack::update(float timeStep)
{
// todo nothing
}
}
12 changes: 3 additions & 9 deletions Projects/Skylicht/Engine/Source/Animation/CAnimationTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ namespace Skylicht
s32 m_rotHint;

CFrameData *m_data;
public:

public:
std::string Name;
int TrackID;
bool Enable;
bool HaveAnimation;

public:
CAnimationTrack();
Expand All @@ -94,21 +93,16 @@ namespace Skylicht

CFrameData* getAnimData();

void update(float timeStep);

void clearAllKeyFrame()
{
m_data = NULL;

// clear hint
m_posHint = 0;
m_scaleHint = 0;
m_rotHint = 0;

Name = "";

// disable animation
Enable = false;
HaveAnimation = false;
}

void setFrameData(CFrameData *data)
Expand Down
Loading

0 comments on commit 2b7ae8e

Please sign in to comment.