qtgl.h 4.25 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:
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
64
	static const float FAR_PLANE = 500.0f;
Sylvain Thery's avatar
Sylvain Thery committed
65 66 67 68 69 70 71 72 73

	SimpleQT* m_cbs;

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

	int m_current_button;
	int beginx;
	int beginy;
74 75
//	float curquat[4];
//	float lastquat[4];
Sylvain Thery's avatar
Sylvain Thery committed
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
	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;

	void recalcModelView();

public:
	void setParamObject(float width, float* pos);

	void initializeGL();

	void paintGL();

	void resizeGL(int width, int height);

	void mousePressEvent(QMouseEvent *event);

	void mouseReleaseEvent(QMouseEvent *event);

	void mouseMoveEvent(QMouseEvent *event);

	void keyPressEvent(QKeyEvent *event);

	void keyReleaseEvent(QKeyEvent *event);

	void wheelEvent ( QWheelEvent * event );

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

Sylvain Thery's avatar
Sylvain Thery committed
125 126 127 128 129 130 131 132
	/**
	 * 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
133
	float getFocal() { return foc; }
Sylvain Thery's avatar
Sylvain Thery committed
134

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

Sylvain Thery's avatar
Sylvain Thery committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
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
166
	float getScale() { return scalefactor / foc; }
Sylvain Thery's avatar
Sylvain Thery committed
167 168
};

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
169 170 171 172 173
} // namespace QT

} // namespace Utils

} // namespace CGoGN
Sylvain Thery's avatar
Sylvain Thery committed
174 175

#endif