mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
animation channel test
This commit is contained in:
+2
-1
@@ -29,7 +29,8 @@ target_link_libraries(vb01 freetype)
|
||||
set(renderTest nodeTest.cpp cameraTest.cpp)
|
||||
set(armatureTest boneTest.cpp)
|
||||
set(modelTest vbModelReaderTest.cpp)
|
||||
set(test ${library} ${renderTest} ${armatureTest} ${modelTest})
|
||||
set(animationTest animationChannelTest.cpp)
|
||||
set(test ${library} ${renderTest} ${armatureTest} ${modelTest} ${animationTest})
|
||||
|
||||
add_executable(vb01Tests main.cpp ${test})
|
||||
target_link_libraries(vb01Tests cppunit)
|
||||
|
||||
@@ -14,14 +14,12 @@ namespace vb01{
|
||||
|
||||
void AnimationChannel::update(){
|
||||
if(canUpdate()){
|
||||
if(firstFrame < currentFrame && currentFrame < numFrames)
|
||||
currentFrame += (forward? 1 : -1);
|
||||
else if(loop){
|
||||
if(!forward && currentFrame <= firstFrame)
|
||||
currentFrame = numFrames - 1;
|
||||
else if(forward && currentFrame >= numFrames)
|
||||
currentFrame = firstFrame + 1;
|
||||
}
|
||||
if(firstFrame <= currentFrame && currentFrame <= numFrames)
|
||||
currentFrame += (forward ? 1 : -1);
|
||||
if(currentFrame < firstFrame)
|
||||
currentFrame = (loop ? numFrames : firstFrame);
|
||||
else if(currentFrame > numFrames)
|
||||
currentFrame = (loop ? firstFrame : numFrames);
|
||||
|
||||
lastUpdateTime = getTime();
|
||||
}
|
||||
|
||||
+4
-1
@@ -20,9 +20,10 @@ namespace vb01{
|
||||
inline void removeAllBones(){bones.clear();}
|
||||
inline void setUpdateRate(float updateRate){this->updateRate = updateRate;}
|
||||
inline int getUpdateRate(){return updateRate;}
|
||||
inline int getFirstFrame(){return firstFrame;}
|
||||
inline int getCurrentFrame(){return currentFrame;}
|
||||
inline void setCurrentFrame(int frame){this->currentFrame = frame;}
|
||||
inline int getNumnFrames(){return numFrames;}
|
||||
inline int getNumFrames(){return numFrames;}
|
||||
inline void setLoop(bool loop){this->loop = loop;}
|
||||
inline bool isLoop(){return loop;}
|
||||
inline void setForward(bool forward){this->forward = forward;}
|
||||
@@ -39,6 +40,8 @@ namespace vb01{
|
||||
bool loop = false, forward = true;
|
||||
std::string animationName;
|
||||
std::vector<Bone*> bones;
|
||||
|
||||
friend class AnimationChannelTest;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "animationChannelTest.h"
|
||||
#include "skeleton.h"
|
||||
#include "animationController.h"
|
||||
#include "animationChannel.h"
|
||||
#include "animation.h"
|
||||
#include "bone.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
void AnimationChannelTest::setUp(){
|
||||
Bone *bone = new Bone("bone", 1, Vector3(0, 0, 0), Quaternion::QUAT_I, Vector3::VEC_IJK);
|
||||
skeleton = new Skeleton();
|
||||
skeleton->addBone(bone, nullptr);
|
||||
AnimationController *controller = skeleton->getAnimationController();
|
||||
|
||||
Keyframe k1, k2;
|
||||
k1.frame = 0;
|
||||
k2.frame = 10;
|
||||
KeyframeChannel kc;
|
||||
kc.type = KeyframeChannel::Type::POS_X;
|
||||
kc.keyframes = vector<Keyframe>({k1, k2});
|
||||
KeyframeGroup kg;
|
||||
kg.bone = bone;
|
||||
kg.keyframeChannels = vector<KeyframeChannel>({kc});
|
||||
Animation *anim = new Animation("anim");
|
||||
anim->addKeyframeGroup(kg);
|
||||
|
||||
channel = new AnimationChannel(controller);
|
||||
controller->addAnimationChannel(channel);
|
||||
controller->addAnimation(anim);
|
||||
channel->addBone(bone);
|
||||
channel->setAnimationName("anim");
|
||||
}
|
||||
|
||||
void AnimationChannelTest::tearDown(){
|
||||
}
|
||||
|
||||
void AnimationChannelTest::testUpdate(){
|
||||
int numFrames = 10;
|
||||
int firstFrame = channel->getFirstFrame();
|
||||
channel->numFrames = numFrames;
|
||||
|
||||
channel->lastUpdateTime = 0;
|
||||
channel->setLoop(false);
|
||||
channel->setForward(true);
|
||||
channel->update();
|
||||
CPPUNIT_ASSERT(channel->getCurrentFrame() == 2);
|
||||
|
||||
channel->lastUpdateTime = 0;
|
||||
channel->setCurrentFrame(numFrames - 1);
|
||||
channel->setLoop(false);
|
||||
channel->setForward(true);
|
||||
channel->update();
|
||||
CPPUNIT_ASSERT(channel->getCurrentFrame() == 10);
|
||||
|
||||
channel->lastUpdateTime = 0;
|
||||
channel->setCurrentFrame(1);
|
||||
channel->setLoop(false);
|
||||
channel->setForward(false);
|
||||
channel->update();
|
||||
CPPUNIT_ASSERT(channel->getCurrentFrame() == firstFrame);
|
||||
|
||||
channel->lastUpdateTime = 0;
|
||||
channel->setCurrentFrame(numFrames);
|
||||
channel->setLoop(true);
|
||||
channel->setForward(true);
|
||||
channel->update();
|
||||
CPPUNIT_ASSERT(channel->getCurrentFrame() == firstFrame);
|
||||
|
||||
channel->lastUpdateTime = 0;
|
||||
channel->setCurrentFrame(firstFrame);
|
||||
channel->setLoop(true);
|
||||
channel->setForward(false);
|
||||
channel->update();
|
||||
CPPUNIT_ASSERT(channel->getCurrentFrame() == numFrames);
|
||||
}
|
||||
|
||||
void AnimationChannelTest::testGetMaxKeyframeNum(){
|
||||
int numFrames = channel->getMaxKeyframeNum("anim");
|
||||
CPPUNIT_ASSERT(numFrames == 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef ANIMATION_CHANNEL_TEST
|
||||
#define ANIMATION_CHANNEL_TES
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace vb01{
|
||||
class Skeleton;
|
||||
class AnimationChannel;
|
||||
|
||||
class AnimationChannelTest : public CppUnit::TestFixture{
|
||||
CPPUNIT_TEST_SUITE(AnimationChannelTest);
|
||||
CPPUNIT_TEST(testUpdate);
|
||||
CPPUNIT_TEST(testGetMaxKeyframeNum);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
AnimationChannelTest(){}
|
||||
~AnimationChannelTest(){}
|
||||
void setUp();
|
||||
void tearDown();
|
||||
private:
|
||||
Skeleton *skeleton = nullptr;
|
||||
AnimationChannel *channel = nullptr;
|
||||
|
||||
void testUpdate();
|
||||
void testGetMaxKeyframeNum();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -72,7 +72,7 @@ namespace vb01{
|
||||
Keyframe nextKeyframe = animChannel.keyframes[pastKeyframeId + 1];
|
||||
int pastFrame = pastKeyframe.frame;
|
||||
int nextFrame = nextKeyframe.frame;
|
||||
ratio = (float)(channel->getCurrentFrame() - pastFrame) / (nextFrame - pastFrame);
|
||||
ratio = (float)(max(0, channel->getCurrentFrame() - pastFrame)) / (nextFrame - pastFrame);
|
||||
interpMode = pastKeyframe.interpolation;
|
||||
|
||||
switch(animChannel.type){
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
Bone::Bone(string name, float length, Vector3 pos,Quaternion rot, Vector3 scale) : Node(pos,rot,scale,name){
|
||||
Bone::Bone(string name, float length, Vector3 pos, Quaternion rot, Vector3 scale) : Node(pos, rot, scale, name){
|
||||
this->name = name;
|
||||
this->length = length;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "nodeTest.h"
|
||||
#include "boneTest.h"
|
||||
#include "vbModelReaderTest.h"
|
||||
#include "animationChannelTest.h"
|
||||
|
||||
using namespace CppUnit;
|
||||
using namespace vb01;
|
||||
@@ -17,6 +18,7 @@ int main(){
|
||||
runner.addTest(NodeTest::suite());
|
||||
runner.addTest(BoneTest::suite());
|
||||
runner.addTest(VbModelReaderTest::suite());
|
||||
runner.addTest(AnimationChannelTest::suite());
|
||||
runner.run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user