mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
expanded light sample
minor improvements
This commit is contained in:
@@ -4,8 +4,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace vb01{
|
namespace vb01{
|
||||||
AnimationChannel::AnimationChannel(AnimationController *controller){
|
AnimationChannel::AnimationChannel(){
|
||||||
this->controller = controller;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationChannel::~AnimationChannel(){
|
AnimationChannel::~AnimationChannel(){
|
||||||
|
|||||||
+2
-1
@@ -13,7 +13,7 @@ namespace vb01{
|
|||||||
|
|
||||||
class AnimationChannel{
|
class AnimationChannel{
|
||||||
public:
|
public:
|
||||||
AnimationChannel(AnimationController*);
|
AnimationChannel();
|
||||||
~AnimationChannel();
|
~AnimationChannel();
|
||||||
void update();
|
void update();
|
||||||
void setAnimationName(std::string name);
|
void setAnimationName(std::string name);
|
||||||
@@ -31,6 +31,7 @@ namespace vb01{
|
|||||||
inline void setForward(bool forward){this->forward = forward;}
|
inline void setForward(bool forward){this->forward = forward;}
|
||||||
inline bool isForward(){return forward;}
|
inline bool isForward(){return forward;}
|
||||||
inline std::string getAnimationName(){return animationName;}
|
inline std::string getAnimationName(){return animationName;}
|
||||||
|
inline void setAnimationController(AnimationController *controller){this->controller = controller;}
|
||||||
private:
|
private:
|
||||||
inline bool canUpdate(){return getTime() - lastUpdateTime > updateRate;}
|
inline bool canUpdate(){return getTime() - lastUpdateTime > updateRate;}
|
||||||
int getMaxKeyframeNum(std::string);
|
int getMaxKeyframeNum(std::string);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace vb01{
|
|||||||
Animation *anim = new Animation("anim");
|
Animation *anim = new Animation("anim");
|
||||||
anim->addKeyframeChannel(kc);
|
anim->addKeyframeChannel(kc);
|
||||||
|
|
||||||
channel = new AnimationChannel(controller);
|
channel = new AnimationChannel();
|
||||||
controller->addAnimationChannel(channel);
|
controller->addAnimationChannel(channel);
|
||||||
controller->addAnimation(anim);
|
controller->addAnimation(anim);
|
||||||
channel->addAnimatable(bone);
|
channel->addAnimatable(bone);
|
||||||
|
|||||||
@@ -40,4 +40,9 @@ namespace vb01{
|
|||||||
}
|
}
|
||||||
return anim;
|
return anim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AnimationController::addAnimationChannel(AnimationChannel *channel){
|
||||||
|
channels.push_back(channel);
|
||||||
|
channel->setAnimationController(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ namespace vb01{
|
|||||||
~AnimationController(){}
|
~AnimationController(){}
|
||||||
void update();
|
void update();
|
||||||
Animation* getAnimation(std::string);
|
Animation* getAnimation(std::string);
|
||||||
|
void addAnimationChannel(AnimationChannel *channel);
|
||||||
inline std::vector<Animation*> getAnimations(){return animations;}
|
inline std::vector<Animation*> getAnimations(){return animations;}
|
||||||
inline void addAnimation(Animation *anim){animations.push_back(anim);}
|
inline void addAnimation(Animation *anim){animations.push_back(anim);}
|
||||||
inline void addAnimationChannel(AnimationChannel *channel){channels.push_back(channel);}
|
|
||||||
private:
|
private:
|
||||||
std::vector<Animation*> animations;
|
std::vector<Animation*> animations;
|
||||||
std::vector<AnimationChannel*> channels;
|
std::vector<AnimationChannel*> channels;
|
||||||
|
|||||||
+9
-1
@@ -80,11 +80,19 @@ namespace vb01{
|
|||||||
return keyframeChannel.keyframes[pastKeyframeId + (last ? 0 : 1)];
|
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 keyframe;
|
||||||
keyframe.interpolation = interpolation;
|
keyframe.interpolation = interpolation;
|
||||||
keyframe.frame = frame;
|
keyframe.frame = frame;
|
||||||
keyframe.value = value;
|
keyframe.value = value;
|
||||||
return keyframe;
|
return keyframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeyframeChannel KeyframeChannel::createKeyframeChannel(KeyframeChannelType type, Animatable *animatable, vector<Keyframe> keyframes){
|
||||||
|
KeyframeChannel keyframeChannel;
|
||||||
|
keyframeChannel.type = type;
|
||||||
|
keyframeChannel.animatable = animatable;
|
||||||
|
keyframeChannel.keyframes = keyframes;
|
||||||
|
return keyframeChannel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ namespace vb01{
|
|||||||
static float interpolate(Keyframe, Keyframe, float);
|
static float interpolate(Keyframe, Keyframe, float);
|
||||||
static Keyframe findKeyframe(float, KeyframeChannel, bool);
|
static Keyframe findKeyframe(float, KeyframeChannel, bool);
|
||||||
static Keyframe createKeyframe(Keyframe::Interpolation, float, float);
|
static Keyframe createKeyframe(Keyframe::Interpolation, float, float);
|
||||||
|
static KeyframeChannel createKeyframeChannel(KeyframeChannel::Type, Animatable*, std::vector<Keyframe>);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef KeyframeChannel::Type KeyframeChannelType;
|
typedef KeyframeChannel::Type KeyframeChannelType;
|
||||||
|
|||||||
+34
-2
@@ -3,6 +3,9 @@
|
|||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
|
#include "animation.h"
|
||||||
|
#include "animationController.h"
|
||||||
|
#include "animationChannel.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
@@ -43,11 +46,40 @@ int main(){
|
|||||||
|
|
||||||
Light *light = new Light(Light::SPOT);
|
Light *light = new Light(Light::SPOT);
|
||||||
light->setColor(Vector3(1, 1, 1));
|
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);
|
lightNode->addLight(light);
|
||||||
rootNode->attachChild(lightNode);
|
rootNode->attachChild(lightNode);
|
||||||
lightNode->setOrientation(Quaternion(1.57, Vector3(1, 0, 0)));
|
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<Keyframe>({
|
||||||
|
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<Keyframe>({
|
||||||
|
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)
|
while(true)
|
||||||
root->update();
|
root->update();
|
||||||
|
|||||||
@@ -46,11 +46,11 @@ int main(){
|
|||||||
Skeleton *skeleton = mesh->getSkeleton();
|
Skeleton *skeleton = mesh->getSkeleton();
|
||||||
|
|
||||||
AnimationController *controller = skeleton->getAnimationController();
|
AnimationController *controller = skeleton->getAnimationController();
|
||||||
AnimationChannel *channel = new AnimationChannel(controller);
|
AnimationChannel *channel = new AnimationChannel();
|
||||||
|
controller->addAnimationChannel(channel);
|
||||||
channel->addAnimatable(skeleton->getBone("bone"));
|
channel->addAnimatable(skeleton->getBone("bone"));
|
||||||
channel->setAnimationName("morph");
|
channel->setAnimationName("morph");
|
||||||
channel->setLoop(true);
|
channel->setLoop(true);
|
||||||
controller->addAnimationChannel(channel);
|
|
||||||
|
|
||||||
Box *box = new Box(Vector3(1, 1, 1) * .25);
|
Box *box = new Box(Vector3(1, 1, 1) * .25);
|
||||||
Material *boxMat = new Material();
|
Material *boxMat = new Material();
|
||||||
|
|||||||
@@ -45,12 +45,12 @@ int main(){
|
|||||||
Skeleton *skeleton = mesh->getSkeleton();
|
Skeleton *skeleton = mesh->getSkeleton();
|
||||||
|
|
||||||
AnimationController *controller = skeleton->getAnimationController();
|
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("handIK.R"));
|
||||||
channel->addAnimatable(skeleton->getBone("elbowIK.R"));
|
channel->addAnimatable(skeleton->getBone("elbowIK.R"));
|
||||||
channel->setAnimationName("righArmAnim");
|
channel->setAnimationName("righArmAnim");
|
||||||
channel->setLoop(true);
|
channel->setLoop(true);
|
||||||
controller->addAnimationChannel(channel);
|
|
||||||
|
|
||||||
skeleton->getBone("handIK.L")->setPosePos(Vector3(1.5, -1.5, 0));
|
skeleton->getBone("handIK.L")->setPosePos(Vector3(1.5, -1.5, 0));
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -95,11 +95,11 @@ int main(){
|
|||||||
|
|
||||||
AnimationController *controller = textNode->getAnimationController();
|
AnimationController *controller = textNode->getAnimationController();
|
||||||
controller->addAnimation(anim);
|
controller->addAnimation(anim);
|
||||||
AnimationChannel *channel = new AnimationChannel(controller);
|
AnimationChannel *channel = new AnimationChannel();
|
||||||
|
controller->addAnimationChannel(channel);
|
||||||
channel->addAnimatable(texture);
|
channel->addAnimatable(texture);
|
||||||
channel->setAnimationName("tex");
|
channel->setAnimationName("tex");
|
||||||
channel->setLoop(true);
|
channel->setLoop(true);
|
||||||
controller->addAnimationChannel(channel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
|
|||||||
Reference in New Issue
Block a user