Unofficial OpenGL Software Development Kit: C:/Projects/distro/glsdk_0_5_1/glutil/include/glutil/MousePoles.h Source File

Unofficial OpenGL Software Development Kit 0.5.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MousePoles.h
Go to the documentation of this file.
1
2 #ifndef MOUSE_POLES_UTIL_H
3 #define MOUSE_POLES_UTIL_H
4
10 #include <glm/glm.hpp>
11 #include <glm/gtc/quaternion.hpp>
12
13 namespace glutil
14 {
17
19 class ViewProvider
20 {
21 public:
22 virtual ~ViewProvider() {}
23
25 virtual glm::mat4 CalcMatrix() const = 0;
26 };
27
29 enum MouseButtons
30 {
31 MB_LEFT_BTN = 1,
32 MB_MIDDLE_BTN,
33 MB_RIGHT_BTN,
34 };
35
37 enum MouseModifiers
38 {
39 MM_KEY_SHIFT = 0x01,
40 MM_KEY_CTRL = 0x02,
41 MM_KEY_ALT = 0x04,
42 };
43
45 struct ObjectData
46 {
47 glm::vec3 position;
48 glm::fquat orientation;
49 };
50
84 class ObjectPole
85 {
86 public:
96 ObjectPole(const ObjectData &initialData, float rotateScale,
97 MouseButtons actionButton, const ViewProvider *pLookatProvider);
98
100 glm::mat4 CalcMatrix() const;
101
108 void SetRotationScale(float rotateScale);
110 float GetRotationScale() const {return m_rotateScale;}
111
113 const ObjectData &GetPosOrient() const {return m_po;}
114
116 void Reset();
117
124
125
134 void MouseClick(MouseButtons button, bool isPressed, int modifiers,
135 const glm::ivec2 &position);
136
138 void MouseMove(const glm::ivec2 &position);
139
147 void MouseWheel(int direction, int modifiers, const glm::ivec2 &position);
148
154 void CharPress(char key);
156
158 bool IsDragging() const {return m_bIsDragging;}
159
160 private:
161 enum Axis
162 {
163 AXIS_X,
164 AXIS_Y,
165 AXIS_Z,
166
167 NUM_AXES,
168 };
169
170 enum RotateMode
171 {
172 RM_DUAL_AXIS,
173 RM_BIAXIAL,
174 RM_SPIN,
175 };
176
177 void RotateWorldDegrees(const glm::fquat &rot, bool bFromInitial = false);
178 void RotateLocalDegrees(const glm::fquat &rot, bool bFromInitial = false);
179 void RotateViewDegrees(const glm::fquat &rot, bool bFromInitial = false);
180
181 const ViewProvider *m_pView;
182 ObjectData m_po;
183 ObjectData m_initialPo;
184
185 float m_rotateScale;
186 MouseButtons m_actionButton;
187
188 //Used when rotating.
189 RotateMode m_RotateMode;
190 bool m_bIsDragging;
191
192 glm::ivec2 m_prevMousePos;
193 glm::ivec2 m_startDragMousePos;
194 glm::fquat m_startDragOrient;
195 };
196
198 struct ViewData
199 {
200 glm::vec3 targetPos;
201 glm::fquat orient;
202 float radius;
203 float degSpinRotation;
204 };
205
207 struct ViewScale
208 {
209 float minRadius;
210 float maxRadius;
211 float largeRadiusDelta;
212 float smallRadiusDelta;
213 float largePosOffset;
214 float smallPosOffset;
215 float rotationScale;
216 };
217
245 class ViewPole : public ViewProvider
246 {
247 public:
256 ViewPole(const ViewData &initialView, const ViewScale &viewScale,
257 MouseButtons actionButton = MB_LEFT_BTN, bool bRightKeyboardCtrls = false);
258 virtual ~ViewPole() {}
259
261 glm::mat4 CalcMatrix() const;
262
269 void SetRotationScale(float rotateScale);
270
272 float GetRotationScale() const {return m_viewScale.rotationScale;}
273
275 const ViewData &GetView() const {return m_currView;}
276
278 void Reset();
279
286
287 void MouseClick(MouseButtons button, bool isPressed, int modifiers, const glm::ivec2 &position);
288 void MouseMove(const glm::ivec2 &position);
289 void MouseWheel(int direction, int modifiers, const glm::ivec2 &position);
290 void CharPress(char key);
292
294 bool IsDragging() const {return m_bIsDragging;}
295
296 private:
297 enum TargetOffsetDir
298 {
299 DIR_UP,
300 DIR_DOWN,
301 DIR_FORWARD,
302 DIR_BACKWARD,
303 DIR_RIGHT,
304 DIR_LEFT,
305 };
306
307 void OffsetTargetPos(TargetOffsetDir eDir, float worldDistance);
308 void OffsetTargetPos(const glm::vec3 &cameraOffset);
309
310 enum RotateMode
311 {
312 RM_DUAL_AXIS_ROTATE,
313 RM_BIAXIAL_ROTATE,
314 RM_XZ_AXIS_ROTATE,
315 RM_Y_AXIS_ROTATE,
316 RM_SPIN_VIEW_AXIS,
317 };
318
319 ViewData m_currView;
320 ViewScale m_viewScale;
321
322 ViewData m_initialView;
323 MouseButtons m_actionButton;
324 bool m_bRightKeyboardCtrls;
325
326 //Used when rotating.
327 bool m_bIsDragging;
328 RotateMode m_RotateMode;
329
330 float m_degStarDragSpin;
331 glm::ivec2 m_startDragMouseLoc;
332 glm::fquat m_startDragOrient;
333
334 void ProcessXChange(int iXDiff, bool bClearY = false);
335 void ProcessYChange(int iYDiff, bool bClearXZ = false);
336 void ProcessXYChange(int iXDiff, int iYDiff);
337 void ProcessSpinAxis(int iXDiff, int iYDiff);
338
339 void BeginDragRotate(const glm::ivec2 &ptStart, RotateMode rotMode = RM_DUAL_AXIS_ROTATE);
340 void OnDragRotate(const glm::ivec2 &ptCurr);
341 void EndDragRotate(const glm::ivec2 &ptEnd, bool bKeepResults = true);
342
343 void MoveCloser(bool bLargeStep = true);
344 void MoveAway(bool bLargeStep = true);
345 };
347 }
348
349
350
351 #endif //MOUSE_POLES_UTIL_H