-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenGLNavigationWidget.h
125 lines (107 loc) · 5.39 KB
/
OpenGLNavigationWidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/***************************************************************************
* OpenGL Navigation Widget *
* Copyright (C) 2010 by Tobias Müller *
* Tobias_Mueller@twam.info *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _OPENGLNAVIGATIONWIDGET_H_
#define _OPENGLNAVIGATIONWIDGET_H_
#include <QGLWidget>
#include <QMouseEvent>
#include <QWheelEvent>
#include "Vector.h"
#include "Matrix.h"
class OpenGLNavigationWidget : public QGLWidget
{
Q_OBJECT
public:
OpenGLNavigationWidget(QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
OpenGLNavigationWidget(QGLContext* context, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
OpenGLNavigationWidget(const QGLFormat& format, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
~OpenGLNavigationWidget();
// setter
void setCameraDefaultPosition(const Vector<GLdouble, 3> &);
void setCameraDefaultLookAt(const Vector<GLdouble, 3> &);
void setCameraDefaultUp(const Vector<GLdouble, 3> &);
void setCameraPosition(const Vector<GLdouble, 3> &);
void setCameraLookAt(const Vector<GLdouble, 3> &);
void setCameraUp(const Vector<GLdouble, 3> &);
inline void setNormalMoveFactor(double c) { normalMoveFactor = c; }
inline void setFastMoveFactor(double c) { fastMoveFactor = c; }
inline void setNormalRotationFactor(double c) { normalRotateFactor = c; }
inline void setFastRotationFactor(double c) { fastRotateFactor = c; }
inline void setNormalZoomFactor(double c) { normalZoomFactor = c; }
inline void setFastZoomFactor(double c) { fastZoomFactor = c; }
// getter
inline const Vector<GLdouble ,3>& getCameraDefaultPosition() const { return cameraDefaultPosition; }
inline const Vector<GLdouble ,3>& getCameraDefaultLookAt() const { return cameraDefaultLookAt; }
inline const Vector<GLdouble ,3>& getCameraDefaultUp() const { return cameraDefaultUp; }
inline const Vector<GLdouble ,3>& getCameraPosition() const { return cameraPosition; }
inline const Vector<GLdouble ,3>& getCameraLookAt() const { return cameraLookAt; }
inline const Vector<GLdouble ,3>& getCameraUp() const { return cameraUp; }
inline double getNormalMoveFactor() const { return normalMoveFactor; }
inline double getFastMoveFactor() const { return fastMoveFactor; }
inline double getNormalRotationFactor() const { return normalRotateFactor; }
inline double getFastRotationFactor() const { return fastRotateFactor; }
inline double getNormalZoomFactor() const { return normalZoomFactor; }
inline double getFastZoomFactor() const { return fastZoomFactor; }
void resetCamera();
void setupCamera();
protected:
/// position of last mouse drag
QPoint lastDragPosition;
/// camera default position
Vector<GLdouble, 3> cameraDefaultPosition;
/// camera default target
Vector<GLdouble, 3> cameraDefaultLookAt;
/// camera default up vector
Vector<GLdouble, 3> cameraDefaultUp;
/// camera position
Vector<GLdouble, 3> cameraPosition;
/// camera target
Vector<GLdouble, 3> cameraLookAt;
/// camera up vector (direction which will be upwards on the screen), must be normalized
Vector<GLdouble, 3> cameraUp;
/// camera side vector (direction which will be sidewards on the screen), must be normalized
Vector<GLdouble, 3> cameraSide;
/// camera forward vector (direction which will be in camera direction), must be normalized
Vector<GLdouble, 3> cameraForward;
/// factor for normal moving
double normalMoveFactor;
/// factor for fast moving (ctrl pressed)
double fastMoveFactor;
/// factor for normal rotating
double normalRotateFactor;
/// factor for fast rotating
double fastRotateFactor;
/// factor for normal zooming
double normalZoomFactor;
/// factor for fast zooming (ctrl pressed)
double fastZoomFactor;
/// rotation matrix
Matrix<GLdouble, 4 , 4> cameraRotationMatrix;
void updateCameraBasis();
void updateCameraRotationMatrix();
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
private:
void initialize();
signals:
void cameraUpdated();
};
#endif