pulsaranimationwidget.h 4.53 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);
49
    void setPulsarBeamAngle(const int degrees);
Oliver Bock's avatar
Oliver Bock committed
50

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

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

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

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

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

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

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

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

Oliver Bock's avatar
Oliver Bock committed
84 85
    GLUquadricObj *m_quadricCompanionOrbitPlane;
    GLUquadricObj *m_quadricCompanion;
86
    GLUquadricObj *m_quadricPulsarOrbitPlane;
87
    GLUquadricObj *m_quadricPulsar;
88 89
    GLUquadricObj *m_quadricPulsarCone1Shell;
    GLUquadricObj *m_quadricPulsarCone2Shell;
90
    GLUquadricObj *m_quadricPulsarSpinAxis;
91 92
    GLUquadricObj *m_quadricPulsarSpinAxisTop1;
    GLUquadricObj *m_quadricPulsarSpinAxisTop2;
93 94 95
    GLUquadricObj *m_quadricPulsarMagneticAxis;

    GLuint m_backgroundTexture;
96
    GLuint m_beamTexture;
97 98 99 100 101 102 103 104 105 106

    int m_framesPerSecond;

    double m_pulsarRotationAngle;
    double m_pulsarRotationDelta;

    double m_orbitalPeriod;
    double m_orbitRotationAngle;
    double m_orbitRotationDelta;

Oliver Bock's avatar
Oliver Bock committed
107 108 109 110
    double m_pulsarRadius;
    double m_pulsarBeamLength;
    double m_pulsarBeamAngle;
    double m_pulsarBeamOuterRadius;
111 112 113 114
    double m_pulsarMass;
    double m_pulsarSemiMajorAxis;
    double m_pulsarSpinAxisInclination;
    double m_pulsarMagneticAxisInclination;
Oliver Bock's avatar
Oliver Bock committed
115 116
    double m_companionMass;
    double m_companionSemiMajorAxis;
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

    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
136 137 138
};

#endif /* PULSARANIMATIONWIDGET_H_ */