Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

qtgl.h 6.42 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1
2
3
/*******************************************************************************
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
4
 * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Sylvain Thery's avatar
Sylvain Thery committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *                                                                              *
 * This library is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation; either version 2.1 of the License, or (at your     *
 * option) any later version.                                                   *
 *                                                                              *
 * This library 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 Lesser General Public License  *
 * for more details.                                                            *
 *                                                                              *
 * You should have received a copy of the GNU Lesser General Public License     *
 * along with this library; if not, write to the Free Software Foundation,      *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
 *                                                                              *
20
 * Web site: http://cgogn.unistra.fr/                                           *
Sylvain Thery's avatar
Sylvain Thery committed
21
22
23
24
25
26
27
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

#ifndef __QT_GL2__
#define __QT_GL2__

Thery Sylvain's avatar
Thery Sylvain committed
28
#include "Utils/gl_def.h"
Sylvain Thery's avatar
Sylvain Thery committed
29
30
31
32
33
34
35
36
#include <QGLWidget>
#include <QMouseEvent>
#include <QKeyEvent>
#include <iostream>
#include <stack>

#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
37
#include "Geometry/vector_gen.h"
Sylvain Thery's avatar
Sylvain Thery committed
38

Sylvain Thery's avatar
Sylvain Thery committed
39
40
41
42
43
44
45

#ifdef WIN32
#if defined CGoGN_QT_DLL_EXPORT
#define CGoGN_UTILS_API __declspec(dllexport)
#else
#define CGoGN_UTILS_API __declspec(dllimport)
#endif
Thery Sylvain's avatar
Thery Sylvain committed
46
47
#else
#define CGoGN_UTILS_API
Sylvain Thery's avatar
Sylvain Thery committed
48
49
#endif

Sylvain Thery's avatar
Sylvain Thery committed
50
51
namespace CGoGN
{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
52

Sylvain Thery's avatar
Sylvain Thery committed
53
54
namespace Utils
{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
55

Sylvain Thery's avatar
Sylvain Thery committed
56
57
58
59
60
namespace QT
{

class SimpleQT;

Sylvain Thery's avatar
Sylvain Thery committed
61
class CGoGN_UTILS_API GLWidget : public QGLWidget
Sylvain Thery's avatar
Sylvain Thery committed
62
63
64
65
66
67
68
69
70
71
72
73
74
{
	Q_OBJECT

public:
	GLWidget(SimpleQT* cbs, QWidget *parent = 0);

	~GLWidget();

    QSize minimumSizeHint() const;

    QSize sizeHint() const;

protected:
75

thery's avatar
thery committed
76
	static float FAR_PLANE;
Sylvain Thery's avatar
Sylvain Thery committed
77
78
79
80

	SimpleQT* m_cbs;

	int m_current_button;
81
	QPoint clickPoint;
Sylvain Thery's avatar
Sylvain Thery committed
82
83
84
85
86
87
88
89
90
91
92
93
94
	int beginx;
	int beginy;
	int newModel;

	int moving;
	int scaling;
	int translating;

	float scalefactor;
	float foc;

	float m_obj_sc;
	glm::vec3 m_obj_pos;
95
96
	glm::vec3 m_obj_pos_save;
	float m_obj_width;
Sylvain Thery's avatar
Sylvain Thery committed
97
98
99
100
101
102
103

	// width and height of windows
	int W;
	int H;

	int m_state_modifier;

104
105
106
	/// stack for transformation matrix
	std::stack<glm::mat4> m_stack_trf;

Pierre Kraemer's avatar
Pierre Kraemer committed
107
108
	bool allow_rotation;

109
110
111
	/**
	 * met a jour la matrice modelview
	 */
Sylvain Thery's avatar
Sylvain Thery committed
112
113
	void recalcModelView();

114
115
116
117
118
119
	/**
	 * recalcul le quaternion ainsi que le deplacement courant
	 * pour un nouveau centre de rotation
	 */
	void changeCenterOfRotation(const glm::vec3& newCenter);

Sylvain Thery's avatar
Sylvain Thery committed
120
public:
121
122
	void resetCenterOfRotation(float width, float* pos);

Sylvain Thery's avatar
Sylvain Thery committed
123
124
	void setParamObject(float width, float* pos);

