mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
expanded light sample
minor improvements
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
AnimationChannel::AnimationChannel(AnimationController *controller){
|
||||
this->controller = controller;
|
||||
AnimationChannel::AnimationChannel(){
|
||||
}
|
||||
|
||||
AnimationChannel::~AnimationChannel(){
|
||||
|
||||
+2
-1
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -40,4 +40,9 @@ namespace vb01{
|
||||
}
|
||||
return anim;
|
||||
}
|
||||
|
||||
void AnimationController::addAnimationChannel(AnimationChannel *channel){
|
||||
channels.push_back(channel);
|
||||
channel->setAnimationController(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace vb01{
|
||||
~AnimationController(){}
|
||||
void update();
|
||||
Animation* getAnimation(std::string);
|
||||
void addAnimationChannel(AnimationChannel *channel);
|
||||
inline std::vector<Animation*> getAnimations(){return animations;}
|
||||
inline void addAnimation(Animation *anim){animations.push_back(anim);}
|
||||
inline void addAnimationChannel(AnimationChannel *channel){channels.push_back(channel);}
|
||||
private:
|
||||
std::vector<Animation*> animations;
|
||||
std::vector<AnimationChannel*> channels;
|
||||
|
||||
+9
-1
@@ -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<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 Keyframe findKeyframe(float, KeyframeChannel, bool);
|
||||
static Keyframe createKeyframe(Keyframe::Interpolation, float, float);
|
||||
static KeyframeChannel createKeyframeChannel(KeyframeChannel::Type, Animatable*, std::vector<Keyframe>);
|
||||
};
|
||||
|
||||
typedef KeyframeChannel::Type KeyframeChannelType;
|
||||
|
||||
+34
-2
@@ -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<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)
|
||||
root->update();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
+2
-2
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user