This example shows how to render a model with a clipping plane or cross-sections.
The header file of the viewer class:
27#ifndef EASY3D_TUTORIAL_CROSS_SECTION_H
28#define EASY3D_TUTORIAL_CROSS_SECTION_H
30#include <easy3d/viewer/viewer.h>
34 class CrossSection :
public Viewer
37 explicit CrossSection(
const std::string& title);
41 bool mouse_drag_event(
int x,
int y,
int dx,
int dy,
int button,
int modifiers)
override;
Definition collider.cpp:182
The source file of the viewer class:
28#include <easy3d/renderer/clipping_plane.h>
29#include <easy3d/renderer/manipulated_frame.h>
30#include <easy3d/renderer/manipulator.h>
37 CrossSection::CrossSection(
const std::string &title) : Viewer(title) {
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";
50 bool CrossSection::mouse_drag_event(
int x,
int y,
int dx,
int dy,
int button,
int modifiers) {
53 if (pressed_button_ == BUTTON_LEFT)
55 else if (pressed_button_ == BUTTON_RIGHT)
58 return Viewer::mouse_drag_event(x, y, dx, dy, button, modifiers);
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
27#include <easy3d/renderer/camera.h>
28#include <easy3d/util/resource.h>
29#include <easy3d/util/initializer.h>
46int main(
int argc,
char** argv) {
50 const std::string file_name = resource::directory() +
"/data/bunny.ply";
51 CrossSection viewer(EXAMPLE_TITLE);
52 viewer.camera()->setViewDirection(
vec3(-1, 1, -1));
54 if (!viewer.add_model(file_name)) {
55 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";