pulsaranimationwidget.h 4.02 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 float mass);
	void setPulsarMass(const float mass);
	void setPulsarSpinFrequency(const float frequency);
45
	void setPulsarSpinAxisInclination(const int degrees);
46
	void setPulsarMagneticAxisInclination(const int degrees);
Oliver Bock's avatar
Oliver Bock committed
47
	void setPulsarSemiMajorAxis(const float 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);
61
	void pulseProfileUpdated(const QVector<float>& data);
Oliver Bock's avatar
Oliver Bock committed
62
63
	void pulsarAnimationStep(float stepSize);
	void pulsarAnimationReset();
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
73
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

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

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

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

91
	GLuint m_pulsarTexture;
92
	GLuint m_backgroundTexture;
93

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

Oliver Bock's avatar
Oliver Bock committed
96
	float m_pulsarRotationAngle;
Oliver Bock's avatar
Oliver Bock committed
97
	float m_pulsarRotationDelta;
98

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

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

108
	int m_pulsarSpinAxisInclination;
109
110
	int m_pulsarMagneticAxisInclination;

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

115
116
117
118
119
120
121
122
123
	int m_mouseLastX;
	int m_mouseLastY;
	int m_mouseAngleH;
	int m_mouseAngleV;
	float m_cameraZoom;
	float m_cameraZoomLBound;
	float m_cameraPosX;
	float m_cameraPosY;
	float m_cameraPosZ;
124

125
126
	QVector<float> m_pulseProfile;

127
	static const float deg2rad;
Oliver Bock's avatar
Oliver Bock committed
128
129
130
};

#endif /* PULSARANIMATIONWIDGET_H_ */