-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: camera manipulator bpa moved to its own class by deriving f…
…rom camera_manip
- Loading branch information
1 parent
b800d9a
commit 96c81a0
Showing
9 changed files
with
112 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Arrangement_on_surface_2/demo/earth/Camera_manip_rot_bpa.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
#include "Camera_manip_rot_bpa.h" | ||
|
||
|
||
Camera_manip_rot_bpa::Camera_manip_rot_bpa(Camera& camera) : | ||
Camera_manip(camera) | ||
{ | ||
} | ||
|
||
void Camera_manip_rot_bpa::mouse_press_event(QMouseEvent* e) | ||
{ | ||
// for the backprojected diff-vector method: | ||
if (m_left_mouse_button_down) | ||
{ | ||
m_camera.save_config(); | ||
} | ||
} | ||
void Camera_manip_rot_bpa::mouse_move_event(QMouseEvent* e) | ||
{ | ||
auto current_mouse_pos = QVector2D(e->position()); | ||
const auto diff = current_mouse_pos - m_last_mouse_pos; | ||
const float rotation_scale_factor = 0.1f; | ||
|
||
// ROTATION AROUND AN AXIS ORTHOGONAL TO THE BACKPROJECTED DIF-VECTOR | ||
//QVector3D p0(m_last_mouse_pos.x(), m_vp_height - m_last_mouse_pos.y(), 0); | ||
QVector3D p0(m_mouse_press_pos.x(), m_vp_height - m_mouse_press_pos.y(), 0); | ||
QVector3D p1(current_mouse_pos.x(), m_vp_height - current_mouse_pos.y(), 0); | ||
auto dp = p1 - p0; // difference vector in OpenGL window coords. | ||
QVector3D rdp(-dp.y(), dp.x(), 0); // rotate diff-vector CCW by 90-deg | ||
QVector3D rp = p0 + rdp; // r1 rotated CCW by 90 deg | ||
|
||
QMatrix4x4 model; // this is different from Sphere's model matrix!!! | ||
auto proj = m_camera.get_projection_matrix(); | ||
auto view = m_camera.get_view_matrix(); | ||
auto model_view = view * model; | ||
QRect viewport(0, 0, m_vp_width, m_vp_height); | ||
auto wp0 = p0.unproject(model_view, proj, viewport); | ||
auto wrp = rp.unproject(model_view, proj, viewport); | ||
|
||
// rotation axis & angle | ||
auto rot_axis = wrp - wp0; | ||
rot_axis.normalize(); | ||
const auto rot_angle = rotation_scale_factor * dp.length(); | ||
|
||
QMatrix4x4 rot_matrix; | ||
rot_matrix.rotate(-rot_angle, rot_axis); | ||
|
||
m_camera.rotate_from_saved_config(rot_matrix); | ||
|
||
} | ||
void Camera_manip_rot_bpa::mouse_release_event(QMouseEvent* e) | ||
{ | ||
} | ||
void Camera_manip_rot_bpa::resize(int w, int h) | ||
{ | ||
m_vp_width = w; | ||
m_vp_height = h; | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
Arrangement_on_surface_2/demo/earth/Camera_manip_rot_bpa.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
#ifndef CAMERA_MANIP_ROT_BPA_H | ||
#define CAMERA_MANIP_ROT_BPA_H | ||
|
||
#include <qevent.h> | ||
#include <qvector2d.h> | ||
|
||
#include "Camera_manip.h" | ||
|
||
|
||
class Camera_manip_rot_bpa : public Camera_manip | ||
{ | ||
public: | ||
Camera_manip_rot_bpa(Camera& camera); | ||
|
||
protected: | ||
virtual void mouse_press_event(QMouseEvent* e) override; | ||
virtual void mouse_move_event(QMouseEvent* e) override; | ||
virtual void mouse_release_event(QMouseEvent* e) override; | ||
virtual void resize(int w, int h) override; | ||
|
||
private: | ||
int m_vp_width, m_vp_height; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters