pulsaranimationwidget.h 4.1 KB
Newer Older
Oliver Bock's avatar
Oliver Bock committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/******************************************************************************
 *   Copyright (C) 2008 by Oliver Bock                                        *
 *   oliver.bock[AT]aei.mpg.de                                                *
 *                                                                            *
 *   This file is part of PulsatingScience.                                   *
 *                                                                            *
 *   PulsatingScience is free software: you can redistribute it and/or modify *
 *   it under the terms of the GNU General Public License as published        *
 *   by the Free Software Foundation, version 3 of the License.               *
 *                                                                            *
 *   PulsatingScience 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 General Public License for more details.                             *
 *                                                                            *
 *   You should have received a copy of the GNU General Public License        *
 *   along with PulsatingScience. If not, see <http://www.gnu.org/licenses/>. *
 *                                                                            *
 ******************************************************************************/

#ifndef PULSARANIMATIONWIDGET_H_
#define PULSARANIMATIONWIDGET_H_

24
25
#include <cmath>

Oliver Bock's avatar
Oliver Bock committed
26
#include <QGLWidget>
Oliver Bock's avatar
Oliver Bock committed
27
#include <QTimer>
28
#include <QMouseEvent>
Oliver Bock's avatar
Oliver Bock committed
29
#include <QDebug>
30
31

#define PI 3.14159265
Oliver Bock's avatar
Oliver Bock committed
32

33

Oliver Bock's avatar
Oliver Bock committed
34
35
36
37
38
39
40
41
class PulsarAnimationWidget : public QGLWidget
{
	Q_OBJECT

public:
	PulsarAnimationWidget(QWidget *parent);
	virtual ~PulsarAnimationWidget();

Oliver Bock's avatar
Oliver Bock committed
42
	void setFramePerSecond(const unsigned int fps);
Oliver Bock's avatar
Oliver Bock committed
43
44
45
	void setCompanionMass(const double mass);
	void setPulsarMass(const double mass);
	void setPulsarSpinFrequency(const double frequency);
46
	void setPulsarSpinAxisInclination(const int degrees);
47
	void setPulsarMagneticAxisInclination(const int degrees);
Oliver Bock's avatar
Oliver Bock committed
48
	void setPulsarSemiMajorAxis(const double length);
Oliver Bock's avatar
Oliver Bock committed
49

Oliver Bock's avatar
Oliver Bock committed
50
51
52
53
54
55
56
public slots:
	void runAnimation();
	void pauseAnimation();
	void stopAnimation();

	void updateFrame();

57
	void showOrbits(bool enabled);
Oliver Bock's avatar
Oliver Bock committed
58
59
	void showRotationAxes(bool enabled);

Oliver Bock's avatar
Oliver Bock committed
60
61
signals:
	void pulsarSemiMajorAxisUpdated(double value);
Oliver Bock's avatar
Oliver Bock committed
62
	void pulseProfileUpdated(const QVector<double>& data);
63
	void pulsarAnimationStep(double position);
Oliver Bock's avatar
Oliver Bock committed
64

65
private:
Oliver Bock's avatar
Oliver Bock committed
66
67
68
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
Oliver Bock's avatar
Oliver Bock committed
69

70
    void mousePressEvent(QMouseEvent *event);
71
72
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
Oliver Bock's avatar
Oliver Bock committed
73
    void showEvent(QShowEvent *event);
74

Oliver Bock's avatar
Oliver Bock committed
75
76
	void updateOrbitPeriod();
    void updateOrbitRadii();
Oliver Bock's avatar
Oliver Bock committed
77
    void updateCameraPosition(const int angleH, const int angleV, const double zoom);
78
    void resetParameters();
79
    void updatePulseProfile();
80

Oliver Bock's avatar
Oliver Bock committed
81
82
    QTimer m_frameTimer;

Oliver Bock's avatar
Oliver Bock committed
83
84
    GLUquadricObj *m_quadricCompanionOrbitPlane;
    GLUquadricObj *m_quadricCompanion;
85
    GLUquadricObj *m_quadricPulsarOrbitPlane;
Oliver Bock's avatar
Oliver Bock committed
86
87
88
	GLUquadricObj *m_quadricPulsar;
	GLUquadricObj *m_quadricPulsarCone1;
	GLUquadricObj *m_quadricPulsarCone2;
89
	GLUquadricObj *m_quadricPulsarSpinAxis;
90
	GLUquadricObj *m_quadricPulsarMagneticAxis;
Oliver Bock's avatar
Oliver Bock committed
91

92
	GLuint m_pulsarTexture;
93
	GLuint m_backgroundTexture;
94

Oliver Bock's avatar
Oliver Bock committed
95
	int m_framesPerSecond;
96

Oliver Bock's avatar
Oliver Bock committed
97
98
	double m_pulsarRotationAngle;
	double m_pulsarRotationDelta;
99

Oliver Bock's avatar
Oliver Bock committed
100
	double m_orbitalPeriod;
Oliver Bock's avatar
Oliver Bock committed
101
102
	double m_orbitRotationAngle;
	double m_orbitRotationDelta;
103

Oliver Bock's avatar
Oliver Bock committed
104
	double m_pulsarMass;
Oliver Bock's avatar
Oliver Bock committed
105
	double m_pulsarSemiMajorAxis;
Oliver Bock's avatar
Oliver Bock committed
106
	double m_companionMass;
Oliver Bock's avatar
Oliver Bock committed
107
	double m_companionSemiMajorAxis;
108

Oliver Bock's avatar
Oliver Bock committed
109
110
	double m_pulsarSpinAxisInclination;
	double m_pulsarMagneticAxisInclination;
111

112
	bool m_showOrbits;
Oliver Bock's avatar
Oliver Bock committed
113
	bool m_showRotationAxes;
114
	bool m_cameraInteraction;
115

116
117
	int m_mouseLastX;
	int m_mouseLastY;
Oliver Bock's avatar
Oliver Bock committed
118
119
	double m_mouseAngleH;
	double m_mouseAngleV;
Oliver Bock's avatar
Oliver Bock committed
120
121
	double m_cameraZoom;
	double m_cameraZoomLBound;
122
	double m_cameraZoomUBound;
Oliver Bock's avatar
Oliver Bock committed
123
124
125
	double m_cameraPosX;
	double m_cameraPosY;
	double m_cameraPosZ;
126

Oliver Bock's avatar
Oliver Bock committed
127
	QVector<double> m_pulseProfile;
128

Oliver Bock's avatar
Oliver Bock committed
129
	static const double deg2rad;
Oliver Bock's avatar
Oliver Bock committed
130
131
132
};

#endif /* PULSARANIMATIONWIDGET_H_ */