-
Notifications
You must be signed in to change notification settings - Fork 19
/
SimulationDisplay.h
executable file
·142 lines (124 loc) · 4.25 KB
/
SimulationDisplay.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef SIMULATIONDISPLAY_H
#define SIMULATIONDISPLAY_H
#include <SimulationGL.h>
#include <Simulation.h>
#include <GuiConstants.h>
#include <QImage>
#include <TrackBallCamera.h>
class SimulationDisplay : public SimulationGL
{
Q_OBJECT
public:
SimulationDisplay(int framesPerSecond = GuiConstants::fps, QWidget *parent = 0, char const* name = 0, Simulation *sim = NULL);
~SimulationDisplay();
void initializeGL();
void resizeGL(int width, int height);
void paintGL();
void loadTexture(QString path, unsigned int i);
void drawEllipse(const Orbit* orbit, double scale, int i, int n);
Simulation* sim(void) const {return m_sim;}
QTimer* timer(void) const {return sim_Timer;}
void setSimulation(Simulation *sim);
public slots:
void simUpdateSlot(void);
protected:
void keyPressEvent(QKeyEvent *event)
{
if(sim() != NULL)
{
switch(event->key())
{
case Qt::Key_Space:
sim()->togglePlay();
break;
case Qt::Key_F:
if(sim()->speed()*1.5 > sim()->dt()/Constants::minTimeStep)
{
sim()->setSpeed(1000*sim()->dt());
QMessageBox::warning(this, "Maximum speed reached", "Warning: the simulation is running at its highest speed (1000 updates per second).<br>To make it run faster, you may increase the time step (<i>Simulation>Configure...</i>)");
}
else
sim()->setSpeed(sim()->speed()*1.5);
sim_Timer->setInterval(1000*sim()->dt()/sim()->speed());
break;
case Qt::Key_S:
if(sim()->speed()/1.5 < sim()->dt()/Constants::maxTimeStep)
{
sim()->setSpeed(sim()->dt()/Constants::maxTimeStep);
QMessageBox::warning(this, "Minimum speed reached", "Warning: the simulation is running at its lowest speed (one update every 60 seconds...do you want to fall asleep?).<br>To make it run even slower, you may decrease the time step (<i>Simulation>Configure...</i>)");
}
else
sim()->setSpeed(sim()->speed()/1.5);
sim_Timer->setInterval(1000*sim()->dt()/sim()->speed());
break;
case Qt::Key_V:
sim()->toggleVerbose();
break;
}
}
// Pass event to the parent class
SimulationGL::keyPressEvent(event);
}
void mouseMoveEvent(QMouseEvent* event)
{
if(sim() != NULL)
{
m_camera->onMouseMotion(event);
}
// Pass event to the parent class
SimulationGL::mouseMoveEvent(event);
}
void mousePressEvent(QMouseEvent* event)
{
if(sim() != NULL)
{
switch(event->button())
{
case Qt::LeftButton:
//std::cout << "Left click" << std::endl;
setCursor(QCursor(Qt::ClosedHandCursor));
m_camera->onMousePress(event);
break;
default:
break;
}
}
// Pass event to the parent class
SimulationGL::mousePressEvent(event);
}
void mouseReleaseEvent(QMouseEvent* event)
{
if(sim() != NULL)
{
switch(event->button())
{
case Qt::LeftButton:
//std::cout << "Left released" << std::endl;
setCursor(QCursor(Qt::OpenHandCursor));
m_camera->onMouseRelease(event);
break;
default:
break;
}
}
// Pass event to the parent class
SimulationGL::mouseReleaseEvent(event);
}
void wheelEvent(QWheelEvent* event)
{
if(sim() != NULL)
{
//std::cout << "Wheel !" << std::endl;
m_camera->onWheel(event);
}
// Pass event to the parent class
SimulationGL::wheelEvent(event);
}
private:
Simulation* m_sim;
QTimer* sim_Timer;
GLuint texture[3];
QString planetTexturePath;
TrackBallCamera* m_camera;
};
#endif // SIMULATIONDISPLAY_H