qtgl.h 4.52 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
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
/*******************************************************************************
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
 * Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
 *                                                                              *
 * 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.           *
 *                                                                              *
 * Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

#ifndef __QT_GL2__
#define __QT_GL2__

#include <GL/glew.h>
#include <QGLWidget>
#include <QMouseEvent>
#include <QKeyEvent>
#include <iostream>
#include <stack>

#include "glm/glm.hpp"
#include "glm/gtc/matrix_projection.hpp"
#include "glm/gtc/matrix_transform.hpp"

namespace CGoGN
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
41

Sylvain Thery's avatar
Sylvain Thery committed
42 43
namespace Utils
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
44

Sylvain Thery's avatar
Sylvain Thery committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
namespace QT
{

class SimpleQT;

class GLWidget : public QGLWidget
{
	Q_OBJECT

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

	~GLWidget();

    QSize minimumSizeHint() const;

    QSize sizeHint() const;

protected:
64

thery's avatar
thery committed
65
	static float FAR_PLANE;
Sylvain Thery's avatar
Sylvain Thery committed
66 67 68 69 70 71 72

	SimpleQT* m_cbs;

	// Matrix
	std::stack<glm::mat4> m_stack_mv;

	int m_current_button;
73
	QPoint clickPoint;
Sylvain Thery's avatar
Sylvain Thery committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	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;

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

	int m_state_modifier;

94 95 96
	/**
	 * met a jour la matrice modelview
	 */
Sylvain Thery's avatar
Sylvain Thery committed
97 98
	void recalcModelView();

99 100 101 102 103 104
	/**
	 * 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
105 106 107 108 109 110 111 112 113
public:
	void setParamObject(float width, float* pos);

	void initializeGL();

	void paintGL();

	void resizeGL(int width, int height);

114 115 116 117
public:
	void mousePressEvent(QMouseEvent* event);

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

119
	void mouseClickEvent(QMouseEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
120

121 122
	void mouseDoubleClickEvent(QMouseEvent* event);

123
	void mouseMoveEvent(QMouseEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
124

125
	void keyPressEvent(QKeyEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
126

127
	void keyReleaseEvent(QKeyEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
128

129
	void wheelEvent(QWheelEvent* event);
Sylvain Thery's avatar
Sylvain Thery committed
130 131 132 133 134 135 136

	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
137
	int getHeight() const { return H; }
138

Sylvain Thery's avatar
Sylvain Thery committed
139 140 141 142 143 144 145 146
	/**
	 * set the focale distance (for a screen width of 2), default value is 1
	 */
	void setFocal(float df);

	/**
	 * get the focale distance
	 */
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
147
	float getFocal() { return foc; }
Sylvain Thery's avatar
Sylvain Thery committed
148

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

Sylvain Thery's avatar
Sylvain Thery committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
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);

	/**
	 * pseudo-equivalent to old school glPushMatrix
	 */
	void oglPushModelViewMatrix();

	/**
	 * pseudo-equivalent to old school glPopMatrix
	 */
	bool oglPopModelViewMatrix();

	/**
	 * get the focale distance
	 */
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
180
	float getScale() { return scalefactor / foc; }
Sylvain Thery's avatar
Sylvain Thery committed
181 182
};

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
183 184 185 186 187
} // namespace QT

} // namespace Utils

} // namespace CGoGN
Sylvain Thery's avatar
Sylvain Thery committed
188 189

#endif