Easy3D 2.6.1
Loading...
Searching...
No Matches
manipulated_camera_frame.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
38
39#ifndef EASY3D_RENDERER_MANIPULATED_CAMERA_FRAME_H
40#define EASY3D_RENDERER_MANIPULATED_CAMERA_FRAME_H
41
42#include <easy3d/renderer/manipulated_frame.h>
43
44
45namespace easy3d {
46
62 public:
65
67 ~ManipulatedCameraFrame() override = default;
68
74
81
84
93 vec3 pivotPoint() const { return pivotPoint_; }
94
99 void setPivotPoint(const vec3 &point) { pivotPoint_ = point; }
101
104 public:
114 bool zoomsOnPivotPoint() const { return zoomsOnPivotPoint_; }
115
120 void setZoomsOnPivotPoint(bool enabled) { zoomsOnPivotPoint_ = enabled; }
122
125
134 void action_rotate(int mouse_x, int mouse_y, int mouse_dx, int mouse_dy, Camera* camera, ScreenAxis axis) override;
144 void action_translate(int mouse_x, int mouse_y, int mouse_dx, int mouse_dy, Camera* camera, ScreenAxis axis) override;
150 void action_zoom(int dy_wheel, Camera* camera) override;
156 virtual void action_turn(float angle_radian, Camera* camera);
158
159 //---------------------------------------------------------------
160 // more movement of the camera
161 //---------------------------------------------------------------
162
163// if (key == GLFW_KEY_UP && modifiers == 0) { // move camera forward
164// float step = 0.02f * camera_->sceneRadius();
165// camera_->frame()->translate(camera_->frame()->inverseTransformOf(vec3(0.0, 0.0, -step)));
166// }
167// else if (key == GLFW_KEY_DOWN && modifiers == 0) {// move camera backward
168// float step = 0.02f * camera_->sceneRadius();
169// camera_->frame()->translate(camera_->frame()->inverseTransformOf(vec3(0.0, 0.0, step)));
170// }
171// else if (key == GLFW_KEY_LEFT && modifiers == GLFW_MOD_CONTROL) { // move camera left
172// float step = 0.02f * camera_->sceneRadius();
173// camera_->frame()->translate(camera_->frame()->inverseTransformOf(vec3(-step, 0.0, 0.0)));
174// }
175// else if (key == GLFW_KEY_RIGHT && modifiers == GLFW_MOD_CONTROL) { // move camera right
176// float step = 0.02f * camera_->sceneRadius();
177// camera_->frame()->translate(camera_->frame()->inverseTransformOf(vec3(step, 0.0, 0.0)));
178// }
179// else if (key == GLFW_KEY_UP && modifiers == GLFW_MOD_CONTROL) { // move camera up
180// float step = 0.02f * camera_->sceneRadius();
181// camera_->frame()->translate(camera_->frame()->inverseTransformOf(vec3(0.0, step, 0.0)));
182// }
183// else if (key == GLFW_KEY_DOWN && modifiers == GLFW_MOD_CONTROL) { // move camera down
184// float step = 0.02f * camera_->sceneRadius();
185// camera_->frame()->translate(camera_->frame()->inverseTransformOf(vec3(0.0, -step, 0.0)));
186// }
187//
188//---------------------------------------------------------------------------
189//
190// // zoom to pixel
191// const double coef = 0.1;
192// // Small hack: attach a temporary frame to take advantage of lookAt without modifying frame
193// static ManipulatedCameraFrame* tempFrame = new ManipulatedCameraFrame;
194// tempFrame->setPosition(coef*camera()->frame()->position() + (1.0-coef)*p);
195// tempFrame->setOrientation(camera()->frame()->orientation());
196// camera()->setFrame(tempFrame);
197// camera()->lookAt(p);
198//
199// // zoom to fit screen
200// static ManipulatedCameraFrame* tempFrame = new ManipulatedCameraFrame;
201// tempFrame->setPosition(camera()->frame()->position());
202// tempFrame->setOrientation(camera()->frame()->orientation());
203// camera()->setFrame(tempFrame);
204// camera()->showEntireScene();
205
206 private:
207 bool zoomsOnPivotPoint_;
208 vec3 pivotPoint_;
209
210 private:
211 friend class Camera;
212 friend class Viewer;
213 };
214
215
216}
217
218#endif // EASY3D_RENDERER_MANIPULATED_CAMERA_FRAME_H
A perspective or orthographic camera.
Definition camera.h:113
void setPivotPoint(const vec3 &point)
Sets the pivotPoint(), defined in the world coordinate system.
Definition manipulated_camera_frame.h:99
void action_rotate(int mouse_x, int mouse_y, int mouse_dx, int mouse_dy, Camera *camera, ScreenAxis axis) override
Rotates the frame based on mouse movement.
Definition manipulated_camera_frame.cpp:71
vec3 pivotPoint() const
Returns the point the ManipulatedCameraFrame pivots around, which is the camera's pivot point.
Definition manipulated_camera_frame.h:93
ManipulatedCameraFrame & operator=(const ManipulatedCameraFrame &mcf)
Copy assignment operator.
Definition manipulated_camera_frame.cpp:53
void action_zoom(int dy_wheel, Camera *camera) override
Zooms the frame based on mouse wheel movement.
Definition manipulated_camera_frame.cpp:175
ManipulatedCameraFrame()
Default constructor.
Definition manipulated_camera_frame.cpp:46
~ManipulatedCameraFrame() override=default
bool zoomsOnPivotPoint() const
Returns whether the QGLViewer::ZOOM action zooms on the pivot point.
Definition manipulated_camera_frame.h:114
void setZoomsOnPivotPoint(bool enabled)
Sets the value of zoomsOnPivotPoint().
Definition manipulated_camera_frame.h:120
virtual void action_turn(float angle_radian, Camera *camera)
Turns the frame around the camera's Y axis.
Definition manipulated_camera_frame.cpp:244
void action_translate(int mouse_x, int mouse_y, int mouse_dx, int mouse_dy, Camera *camera, ScreenAxis axis) override
Translates the frame based on mouse movement.
Definition manipulated_camera_frame.cpp:117
ManipulatedFrame()
Default constructor.
ScreenAxis
ScreenAxis constrains rotation or translation around/along the axis.
Definition manipulated_frame.h:164
The built-in Easy3D viewer.
Definition viewer.h:63
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44