Commit 07513a3b authored by Oliver Bock's avatar Oliver Bock

Sent pulsar on a cricular orbit around a central companion

* Again, not to scale!
* Also: fixed quadrics pointer initialization
parent a9a05d7b
...@@ -23,18 +23,25 @@ ...@@ -23,18 +23,25 @@
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) : PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(parent), QGLWidget(parent),
m_frameTimer(), m_frameTimer(),
m_pulsarSpinTimer() m_pulsarSpinTimer(),
m_orbitTimer()
{ {
connect(&m_frameTimer, SIGNAL(timeout()), this, SLOT(updateFrame())); connect(&m_frameTimer, SIGNAL(timeout()), this, SLOT(updateFrame()));
connect(&m_pulsarSpinTimer, SIGNAL(timeout()), this, SLOT(updatePulsarSpin())); connect(&m_pulsarSpinTimer, SIGNAL(timeout()), this, SLOT(updatePulsarSpin()));
connect(&m_orbitTimer, SIGNAL(timeout()), this, SLOT(updateOrbit()));
GLUquadricObj *m_quadricPulsar; m_quadricPulsar = NULL;
GLUquadricObj *m_quadricPulsarCone1; m_quadricPulsarCone1 = NULL;
GLUquadricObj *m_quadricPulsarCone2; m_quadricPulsarCone2 = NULL;
m_framesPerSecond = 25; m_framesPerSecond = 25;
setPulsarSpinFrequency(0.5f); setPulsarSpinFrequency(0.5f);
m_pulsarRotationAngle = 0.0; m_pulsarRotationAngle = 0.0f;
setOrbitFrequency(0.25f);
setOrbitRadius(4.0f);
m_orbitRotationAngle = 0.0f;
} }
PulsarAnimationWidget::~PulsarAnimationWidget() PulsarAnimationWidget::~PulsarAnimationWidget()
...@@ -117,6 +124,13 @@ void PulsarAnimationWidget::paintGL() ...@@ -117,6 +124,13 @@ void PulsarAnimationWidget::paintGL()
glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
glPushMatrix();
gluSphere(m_quadricPulsar, 1.0f, 32, 32);
glPopMatrix();
glRotatef(m_orbitRotationAngle, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, m_orbitRadius);
glPushMatrix(); glPushMatrix();
glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f); glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f);
gluSphere(m_quadricPulsar, 1.0f, 32, 32); gluSphere(m_quadricPulsar, 1.0f, 32, 32);
...@@ -139,20 +153,24 @@ void PulsarAnimationWidget::runAnimation() ...@@ -139,20 +153,24 @@ void PulsarAnimationWidget::runAnimation()
{ {
m_frameTimer.start(1000.0 / m_framesPerSecond); m_frameTimer.start(1000.0 / m_framesPerSecond);
m_pulsarSpinTimer.start(m_pulsarSpinFrequency); m_pulsarSpinTimer.start(m_pulsarSpinFrequency);
m_orbitTimer.start(m_orbitFrequency);
} }
void PulsarAnimationWidget::pauseAnimation() void PulsarAnimationWidget::pauseAnimation()
{ {
m_frameTimer.stop(); m_frameTimer.stop();
m_pulsarSpinTimer.stop(); m_pulsarSpinTimer.stop();
m_orbitTimer.stop();
} }
void PulsarAnimationWidget::stopAnimation() void PulsarAnimationWidget::stopAnimation()
{ {
m_frameTimer.stop(); m_frameTimer.stop();
m_pulsarSpinTimer.stop(); m_pulsarSpinTimer.stop();
m_orbitTimer.stop();
m_pulsarRotationAngle = 0.0; m_pulsarRotationAngle = 0.0;
m_orbitRotationAngle = 0.0;
updateGL(); updateGL();
} }
...@@ -171,6 +189,16 @@ void PulsarAnimationWidget::updatePulsarSpin() ...@@ -171,6 +189,16 @@ void PulsarAnimationWidget::updatePulsarSpin()
} }
} }
void PulsarAnimationWidget::updateOrbit()
{
if(m_orbitRotationAngle <= 360.0) {
m_orbitRotationAngle++;
}
else {
m_orbitRotationAngle = 0.0;
}
}
void PulsarAnimationWidget::setFramePerSecond(const unsigned int fps) void PulsarAnimationWidget::setFramePerSecond(const unsigned int fps)
{ {
m_framesPerSecond = fps; m_framesPerSecond = fps;
...@@ -181,3 +209,14 @@ void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency) ...@@ -181,3 +209,14 @@ void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency)
m_pulsarSpinFrequency = (unsigned int) (1000 / (frequency * 360.0f)); m_pulsarSpinFrequency = (unsigned int) (1000 / (frequency * 360.0f));
m_pulsarSpinTimer.setInterval(m_pulsarSpinFrequency); m_pulsarSpinTimer.setInterval(m_pulsarSpinFrequency);
} }
void PulsarAnimationWidget::setOrbitRadius(const float radius)
{
m_orbitRadius = -1.0 * radius;
}
void PulsarAnimationWidget::setOrbitFrequency(const float frequency)
{
m_orbitFrequency = (unsigned int) (1000 / (frequency * 360.0f));
m_orbitTimer.setInterval(m_orbitFrequency);
}
...@@ -34,6 +34,8 @@ public: ...@@ -34,6 +34,8 @@ public:
void setFramePerSecond(const unsigned int fps); void setFramePerSecond(const unsigned int fps);
void setPulsarSpinFrequency(const float frequency); void setPulsarSpinFrequency(const float frequency);
void setOrbitRadius(const float radius);
void setOrbitFrequency(const float frequency);
public slots: public slots:
void runAnimation(); void runAnimation();
...@@ -42,6 +44,7 @@ public slots: ...@@ -42,6 +44,7 @@ public slots:
void updateFrame(); void updateFrame();
void updatePulsarSpin(); void updatePulsarSpin();
void updateOrbit();
protected: protected:
...@@ -54,14 +57,20 @@ protected: ...@@ -54,14 +57,20 @@ protected:
private: private:
QTimer m_frameTimer; QTimer m_frameTimer;
QTimer m_pulsarSpinTimer; QTimer m_pulsarSpinTimer;
QTimer m_orbitTimer;
GLUquadricObj *m_quadricPulsar; GLUquadricObj *m_quadricPulsar;
GLUquadricObj *m_quadricPulsarCone1; GLUquadricObj *m_quadricPulsarCone1;
GLUquadricObj *m_quadricPulsarCone2; GLUquadricObj *m_quadricPulsarCone2;
int m_framesPerSecond; int m_framesPerSecond;
float m_pulsarSpinFrequency; float m_pulsarSpinFrequency;
float m_pulsarRotationAngle; float m_pulsarRotationAngle;
float m_orbitRadius;
float m_orbitFrequency;
float m_orbitRotationAngle;
}; };
#endif /* PULSARANIMATIONWIDGET_H_ */ #endif /* PULSARANIMATIONWIDGET_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment