1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef EASY3D_TUTORIAL_CAMERA_INTERPOLATION_H
28#define EASY3D_TUTORIAL_CAMERA_INTERPOLATION_H
29
30#include <easy3d/viewer/viewer.h>
31
32
34 class KeyFrameInterpolator;
35}
36
37
38
39
41{
42public:
43 explicit TutorialCameraInterpolation(const std::string& title);
44 ~TutorialCameraInterpolation() override;
45
46protected:
47 bool key_press_event(int key, int modifiers) override;
48 void draw() const override;
49
50private:
52};
53
54
55#endif
A keyframe interpolator for animation generation.
Definition key_frame_interpolator.h:104
The built-in Easy3D viewer.
Definition viewer.h:63
Definition collider.cpp:182
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "viewer.h"
28#include <easy3d/renderer/camera.h>
29#include <easy3d/renderer/manipulated_camera_frame.h>
30#include <easy3d/renderer/key_frame_interpolator.h>
31#include <easy3d/core/model.h>
32
33
35
36
37
38TutorialCameraInterpolation::TutorialCameraInterpolation(const std::string& title)
40{
42
44
45 hint_ = "Press 'k' to add key frames\n"
46 "Press 'space' to start/stop the animation\n"
47 "Press 'd' to delete the camera path";
48}
49
50
51TutorialCameraInterpolation::~TutorialCameraInterpolation()
52{
53 delete interpolator_;
54}
55
56
57bool TutorialCameraInterpolation::key_press_event(int key, int modifiers)
58{
59 if (key == KEY_K && modifiers == 0) {
61 if (interpolator_->add_keyframe(*frame)) {
63 if (dist > camera_->sceneRadius())
64 camera_->setSceneRadius(dist);
65 std::cout << "Key frame added" << std::endl;
66 return true;
67 }
68 else
69 return false;
70 }
71 else if (key == KEY_SPACE && modifiers == 0) {
72 if (interpolator_->is_interpolation_started()) {
73 interpolator_->stop_interpolation();
74 std::cout << "Animation stopped" << std::endl;
75 }
76 else {
77 interpolator_->start_interpolation();
78 if (interpolator_->is_interpolation_started())
79 std::cout << "Animation started" << std::endl;
80 }
81 return true;
82 }
83 else if (key == KEY_D && modifiers == 0) {
84 interpolator_->delete_path();
85
87 for (auto m : models_)
88 box.
grow(m->bounding_box());
90 std::cout << "path deleted"<< std::endl;
91 return true;
92 }
93 else
94 return Viewer::key_press_event(key, modifiers);
95}
96
97
98void TutorialCameraInterpolation::draw() const {
99 Viewer::draw();
100
101
102 if (!interpolator_->is_interpolation_started()) {
103 interpolator_->draw_cameras(camera(), camera()->sceneRadius() * 0.05f);
104 interpolator_->draw_path(camera());
105 }
106}
107
108
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition frame.h:78
vec3 position() const
Returns the position of the Frame.
const Point & min_point() const
Return the coordinates of the min corner (const version).
Definition box.h:106
const Point & max_point() const
Return the coordinates of the max corner (const version).
Definition box.h:117
void grow(const Point &p)
Add a point to this box. This will compute its new extent.
Definition box.h:276
void update() const
Update the display (i.e., repaint).
Definition viewer.cpp:630
T distance(const Vec< N, T > &v1, const Vec< N, T > &v2)
Computes the distance between two vectors/points.
Definition vec.h:295
GenericBox< 3, float > Box3
A 3D axis-aligned bounding box of float type.
Definition types.h:108
int connect(SIGNAL *signal, FUNCTION const &slot)
Connects a function to the signal.
Definition signal.h:200
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "viewer.h"
28#include <easy3d/util/resource.h>
29#include <easy3d/util/initializer.h>
30
42
43
45
46int main(int argc, char** argv) {
47
49
51
52 TutorialCameraInterpolation viewer(EXAMPLE_TITLE);
53 if (!viewer.add_model(file_name, true)) {
54 LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
55 return EXIT_FAILURE;
56 }
57
58 return viewer.run();
59}
std::string directory()
Returns the resource directory (containing color maps, shaders, textures, fonts, etc....
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39