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_OBJECT_MANIPULATION_VIEWER_H
28#define EASY3D_TUTORIAL_OBJECT_MANIPULATION_VIEWER_H
29
30#include <easy3d/viewer/viewer.h>
31
32#include <unordered_map>
33
34
35
37 class Model;
38}
39
41public:
42 explicit TutorialObjectManipulation(const std::string &title);
43
44protected:
45 bool mouse_press_event(int x, int y, int button, int modifiers) override;
46 bool mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) override;
47 void draw() const override;
48
49private:
51
52private:
54};
55
56
57#endif
The base class of renderable 3D models.
Definition model.h:50
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/gui/picker_model.h>
29#include <easy3d/core/model.h>
30#include <easy3d/renderer/drawable_triangles.h>
31#include <easy3d/renderer/renderer.h>
32#include <easy3d/renderer/manipulator.h>
33#include <easy3d/renderer/manipulated_frame.h>
34#include <easy3d/util/file_system.h>
35#include <easy3d/util/setting.h>
36
37
39
40
41
42TutorialObjectManipulation::TutorialObjectManipulation(const std::string &title)
43 :
Viewer(title), selected_model_(nullptr)
44{
45
46 camera()->setViewDirection(
vec3(0, 0, -1));
47 camera()->setUpVector(
vec3(0, 1, 0));
48
49 manual_ =
50 "-------------------- Manipulator Viewer usage ---------------------\n"
51 "Press the left button to pick/unpick a model. \n"
52 "When a model is picked, using the mouse to manipulate it: \n"
53 " - Alt + left button: rotate the model \n"
54 " - Alt + right button: translate the model \n"
55 "------------------------------------------------------------------ \n";
56
57 hint_ = "Press left button to pick/unpick a model\n"
58 "When picked:\n"
59 " - Alt + left button: rotate bunny model\n"
60 " - Alt + right button: translate bunny model";
61}
62
63
64bool TutorialObjectManipulation::mouse_press_event(int x, int y, int button, int modifiers) {
65 if (modifiers != MODIF_ALT) {
67 auto model = picker.pick(models(), x, y);
68 if (model)
69 mark(model);
70 return true;
71 }
72 else
73 return Viewer::mouse_press_event(x, y, button, modifiers);
74}
75
76
77bool TutorialObjectManipulation::mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) {
78
79 if (modifiers == MODIF_ALT && selected_model_) {
81
86 switch (button) {
87 case BUTTON_LEFT:
89 break;
90 case BUTTON_RIGHT:
92 break;
93 default:
94 break;
95 }
96 return true;
97 }
98 else
99 return Viewer::mouse_drag_event(x, y, dx, dy, button, modifiers);
100}
101
102
104 for (auto m : models()) {
105 m->renderer()->set_selected(m.get() == model);
106 auto faces = m->renderer()->get_triangles_drawable("faces");
107 if (m.get() == model)
108 faces->set_uniform_coloring(
vec4(1, 0, 0, 1.0f));
109 else
111 }
113
114 selected_model_ = model;
115 if (!model->manipulator()) {
116 model->set_manipulator(std::make_shared<Manipulator>(model));
117 model->manipulator()->frame()->modified.connect(this,
118 static_cast<void (TutorialObjectManipulation::*)(void) const>(&TutorialObjectManipulation::update));
119 }
120 update();
121}
122
123
124void TutorialObjectManipulation::draw() const {
125 Viewer::draw();
126 for (auto m : models()) {
127 if (m->renderer()->is_selected() && m->manipulator())
128 m->manipulator()->draw_frame(camera());
129 }
130}
131
132
A Frame that can be rotated and translated using the mouse.
Definition manipulated_frame.h:57
virtual void action_translate(int mouse_x, int mouse_y, int mouse_dx, int mouse_dy, Camera *camera, ScreenAxis axis)
Translates the frame based on mouse movement.
@ VERTICAL
Vertical constraint.
Definition manipulated_frame.h:167
@ HORIZONTAL
Horizontal constraint.
Definition manipulated_frame.h:166
@ ORTHOGONAL
Orthogonal constraint.
Definition manipulated_frame.h:168
@ NONE
No constraint.
Definition manipulated_frame.h:165
virtual void action_rotate(int mouse_x, int mouse_y, int mouse_dx, int mouse_dy, Camera *camera, ScreenAxis axis)
Rotates the frame based on mouse movement.
Implementation of picking mechanism for set of models.
Definition picker_model.h:49
std::string simple_name(const std::string &path)
Gets file name without path but with extension (e.g, /a/b/c.Ext => c.Ext)
EASY3D_UTIL_EXPORT vec4 surface_mesh_faces_color
Color of surface mesh faces.
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46