103 lines
2.4 KiB
C
103 lines
2.4 KiB
C
|
// CC-BY Edouard.Thiel@univ-amu.fr - 22/01/2019
|
||
|
|
||
|
#ifndef GLAREA_H
|
||
|
#define GLAREA_H
|
||
|
|
||
|
#include <QKeyEvent>
|
||
|
#include <QTimer>
|
||
|
#include <QOpenGLWidget>
|
||
|
#include <QOpenGLFunctions>
|
||
|
#include <QOpenGLShaderProgram>
|
||
|
|
||
|
#include <scene.h>
|
||
|
|
||
|
|
||
|
class GLArea : public QOpenGLWidget,
|
||
|
protected QOpenGLFunctions
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
|
explicit GLArea(QWidget *parent = 0);
|
||
|
~GLArea();
|
||
|
|
||
|
static constexpr double distance_min = 0;
|
||
|
static constexpr double distance_max = 5;
|
||
|
static constexpr double distance_step = .1;
|
||
|
|
||
|
static constexpr double focal_length_min = 0;
|
||
|
static constexpr double focal_length_max = .2;
|
||
|
static constexpr double focal_length_step = .005;
|
||
|
|
||
|
static constexpr double near_clip_min = 0;
|
||
|
static constexpr double near_clip_max = 1;
|
||
|
static constexpr double near_clip_step = .05;
|
||
|
|
||
|
static constexpr double far_clip_min = 2;
|
||
|
static constexpr double far_clip_max = 7;
|
||
|
static constexpr double far_clip_step = .1;
|
||
|
|
||
|
static constexpr double angle_min = 0;
|
||
|
static constexpr double angle_max = 360;
|
||
|
static constexpr double angle_step = 1;
|
||
|
|
||
|
double getDistance() const { return distance; }
|
||
|
double getFocalLength() const { return focal_length; }
|
||
|
double getNearClip() const { return near_clip; }
|
||
|
double getFarClip() const { return far_clip; }
|
||
|
double getAngle() const { return angle; }
|
||
|
|
||
|
|
||
|
public slots:
|
||
|
void setDistance(double d);
|
||
|
void setFocalLength(double f);
|
||
|
void setNearClip(double n);
|
||
|
void setFarClip(double f);
|
||
|
void setAngle(double a);
|
||
|
|
||
|
signals:
|
||
|
void distanceChanged(double d);
|
||
|
void focalLengthChanged(double f);
|
||
|
void nearClipChanged(double n);
|
||
|
void farClipChanged(double f);
|
||
|
void angleChanged(double a);
|
||
|
|
||
|
protected slots:
|
||
|
void onTimeout();
|
||
|
|
||
|
protected:
|
||
|
void initializeGL() override;
|
||
|
void doProjection();
|
||
|
void resizeGL(int w, int h) override;
|
||
|
void paintGL() override;
|
||
|
void keyPressEvent(QKeyEvent *ev) override;
|
||
|
void mousePressEvent(QMouseEvent *ev) override;
|
||
|
void mouseMoveEvent(QMouseEvent *ev) override;
|
||
|
void wheelEvent(QWheelEvent *ev) override;
|
||
|
|
||
|
private:
|
||
|
QTimer *timer = nullptr;
|
||
|
double anim = 0;
|
||
|
double ratio = 1;
|
||
|
|
||
|
// Pour utiliser les shaders
|
||
|
QOpenGLShaderProgram *program;
|
||
|
int posAttr;
|
||
|
int colAttr;
|
||
|
int matrix_uniform;
|
||
|
|
||
|
Scene scene;
|
||
|
|
||
|
float mouse_last[2] = {0, 0};
|
||
|
double horiz_angle = 0;
|
||
|
double vert_angle = 0;
|
||
|
|
||
|
double distance = 3;
|
||
|
double focal_length = .1;
|
||
|
double near_clip = .1;
|
||
|
double far_clip = 5;
|
||
|
double angle = 0;
|
||
|
};
|
||
|
|
||
|
#endif // GLAREA_H
|