pulsaranimationwidget.h 4.01 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
29
30
#include <QMouseEvent>

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

32

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

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

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

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

	void updateFrame();

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

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

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

69
    void mousePressEvent(QMouseEvent *event);
70
71
72
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

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

Oliver Bock's avatar
Oliver Bock committed
79
80
    QTimer m_frameTimer;

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

90
	GLuint m_pulsarTexture;
91
	GLuint m_backgroundTexture;
92

Oliver Bock's avatar
Oliver Bock committed
93
	int m_framesPerSecond;
94

Oliver Bock's avatar
Oliver Bock committed
95
96
	double m_pulsarRotationAngle;
	double m_pulsarRotationDelta;
97

Oliver Bock's avatar
Oliver Bock committed
98
	double m_orbitalPeriod;
Oliver Bock's avatar
Oliver Bock committed
99
100
	double m_orbitRotationAngle;
	double m_orbitRotationDelta;
101

Oliver Bock's avatar
Oliver Bock committed
102
	double m_pulsarMass;
Oliver Bock's avatar
Oliver Bock committed
103
	double m_pulsarSemiMajorAxis;
Oliver Bock's avatar
Oliver Bock committed
104
	double m_companionMass;
Oliver Bock's avatar
Oliver Bock committed
105
	double m_companionSemiMajorAxis;
106

107
	int m_pulsarSpinAxisInclination;
108
109
	int m_pulsarMagneticAxisInclination;

110
	bool m_showOrbits;
Oliver Bock's avatar
Oliver Bock committed
111
	bool m_showRotationAxes;
112
	bool m_cameraInteraction;
113

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

Oliver Bock's avatar
Oliver Bock committed
124
	QVector<double> m_pulseProfile;
125

Oliver Bock's avatar
Oliver Bock committed
126
	static const double deg2rad;
Oliver Bock's avatar
Oliver Bock committed
127
128
129
};

#endif /* PULSARANIMATIONWIDGET_H_ */