animate.h 2.48 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

namespace Gui {

enum class Mode;
class Manager;
TheNumbat's avatar
TheNumbat committed
12
class Simulate;
TheNumbat's avatar
TheNumbat committed
13
14
15

class Anim_Camera {
public:
TheNumbat's avatar
TheNumbat committed
16
17
    Anim_Camera(Vec2 dim) : dim(dim) {
    }
TheNumbat's avatar
TheNumbat committed
18
19

    Camera at(float t) const;
TheNumbat's avatar
TheNumbat committed
20
    void set(float t, const Camera& cam);
TheNumbat's avatar
TheNumbat committed
21

TheNumbat's avatar
TheNumbat committed
22
    Splines<Vec3, Quat, float, float, float, float> splines;
TheNumbat's avatar
TheNumbat committed
23
24
25
26
27
28
29

private:
    Vec2 dim;
};

class Animate {
public:
TheNumbat's avatar
TheNumbat committed
30
31
32
    Animate(Simulate& sim, Vec2 screen_dim)
        : ui_camera(screen_dim), anim_camera(screen_dim), ui_render(screen_dim), simulate(sim) {
    }
TheNumbat's avatar
TheNumbat committed
33
34

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

TheNumbat's avatar
TheNumbat committed
37
38
39
40
    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,
TheNumbat's avatar
TheNumbat committed
41
42
                Vec3 dir);

TheNumbat's avatar
TheNumbat committed
43
44
45
    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
46
47

    void clear();
TheNumbat's avatar
TheNumbat committed
48
49
50
51
    void update(Scene& scene);
    void refresh(Scene& scene);
    void load_cam(Vec3 pos, Vec3 front, float ar, float fov, float ap, float dist);
    void step_sim(Scene& scene);
TheNumbat's avatar
TheNumbat committed
52

TheNumbat's avatar
TheNumbat committed
53
54
    std::string pump_output(Scene& scene);
    Camera set_time(Scene& scene, float time);
TheNumbat's avatar
TheNumbat committed
55
56
    float fps() const;
    int n_frames() const;
TheNumbat's avatar
TheNumbat committed
57
58
59
    const Anim_Camera& camera() const;
    Anim_Camera& camera();
    Camera current_camera() const;
TheNumbat's avatar
TheNumbat committed
60
    void set(int n_frames, int fps);
TheNumbat's avatar
TheNumbat committed
61
    void set_max(int frames);
TheNumbat's avatar
TheNumbat committed
62
63
    void invalidate(Skeleton::IK_Handle* handle);
    void invalidate(Joint* handle);
TheNumbat's avatar
TheNumbat committed
64
65
66
67

private:
    Uint64 last_frame = 0;
    bool playing = false;
TheNumbat's avatar
TheNumbat committed
68
69
    int frame_rate = 24;
    int max_frame = 96;
TheNumbat's avatar
TheNumbat committed
70
71
72
73
74
75
    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
76
    Simulate& simulate;
TheNumbat's avatar
TheNumbat committed
77

TheNumbat's avatar
TheNumbat committed
78
79
    Joint* joint_select = nullptr;
    Skeleton::IK_Handle* handle_select = nullptr;
TheNumbat's avatar
TheNumbat committed
80
    unsigned int joint_id_offset = 0;
TheNumbat's avatar
TheNumbat committed
81

TheNumbat's avatar
TheNumbat committed
82
    Pose old_pose;
TheNumbat's avatar
TheNumbat committed
83
84
    Mat4 old_T;
    Vec3 old_euler, old_pos;
TheNumbat's avatar
TheNumbat committed
85
86
87
88
89

    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
90
    void make_spline(Scene_ID id, const Anim_Pose& pose);
TheNumbat's avatar
TheNumbat committed
91
92
    void camera_spline();
};
TheNumbat's avatar
TheNumbat committed
93
94

} // namespace Gui