pulsaranimationwidget.h 4.24 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
class PulsarAnimationWidget : public QGLWidget
{
36
    Q_OBJECT
Oliver Bock's avatar
Oliver Bock committed
37
38

public:
39
40
    PulsarAnimationWidget(QWidget *parent);
    virtual ~PulsarAnimationWidget();
Oliver Bock's avatar
Oliver Bock committed
41

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

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

55
    void updateFrame();
Oliver Bock's avatar
Oliver Bock committed
56

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

Oliver Bock's avatar
Oliver Bock committed
60
signals:
61
62
63
    void pulsarSemiMajorAxisUpdated(double value);
    void pulseProfileUpdated(const QVector<double>& data);
    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

75
    void updateOrbitPeriod();
Oliver Bock's avatar
Oliver Bock committed
76
    void updateOrbitRadii();
Oliver Bock's avatar
Oliver Bock committed
77
    void updateCameraPosition(const double angleH, const double 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;
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
    GLUquadricObj *m_quadricPulsar;
    GLUquadricObj *m_quadricPulsarCone1;
    GLUquadricObj *m_quadricPulsarCone2;
    GLUquadricObj *m_quadricPulsarSpinAxis;
    GLUquadricObj *m_quadricPulsarMagneticAxis;

    GLuint m_backgroundTexture;

    int m_framesPerSecond;

    double m_pulsarRotationAngle;
    double m_pulsarRotationDelta;

    double m_orbitalPeriod;
    double m_orbitRotationAngle;
    double m_orbitRotationDelta;

    double m_pulsarMass;
    double m_pulsarSemiMajorAxis;
    double m_companionMass;
    double m_companionSemiMajorAxis;

    double m_pulsarSpinAxisInclination;
    double m_pulsarMagneticAxisInclination;

    bool m_showOrbits;
    bool m_showRotationAxes;
    bool m_cameraInteraction;

    int m_mouseLastX;
    int m_mouseLastY;
    double m_mouseAngleH;
    double m_mouseAngleV;
    double m_cameraZoom;
    double m_cameraZoomLBound;
    double m_cameraZoomUBound;
    double m_cameraPosX;
    double m_cameraPosY;
    double m_cameraPosZ;

    QVector<double> m_pulseProfile;

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

#endif /* PULSARANIMATIONWIDGET_H_ */