animate.h 2.08 KB
Newer Older
TheNumbat's avatar
TheNumbat committed
1
2
3
4

#pragma once

#include "widgets.h"
TheNumbat's avatar
TheNumbat committed
5
6
#include <SDL2/SDL.h>
#include <set>
TheNumbat's avatar
TheNumbat committed
7
8
9
10
11
12
13
14
15
16
17

namespace Gui {

enum class Mode;
class Manager;

class Anim_Camera {
public:
    Anim_Camera(Vec2 dim) : dim(dim) {}

    Camera at(float t) const;
TheNumbat's avatar
TheNumbat committed
18
    void set(float t, const Camera &cam);
TheNumbat's avatar
TheNumbat committed
19
20
21
22
23
24
25
26
27

    Splines<Vec3, Quat, float, float> splines;

private:
    Vec2 dim;
};

class Animate {
public:
TheNumbat's avatar
TheNumbat committed
28
29
    Animate(Vec2 screen_dim)
        : ui_camera(screen_dim), anim_camera(screen_dim), ui_render(screen_dim) {}
TheNumbat's avatar
TheNumbat committed
30
31

    void update_dim(Vec2 dim);
TheNumbat's avatar
TheNumbat committed
32
    bool keydown(Widgets &widgets, Undo &undo, Scene_ID sel, SDL_Keysym key);
TheNumbat's avatar
TheNumbat committed
33

TheNumbat's avatar
TheNumbat committed
34
35
36
37
38
39
40
41
42
    Vec3 selected_pos(Scene_Item &item);
    void end_transform(Undo &undo, Scene_Item &obj);
    void apply_transform(Widgets &widgets, Scene_Item &obj);
    bool select(Scene &scene, Widgets &widgets, Scene_ID selected, Scene_ID id, Vec3 cam, Vec2 spos,
                Vec3 dir);

    void render(Scene &scene, Scene_Maybe obj_opt, Widgets &widgets, Camera &cam);
    void timeline(Manager &manager, Undo &undo, Scene &scene, Scene_Maybe obj, Camera &user_cam);
    void UIsidebar(Manager &manager, Undo &undo, Scene_Maybe obj_opt, Camera &user_cam);
TheNumbat's avatar
TheNumbat committed
43
44

    void clear();
TheNumbat's avatar
TheNumbat committed
45
46
    void update(Scene &scene);
    void refresh(Scene &scene);
TheNumbat's avatar
TheNumbat committed
47

TheNumbat's avatar
TheNumbat committed
48
49
    std::string pump_output(Scene &scene);
    Camera set_time(Scene &scene, float time);
TheNumbat's avatar
TheNumbat committed
50
51
    float fps() const;
    int n_frames() const;
TheNumbat's avatar
TheNumbat committed
52
53
    const Anim_Camera &camera() const;
    Anim_Camera &camera();
TheNumbat's avatar
TheNumbat committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    void set(int n_frames, int fps);

private:
    Uint64 last_frame = 0;
    bool playing = false;
    int frame_rate = 30;
    int max_frame = 90;
    int current_frame = 0;
    int displayed_frame = 0;

    Widget_Camera ui_camera;
    Widget_Render ui_render;
    Anim_Camera anim_camera;

TheNumbat's avatar
TheNumbat committed
68
    Joint *joint_select = nullptr;
TheNumbat's avatar
TheNumbat committed
69
    unsigned int joint_id_offset = 0;
TheNumbat's avatar
TheNumbat committed
70

TheNumbat's avatar
TheNumbat committed
71
72
73
74
75
76
77
78
    Pose old_pose;
    Mat4 old_p_to_j;
    Vec3 old_euler;

    bool visualize_splines = false;
    bool camera_selected = false;
    Scene_ID prev_selected = 0;
    std::unordered_map<Scene_ID, GL::Lines> spline_cache;
TheNumbat's avatar
TheNumbat committed
79
    void make_spline(Scene_ID id, const Anim_Pose &pose);
TheNumbat's avatar
TheNumbat committed
80
81
    void camera_spline();
};
TheNumbat's avatar
TheNumbat committed
82
83

} // namespace Gui