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 @@
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(parent),
m_frameTimer(),
m_pulsarSpinTimer()
m_pulsarSpinTimer(),
m_orbitTimer()
{
connect(&m_frameTimer, SIGNAL(timeout()), this, SLOT(updateFrame()));
connect(&m_pulsarSpinTimer, SIGNAL(timeout()), this, SLOT(updatePulsarSpin()));
connect(&m_orbitTimer, SIGNAL(timeout()), this, SLOT(updateOrbit()));
GLUquadricObj *m_quadricPulsar;
GLUquadricObj *m_quadricPulsarCone1;
GLUquadricObj *m_quadricPulsarCone2;
m_quadricPulsar = NULL;
m_quadricPulsarCone1 = NULL;
m_quadricPulsarCone2 = NULL;
m_framesPerSecond = 25;
setPulsarSpinFrequency(0.5f);
m_pulsarRotationAngle = 0.0;
m_pulsarRotationAngle = 0.0f;
setOrbitFrequency(0.25f);
setOrbitRadius(4.0f);
m_orbitRotationAngle = 0.0f;
}
PulsarAnimationWidget::~PulsarAnimationWidget()
......@@ -117,6 +124,13 @@ void PulsarAnimationWidget::paintGL()
glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
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();
glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f);
gluSphere(m_quadricPulsar, 1.0f, 32, 32);
......@@ -139,20 +153,24 @@ void PulsarAnimationWidget::runAnimation()
{
m_frameTimer.start(1000.0 / m_framesPerSecond);
m_pulsarSpinTimer.start(m_pulsarSpinFrequency);
m_orbitTimer.start(m_orbitFrequency);
}
void PulsarAnimationWidget::pauseAnimation()
{
m_frameTimer.stop();
m_pulsarSpinTimer.stop();
m_orbitTimer.stop();
}
void PulsarAnimationWidget::stopAnimation()
{
m_frameTimer.stop();
m_pulsarSpinTimer.stop();
m_orbitTimer.stop();
m_pulsarRotationAngle = 0.0;
m_orbitRotationAngle = 0.0;
updateGL();
}
......@@ -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)
{
m_framesPerSecond = fps;
......@@ -181,3 +209,14 @@ void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency)
m_pulsarSpinFrequency = (unsigned int) (1000 / (frequency * 360.0f));
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:
void setFramePerSecond(const unsigned int fps);
void setPulsarSpinFrequency(const float frequency);
void setOrbitRadius(const float radius);
void setOrbitFrequency(const float frequency);
public slots:
void runAnimation();
......@@ -42,6 +44,7 @@ public slots:
void updateFrame();
void updatePulsarSpin();
void updateOrbit();
protected:
......@@ -54,14 +57,20 @@ protected:
private:
QTimer m_frameTimer;
QTimer m_pulsarSpinTimer;
QTimer m_orbitTimer;
GLUquadricObj *m_quadricPulsar;
GLUquadricObj *m_quadricPulsarCone1;
GLUquadricObj *m_quadricPulsarCone2;
int m_framesPerSecond;
float m_pulsarSpinFrequency;
float m_pulsarRotationAngle;
float m_orbitRadius;
float m_orbitFrequency;
float m_orbitRotationAngle;
};
#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