This example shows how to render a model with a clipping plane or cross-sections.
The header file of the viewer class:
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_CROSS_SECTION_H
28#define EASY3D_TUTORIAL_CROSS_SECTION_H
29
30#include <easy3d/viewer/viewer.h>
31
33
34 class CrossSection : public Viewer
35 {
36 public:
37 explicit CrossSection(const std::string& title);
38
39 protected:
40
41 bool mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) override;
42 };
43
44}
45
46#endif
Definition collider.cpp:182
The source file of the viewer class:
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/clipping_plane.h>
29#include <easy3d/renderer/manipulated_frame.h>
30#include <easy3d/renderer/manipulator.h>
31
32
34
35
36
37 CrossSection::CrossSection(const std::string &title) : Viewer(title) {
38
40
41 hint_ =
42 "Left button: rotate the clipping plane \n"
43 "Right button: translate the clipping plane \n"
44 "Alt + 'c': enable/disable clipping plane\n"
45 "Alt + 'v': show/hide clipping plane \n"
46 "Alt + 'x': toggle cross-section";
47 }
48
49
50 bool CrossSection::mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) {
51
53 if (pressed_button_ == BUTTON_LEFT)
55 else if (pressed_button_ == BUTTON_RIGHT)
57 else
58 return Viewer::mouse_drag_event(x, y, dx, dy, button, modifiers);
59
60 return false;
61 }
62
63
64
65}
static ClippingPlane * instance()
Definition clipping_plane.cpp:61
virtual Manipulator * manipulator()
returns the manipulator attached to the clipping plane.
Definition clipping_plane.h:106
void set_enabled(bool b)
enables/disables the clipping plane.
Definition clipping_plane.h:56
@ 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.
ManipulatedFrame * frame()
Returns the manipulated frame.
Definition manipulator.h:69
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 <easy3d/renderer/camera.h>
28#include <easy3d/util/resource.h>
29#include <easy3d/util/initializer.h>
30
31#include "viewer.h"
32
43
45
46int main(int argc, char** argv) {
47
49
51 CrossSection viewer(EXAMPLE_TITLE);
52 viewer.camera()->setViewDirection(
vec3(-1, 1, -1));
53
54 if (!viewer.add_model(file_name)) {
55 LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
56 return EXIT_FAILURE;
57 }
58
59 return viewer.run();
60}
std::string directory()
Returns the resource directory (containing color maps, shaders, textures, fonts, etc....
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
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