diff --git a/animationChannel.cpp b/animationChannel.cpp index 17bb85c..4bd8968 100644 --- a/animationChannel.cpp +++ b/animationChannel.cpp @@ -4,8 +4,7 @@ using namespace std; namespace vb01{ - AnimationChannel::AnimationChannel(AnimationController *controller){ - this->controller = controller; + AnimationChannel::AnimationChannel(){ } AnimationChannel::~AnimationChannel(){ diff --git a/animationChannel.h b/animationChannel.h index a7aa5e3..a980467 100644 --- a/animationChannel.h +++ b/animationChannel.h @@ -13,7 +13,7 @@ namespace vb01{ class AnimationChannel{ public: - AnimationChannel(AnimationController*); + AnimationChannel(); ~AnimationChannel(); void update(); void setAnimationName(std::string name); @@ -31,6 +31,7 @@ namespace vb01{ inline void setForward(bool forward){this->forward = forward;} inline bool isForward(){return forward;} inline std::string getAnimationName(){return animationName;} + inline void setAnimationController(AnimationController *controller){this->controller = controller;} private: inline bool canUpdate(){return getTime() - lastUpdateTime > updateRate;} int getMaxKeyframeNum(std::string); diff --git a/animationChannelTest.cpp b/animationChannelTest.cpp index 228761b..60f33e6 100644 --- a/animationChannelTest.cpp +++ b/animationChannelTest.cpp @@ -26,7 +26,7 @@ namespace vb01{ Animation *anim = new Animation("anim"); anim->addKeyframeChannel(kc); - channel = new AnimationChannel(controller); + channel = new AnimationChannel(); controller->addAnimationChannel(channel); controller->addAnimation(anim); channel->addAnimatable(bone); diff --git a/animationController.cpp b/animationController.cpp index 3160539..e0dd0b1 100644 --- a/animationController.cpp +++ b/animationController.cpp @@ -40,4 +40,9 @@ namespace vb01{ } return anim; } + + void AnimationController::addAnimationChannel(AnimationChannel *channel){ + channels.push_back(channel); + channel->setAnimationController(this); + } } diff --git a/animationController.h b/animationController.h index b57c032..f93bed8 100644 --- a/animationController.h +++ b/animationController.h @@ -19,9 +19,9 @@ namespace vb01{ ~AnimationController(){} void update(); Animation* getAnimation(std::string); + void addAnimationChannel(AnimationChannel *channel); inline std::vector getAnimations(){return animations;} inline void addAnimation(Animation *anim){animations.push_back(anim);} - inline void addAnimationChannel(AnimationChannel *channel){channels.push_back(channel);} private: std::vector animations; std::vector channels; diff --git a/keyframeChannel.cpp b/keyframeChannel.cpp index 049f6a6..dbfc242 100644 --- a/keyframeChannel.cpp +++ b/keyframeChannel.cpp @@ -80,11 +80,19 @@ namespace vb01{ return keyframeChannel.keyframes[pastKeyframeId + (last ? 0 : 1)]; } - Keyframe KeyframeChannel::createKeyframe(KeyframeInterpolation interpolation, float frame, float value){ + Keyframe KeyframeChannel::createKeyframe(KeyframeInterpolation interpolation, float value, float frame) { Keyframe keyframe; keyframe.interpolation = interpolation; keyframe.frame = frame; keyframe.value = value; return keyframe; } + + KeyframeChannel KeyframeChannel::createKeyframeChannel(KeyframeChannelType type, Animatable *animatable, vector keyframes){ + KeyframeChannel keyframeChannel; + keyframeChannel.type = type; + keyframeChannel.animatable = animatable; + keyframeChannel.keyframes = keyframes; + return keyframeChannel; + } } diff --git a/keyframeChannel.h b/keyframeChannel.h index eaa6aab..4c6e098 100644 --- a/keyframeChannel.h +++ b/keyframeChannel.h @@ -68,6 +68,7 @@ namespace vb01{ static float interpolate(Keyframe, Keyframe, float); static Keyframe findKeyframe(float, KeyframeChannel, bool); static Keyframe createKeyframe(Keyframe::Interpolation, float, float); + static KeyframeChannel createKeyframeChannel(KeyframeChannel::Type, Animatable*, std::vector); }; typedef KeyframeChannel::Type KeyframeChannelType; diff --git a/lightSample.cpp b/lightSample.cpp index ffa047a..7d70df3 100644 --- a/lightSample.cpp +++ b/lightSample.cpp @@ -3,6 +3,9 @@ #include "material.h" #include "node.h" #include "light.h" +#include "animation.h" +#include "animationController.h" +#include "animationChannel.h" using namespace std; using namespace vb01; @@ -43,11 +46,40 @@ int main(){ Light *light = new Light(Light::SPOT); light->setColor(Vector3(1, 1, 1)); - Node *lightNode = new Node(); + Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "", new AnimationController()); lightNode->addLight(light); rootNode->attachChild(lightNode); lightNode->setOrientation(Quaternion(1.57, Vector3(1, 0, 0))); - lightNode->setPosition(Vector3(0, 2, 0)); + lightNode->setPosition(Vector3(0, 5, 0)); + + KeyframeChannel kcA; + kcA.animatable = light; + kcA.type = KeyframeChannel::SPOTLIGHT_OUTER_ANGLE; + kcA.keyframes = vector({ + KeyframeChannel::createKeyframe(Keyframe::LINEAR, .1, 1), + KeyframeChannel::createKeyframe(Keyframe::LINEAR, .7, 60), + KeyframeChannel::createKeyframe(Keyframe::LINEAR, .9, 120) + }); + + KeyframeChannel kcB; + kcA.animatable = light; + kcA.type = KeyframeChannel::SPOTLIGHT_INNER_ANGLE; + kcA.keyframes = vector({ + KeyframeChannel::createKeyframe(Keyframe::LINEAR, .1, 1), + KeyframeChannel::createKeyframe(Keyframe::LINEAR, .7, 60) + }); + + Animation *animation = new Animation("spotlightAnim"); + animation->addKeyframeChannel(kcA); + animation->addKeyframeChannel(kcB); + + AnimationController *controller = lightNode->getAnimationController(); + controller->addAnimation(animation); + AnimationChannel *channel = new AnimationChannel(); + controller->addAnimationChannel(channel); + channel->addAnimatable(light); + channel->setLoop(true); + channel->setAnimationName("spotlightAnim"); while(true) root->update(); diff --git a/morphAnimationSample.cpp b/morphAnimationSample.cpp index cec6456..0180b00 100644 --- a/morphAnimationSample.cpp +++ b/morphAnimationSample.cpp @@ -46,11 +46,11 @@ int main(){ Skeleton *skeleton = mesh->getSkeleton(); AnimationController *controller = skeleton->getAnimationController(); - AnimationChannel *channel = new AnimationChannel(controller); + AnimationChannel *channel = new AnimationChannel(); + controller->addAnimationChannel(channel); channel->addAnimatable(skeleton->getBone("bone")); channel->setAnimationName("morph"); channel->setLoop(true); - controller->addAnimationChannel(channel); Box *box = new Box(Vector3(1, 1, 1) * .25); Material *boxMat = new Material(); diff --git a/skeletalAnimationSample.cpp b/skeletalAnimationSample.cpp index 5a74a11..7213e4c 100644 --- a/skeletalAnimationSample.cpp +++ b/skeletalAnimationSample.cpp @@ -45,12 +45,12 @@ int main(){ Skeleton *skeleton = mesh->getSkeleton(); AnimationController *controller = skeleton->getAnimationController(); - AnimationChannel *channel = new AnimationChannel(controller); + AnimationChannel *channel = new AnimationChannel(); + controller->addAnimationChannel(channel); channel->addAnimatable(skeleton->getBone("handIK.R")); channel->addAnimatable(skeleton->getBone("elbowIK.R")); channel->setAnimationName("righArmAnim"); channel->setLoop(true); - controller->addAnimationChannel(channel); skeleton->getBone("handIK.L")->setPosePos(Vector3(1.5, -1.5, 0)); diff --git a/textSample.cpp b/textSample.cpp index f15524c..aad5041 100644 --- a/textSample.cpp +++ b/textSample.cpp @@ -95,11 +95,11 @@ int main(){ AnimationController *controller = textNode->getAnimationController(); controller->addAnimation(anim); - AnimationChannel *channel = new AnimationChannel(controller); + AnimationChannel *channel = new AnimationChannel(); + controller->addAnimationChannel(channel); channel->addAnimatable(texture); channel->setAnimationName("tex"); channel->setLoop(true); - controller->addAnimationChannel(channel); } while(true){