Commit c5ffca43 authored by Lázár Bence Kis's avatar Lázár Bence Kis
Browse files

Cb says...

parent e39c86f8
Loading
Loading
Loading
Loading
+33 −634

File changed.

Preview size limit exceeded, changes collapsed.

+39 −0
Original line number Diff line number Diff line
#pragma once
#include "animation.hpp"
#include <string>
#include <unordered_map>
#include <memory>

namespace anim {

class AnimationController {
public:
    AnimationController();
    
    void update(double deltaTime);
    void playAnimation(const std::string& name, bool crossFade = true);
    void stopAnimation(const std::string& name);
    void stopAllAnimations();
    
    void addAnimation(std::shared_ptr<Animation> animation);
    void removeAnimation(const std::string& name);
    
    void setBlendTime(double time) { m_blendTime = time; }
    void setDefaultBlendTime(double time) { m_defaultBlendTime = time; }
    
private:
    struct AnimationState {
        std::shared_ptr<Animation> animation;
        double weight{1.0};
        double blendTime{0.5};
        bool isBlendingOut{false};
    };
    
    std::unordered_map<std::string, AnimationState> m_activeAnimations;
    double m_blendTime{0.5};
    double m_defaultBlendTime{0.5};
    
    void updateBlendWeights(double deltaTime);
};

} // namespace anim
+47 −0
Original line number Diff line number Diff line
#pragma once
#include <string>
#include <vector>
#include <anim/keyframe.hpp>
#include <com/reflection.hpp>
#include <com/frame.hpp>

namespace anim {

class AnimationTrack {
public:
    AnimationTrack(const std::string& name, 
                   com::Frame* target, 
                   const std::string& method,
                   const std::vector<KeyPtr>& keyframes,
                   com::Reflection::TypeID valueType);
                   
    virtual ~AnimationTrack() = default;

    // Core functionality
    void evaluate(double currentTime, bool looping = true);
    void addKeyframe(KeyPtr key);
    void removeKeyframe(size_t index);
    
    // Getters
    const std::string& getName() const { return m_name; }
    double getDuration() const;
    size_t getKeyframeCount() const { return m_keyframes.size(); }
    const KeyPtr& getKeyframe(size_t index) const { return m_keyframes[index]; }
    com::Frame* getTarget() const { return m_target; }
    com::Reflection::TypeID getValueType() const { return m_valueType; }

protected:
    // Helper methods
    std::pair<const Key*, const Key*> findSurroundingKeys(double time) const;
    double normalizeTime(double time) const;
    void sortKeyframes();

    // Member variables
    std::string m_name;
    com::Frame* m_target;
    const com::Reflection::Function* m_method;
    std::vector<KeyPtr> m_keyframes;
    com::Reflection::TypeID m_valueType;
};

} // namespace anim
+25 −0
Original line number Diff line number Diff line
#pragma once
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>

namespace anim {

class Interpolator {
public:
    template<typename T>
    static T lerp(const T& a, const T& b, float t);
    
    static glm::quat slerp(const glm::quat& a, const glm::quat& b, float t) {
        return glm::slerp(a, b, t);
    }
    
    static float ease(float t, float easingFactor = 2.0f);
    static float bezier(float t, const glm::vec2& p1, const glm::vec2& p2);
};

template<typename T>
T Interpolator::lerp(const T& a, const T& b, float t) {
    return a + (b - a) * t;
}

} // namespace anim
+40 −0
Original line number Diff line number Diff line
#pragma once
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <memory>
#include <typeinfo>

namespace anim {

class Key {
public:
    Key(double time) : m_time(time) {}
    virtual ~Key() = default;
    
    double getTime() const { return m_time; }
    virtual void* getValue() = 0;
    virtual const std::type_info& getType() const = 0;

protected:
    double m_time;
};

template<typename T>
class Keyframe : public Key {
public:
    Keyframe(double time, const T& value) 
        : Key(time), m_value(value) {}

    void* getValue() override { return &m_value; }
    const std::type_info& getType() const override { return typeid(T); }
    
    const T& value() const { return m_value; }
    void setValue(const T& value) { m_value = value; }

private:
    T m_value;
};

using KeyframePtr = std::shared_ptr<Key>;

} // namespace anim
Loading