-
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: moved camera rotation-manipulator to its own class
- Loading branch information
1 parent
78cead6
commit e7db9ce
Showing
6 changed files
with
96 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include "Camera_manip_rot.h" | ||
|
||
|
||
Camera_manip_rot::Camera_manip_rot(Camera& camera) : | ||
m_camera(camera) | ||
{ | ||
} | ||
|
||
|
||
void Camera_manip_rot::set_mouse_button_pressed_flag(QMouseEvent* e, bool flag) | ||
{ | ||
switch (e->button()) | ||
{ | ||
case Qt::LeftButton: | ||
m_left_mouse_button_down = flag; | ||
break; | ||
} | ||
} | ||
void Camera_manip_rot::mousePressEvent(QMouseEvent* e) | ||
{ | ||
set_mouse_button_pressed_flag(e, true); | ||
m_mouse_press_pos = m_last_mouse_pos = QVector2D(e->position()); | ||
} | ||
void Camera_manip_rot::mouseMoveEvent(QMouseEvent* e) | ||
{ | ||
auto current_mouse_pos = QVector2D(e->position()); | ||
const auto diff = current_mouse_pos - m_last_mouse_pos; | ||
|
||
if (m_left_mouse_button_down) | ||
{ | ||
const float rotation_scale_factor = 0.1f; | ||
m_theta += rotation_scale_factor * diff.x(); | ||
m_phi += rotation_scale_factor * diff.y(); | ||
m_camera.rotate_from_init_config(-m_theta, -m_phi); | ||
} | ||
|
||
m_last_mouse_pos = current_mouse_pos; | ||
} | ||
void Camera_manip_rot::mouseReleaseEvent(QMouseEvent* e) | ||
{ | ||
set_mouse_button_pressed_flag(e, false); | ||
} | ||
|
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,33 @@ | ||
|
||
#ifndef CAMERA_MANIP_ROT_H | ||
#define CAMERA_MANIP_ROT_H | ||
|
||
#include <qevent.h> | ||
#include <qvector2d.h> | ||
|
||
#include "Camera.h" | ||
|
||
|
||
class Camera_manip_rot | ||
{ | ||
public: | ||
Camera_manip_rot(Camera& camera); | ||
|
||
void mousePressEvent(QMouseEvent* e); | ||
void mouseMoveEvent(QMouseEvent* e); | ||
void mouseReleaseEvent(QMouseEvent* e); | ||
|
||
protected: | ||
void set_mouse_button_pressed_flag(QMouseEvent* e, bool flag); | ||
|
||
private: | ||
Camera& m_camera; | ||
float m_theta = 0, m_phi = 0; | ||
|
||
bool m_left_mouse_button_down = false; | ||
QVector2D m_last_mouse_pos; | ||
QVector2D m_mouse_press_pos; | ||
}; | ||
|
||
|
||
#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
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