Radium Engine  1.5.20
Loading...
Searching...
No Matches
TrackballCameraManipulator.hpp
1#pragma once
2#include <Gui/RaGui.hpp>
3#include <Gui/Utils/KeyMappingManager.hpp>
4
5#include <Core/Asset/Camera.hpp>
6#include <Engine/Scene/CameraComponent.hpp>
7#include <Gui/Viewer/CameraManipulator.hpp>
8
9namespace Ra {
10namespace Gui {
11
14 : public CameraManipulator,
15 public KeyMappingManageable<TrackballCameraManipulator>
16{
17 Q_OBJECT
19
20 public:
22
25
28 explicit TrackballCameraManipulator( const CameraManipulator& other );
29
32
33 // KeyMappingManager::Context mappingContext();
34
35 bool handleMousePressEvent( QMouseEvent* event,
36 const Qt::MouseButtons& buttons,
37 const Qt::KeyboardModifiers& modifiers,
38 int key ) override;
39 bool handleMouseReleaseEvent( QMouseEvent* event ) override;
40 bool handleMouseMoveEvent( QMouseEvent* event,
41 const Qt::MouseButtons& buttons,
42 const Qt::KeyboardModifiers& modifiers,
43 int key ) override;
44 bool handleWheelEvent( QWheelEvent* event,
45 const Qt::MouseButtons& buttons,
46 const Qt::KeyboardModifiers& modifiers,
47 int key ) override;
48
49 bool handleKeyPressEvent( QKeyEvent* event,
50 const KeyMappingManager::KeyMappingAction& action ) override;
51
52 void toggleRotateAround();
53 void updateCamera() override;
54
58 void setTrackballRadius( Scalar rad );
59
61 Scalar getTrackballRadius() const;
62
65 const Core::Transform::ConstTranslationPart getTrackballCenter() const;
66
67 KeyMappingManager::Context mappingContext() override;
68
69 public slots:
70 void setCameraPosition( const Core::Vector3& position ) override;
71 void setCameraTarget( const Core::Vector3& target ) override;
72 void fitScene( const Core::Aabb& aabb ) override;
73
74 void resetCamera() override;
75
76 protected:
77 virtual void handleCameraRotate( Scalar dx, Scalar dy );
78 virtual void handleCameraPan( Scalar dx, Scalar dy );
79 virtual void handleCameraZoom( Scalar dx, Scalar dy );
80 virtual void handleCameraZoom( Scalar z );
81 virtual void handleCameraMoveForward( Scalar dx, Scalar dy );
82 virtual void handleCameraMoveForward( Scalar z );
83
85 void updatePhiTheta();
86
87 protected:
88 // the center of the trackball is defined by the m_referenceFrame.translation()
89
95 Scalar m_phi { 0_ra };
96 Scalar m_theta { 0_ra };
98 Scalar m_phiDir { 1_ra };
99
101 Core::Transform m_referenceFrame;
102
104 Scalar m_distFromCenter { 0_ra };
105
106 KeyMappingCallbackManager m_keyMappingCallbackManager;
107
108 private:
109 void setupKeyMappingCallbacks();
110 bool checkIntegrity( const std::string& mess ) const;
111 static void configureKeyMapping_impl();
112 void clampThetaPhi();
113 void rotateCallback( QEvent* event );
114 void panCallback( QEvent* event );
115 void moveForwardCallback( QEvent* event );
116 void zoomCallback( QEvent* event );
117 void mousePressSaveData( const QMouseEvent* mouseEvent );
118
119 protected:
121#define KeyMappingCamera \
122 KMA_VALUE( TRACKBALLCAMERA_ROTATE ) \
123 KMA_VALUE( TRACKBALLCAMERA_PAN ) \
124 KMA_VALUE( TRACKBALLCAMERA_ZOOM ) \
125 KMA_VALUE( TRACKBALLCAMERA_PROJ_MODE ) \
126 KMA_VALUE( TRACKBALLCAMERA_MOVE_FORWARD ) \
127 KMA_VALUE( CAMERA_TOGGLE_QUICK )
128
129#define KMA_VALUE( XX ) static KeyMappingManager::KeyMappingAction XX;
130 KeyMappingCamera
131#undef KMA_VALUE
132};
133
134} // namespace Gui
135} // namespace Ra
The CameraManipulator class is the generic class for camera manipulators.
This class manage a collection of binding/callback associated with a context.
KeyMappingManageable decorator to use as CRTP.
Ra::Core::Utils::Index KeyMappingAction
handle to an action
Ra::Core::Utils::Index Context
handle to a Context
A Trackball manipulator for Cameras.
Core::Transform m_referenceFrame
initial frame of the camera, centered on target, to compute angles.
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3