Pierre Kraemer's avatar
Pierre Kraemer committed
125
126
	void setRotation(bool b);

Sylvain Thery's avatar
Sylvain Thery committed
127
128
129
130
131
132
	void initializeGL();

	void paintGL();

	void resizeGL(int width, int height);

133
134
135
136
public:
	void mousePressEvent(QMouseEvent* event);

	void mouseReleaseEvent(QMouseEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
137

138
	void mouseClickEvent(QMouseEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
139

140
141
	void mouseDoubleClickEvent(QMouseEvent* event);

142
	void mouseMoveEvent(QMouseEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
143

144
	void keyPressEvent(QKeyEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
145

146
	void keyReleaseEvent(QKeyEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
147

148
	void wheelEvent(QWheelEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
149
150
151
152
153
154
155

	bool Shift() { return m_state_modifier & Qt::ShiftModifier; }

	bool Control() { return m_state_modifier & Qt::ControlModifier; }

	bool Alt() { return m_state_modifier & Qt::AltModifier; }

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
156
	int getHeight() const { return H; }
157
	int getWidth() const { return W; }
158

Sylvain Thery's avatar
Sylvain Thery committed
159
160
161
162
163
164
165
166
	/**
	 * set the focale distance (for a screen width of 2), default value is 1
	 */
	void setFocal(float df);

	/**
	 * get the focale distance
	 */
167
168
169
170
171
172
173
	float getFocal() const { return foc; }

	/**
	 * get current state
	 */
	int getStateModifier() const { return m_state_modifier ; }
	int getCurrentButton() const { return m_current_button ; }
Sylvain Thery's avatar
Sylvain Thery committed
174

175
176
	static float getFarPlane() { return FAR_PLANE ; }

177
178
	glm::vec3& getObjPos() ;

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
179
	void modelModified() { newModel = 1; }
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
	void glMousePosition(int& x, int& y);

	/**
	 * get a ray (2 points) from a pick point in GL area
	 * @param x mouse position
	 * @param y mouse position
	 * @param rayA first computed point of ray
	 * @param rayA second computed point of ray
	 * @param radius radius on pixel for clicking precision
	 * @return the distance in modelview world corresponding to radius pixel in screen
	 */
	GLfloat getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f& rayB, int radius=4);

	/**
	 * transform a pixel distance on screen in distance in world
	 * @param pixel_width width on pixel on screen
	 * @param center reference point on world to use (defaut 0,0,0)
	 */
	float getWidthInWorld(unsigned int pixel_width, const Geom::Vec3f& center=Geom::Vec3f(0.0f,0.0f,0.0f));

	/**
	 * current transfo matrix
	 */
	const glm::mat4& transfoMatrix() const;
	glm::mat4& transfoMatrix();

	/**
	 * current modelview matrix
	 */
	const glm::mat4& modelViewMatrix() const;
	glm::mat4& modelViewMatrix();

	/**
	 * current projection matrix
	 */
	const glm::mat4& projectionMatrix() const;
	glm::mat4& projectionMatrix();


	void transfoRotate(float angle, float x, float y, float z);

	void transfoTranslate(float tx, float ty, float tz);

	void transfoScale(float sx, float sy, float sz);

	void pushTransfoMatrix();

	bool popTransfoMatrix();


Sylvain Thery's avatar
Sylvain Thery committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
protected:
	/**
	 * equivalent to old school glRotate
	 */
	void oglRotate(float angle, float x, float y, float z);

	/**
	 * equivalent to old school glTranslate
	 */
	void oglTranslate(float tx, float ty, float tz);

	/**
	 * equivalent to old school glScale
	 */
	void oglScale(float sx, float sy, float sz);

	/**
	 * get the focale distance
	 */
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
250
	float getScale() { return scalefactor / foc; }
251
252
253
254
255
256
257
258
259

	inline int pixelRatio() const
	{
		#if (QT_VERSION>>16) == 5
			return this->devicePixelRatio();
		#else
			return 1;
		#endif
	}
Sylvain Thery's avatar
Sylvain Thery committed
260
261
};

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
262
263
264
265
266
} // namespace QT

} // namespace Utils

} // namespace CGoGN
Sylvain Thery's avatar
Sylvain Thery committed
267
268

#endif