Commit 1263c133 authored by Oliver Bock's avatar Oliver Bock

Improved animation code

* Better efficiency (of course one timer is sufficient!)
* Less complexity, higher accuracy (just compute the actual rotations!)
parent 4ba0eaf2
......@@ -22,13 +22,9 @@
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(parent),
m_frameTimer(),
m_pulsarSpinTimer(),
m_orbitTimer()
m_frameTimer()
{
connect(&m_frameTimer, SIGNAL(timeout()), this, SLOT(updateFrame()));
connect(&m_pulsarSpinTimer, SIGNAL(timeout()), this, SLOT(updatePulsarSpin()));
connect(&m_orbitTimer, SIGNAL(timeout()), this, SLOT(updateOrbit()));
m_quadricPulsar = NULL;
m_quadricPulsarCone1 = NULL;
......@@ -36,17 +32,17 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
m_framesPerSecond = 25;
setPulsarSpinFrequency(0.5f);
m_pulsarRotationAngle = 0.0f;
setOrbitFrequency(0.2f);
setPulsarRotationDelta(0.5f);
setOrbitRotationDelta(0.2f);
setOrbitRadius(4.0f);
m_pulsarRotationAngle = 0.0f;
m_orbitRotationAngle = 0.0f;
m_mouseLastX = 0;
m_mouseLastY = 0;
m_mouseAngleH = 90;
m_mouseAngleV = 30;
m_mouseAngleH = 90.0f;
m_mouseAngleV = 30.f;
m_cameraZoom = 10.0f;
m_cameraZoomLBound = 2.0f;
......@@ -164,52 +160,35 @@ void PulsarAnimationWidget::paintGL()
void PulsarAnimationWidget::runAnimation()
{
m_frameTimer.start(1000.0 / m_framesPerSecond);
m_pulsarSpinTimer.start(m_pulsarSpinFrequency);
m_orbitTimer.start(m_orbitFrequency);
m_frameTimer.start(1000.0f / m_framesPerSecond);
}
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();
}
void PulsarAnimationWidget::updateFrame()
{
updateGL();
}
void PulsarAnimationWidget::updatePulsarSpin()
void PulsarAnimationWidget::updateFrame()
{
if(m_pulsarRotationAngle <= 360.0) {
m_pulsarRotationAngle++;
m_pulsarRotationAngle += m_pulsarRotationDelta;
if(m_pulsarRotationAngle > 360) {
m_pulsarRotationAngle = 0.0f;
}
else {
m_pulsarRotationAngle = 0.0;
m_orbitRotationAngle += m_orbitRotationDelta;
if(m_orbitRotationAngle > 360) {
m_orbitRotationAngle = 0.0f;
}
}
void PulsarAnimationWidget::updateOrbit()
{
if(m_orbitRotationAngle <= 360.0) {
m_orbitRotationAngle++;
}
else {
m_orbitRotationAngle = 0.0;
}
updateGL();
}
void PulsarAnimationWidget::mouseMoveEvent(QMouseEvent *event)
......@@ -265,20 +244,18 @@ void PulsarAnimationWidget::setFramePerSecond(const unsigned int fps)
m_framesPerSecond = fps;
}
void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency)
void PulsarAnimationWidget::setPulsarRotationDelta(const float frequency)
{
m_pulsarSpinFrequency = (unsigned int) (1000 / (frequency * 360.0f) + 0.5f);
m_pulsarSpinTimer.setInterval(m_pulsarSpinFrequency);
m_pulsarRotationDelta = (360.0f * frequency) / m_framesPerSecond;
}
void PulsarAnimationWidget::setOrbitRadius(const float radius)
void PulsarAnimationWidget::setOrbitRotationDelta(const float frequency)
{
m_orbitRadius = radius;
m_orbitRadiusNeg = -1.0 * radius;
m_orbitRotationDelta = (360.0f * frequency) / m_framesPerSecond;
}
void PulsarAnimationWidget::setOrbitFrequency(const float frequency)
void PulsarAnimationWidget::setOrbitRadius(const float radius)
{
m_orbitFrequency = (unsigned int) (1000 / (frequency * 360.0f) + 0.5f);
m_orbitTimer.setInterval(m_orbitFrequency);
m_orbitRadius = radius;
m_orbitRadiusNeg = -1.0 * radius;
}
......@@ -38,9 +38,10 @@ public:
virtual ~PulsarAnimationWidget();
void setFramePerSecond(const unsigned int fps);
void setPulsarSpinFrequency(const float frequency);
void setPulsarRotationDelta(const float frequency);
void setOrbitRotationDelta(const float frequency);
void setOrbitRadius(const float radius);
void setOrbitFrequency(const float frequency);
public slots:
void runAnimation();
......@@ -48,8 +49,6 @@ public slots:
void stopAnimation();
void updateFrame();
void updatePulsarSpin();
void updateOrbit();
protected:
void initializeGL();
......@@ -62,8 +61,6 @@ protected:
void updateCameraPosition(const int angleH, const int angleV, const float zoom);
QTimer m_frameTimer;
QTimer m_pulsarSpinTimer;
QTimer m_orbitTimer;
GLUquadricObj *m_quadricPulsar;
GLUquadricObj *m_quadricPulsarCone1;
......@@ -71,13 +68,12 @@ protected:
int m_framesPerSecond;
float m_pulsarSpinFrequency;
float m_pulsarRotationAngle;
float m_pulsarRotationDelta;
float m_orbitRotationAngle;
float m_orbitRotationDelta;
float m_orbitRadius;
float m_orbitRadiusNeg;
float m_orbitFrequency;
float m_orbitRotationAngle;
int m_mouseLastX;
int m_mouseLastY;
......
......@@ -50,7 +50,7 @@ PulsatingScience::~PulsatingScience()
void PulsatingScience::on_sliderPulsarSpinFrequency_valueChanged(int value)
{
ui.pulsarGlWidget->setPulsarSpinFrequency(value / 10.0);
ui.pulsarGlWidget->setPulsarRotationDelta(value / 10.0);
ui.lcdPulsarSpinFrequency->display(QString::number(value / 10.0, 'f', 1));
}
......@@ -62,7 +62,7 @@ void PulsatingScience::on_sliderOrbitRadius_valueChanged(int value)
void PulsatingScience::on_sliderOrbitFrequency_valueChanged(int value)
{
ui.pulsarGlWidget->setOrbitFrequency(value / 10.0);
ui.pulsarGlWidget->setOrbitRotationDelta(value / 10.0);
ui.lcdOrbitFrequency->display(QString::number(value / 10.0, 'f', 1));
}
......
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