Commit ba9e75c1 authored by Oliver Bock's avatar Oliver Bock
Browse files

Decoupled pulsar spin from orbital motion

parent 979152b1
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "pulsaranimationwidget.h" #include "pulsaranimationwidget.h"
const float PulsarAnimationWidget::deg2rad = PI/180.0f;
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) : PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(parent), QGLWidget(parent),
m_frameTimer() m_frameTimer()
...@@ -131,14 +133,17 @@ void PulsarAnimationWidget::paintGL() ...@@ -131,14 +133,17 @@ 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);
glRotatef(m_orbitRotationAngle, 0.0f, 1.0f, 0.0f);
glPushMatrix(); glPushMatrix();
glTranslatef(0.0f, 0.0f, m_orbitRadiusNeg); glTranslatef(sin((m_orbitRotationAngle + 180) * deg2rad) * m_companionOrbitRadius,
0.0f,
cos((m_orbitRotationAngle + 180) * deg2rad) * m_companionOrbitRadius);
gluSphere(m_quadricPulsar, 1.0f, 32, 32); gluSphere(m_quadricPulsar, 1.0f, 32, 32);
glPopMatrix(); glPopMatrix();
glTranslatef(0.0f, 0.0f, m_orbitRadius); glPushMatrix();
glTranslatef(sin(m_orbitRotationAngle * deg2rad) * m_pulsarOrbitRadius,
0.0f,
cos(m_orbitRotationAngle * deg2rad) * m_pulsarOrbitRadius);
glPushMatrix(); glPushMatrix();
glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f); glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f);
...@@ -156,6 +161,7 @@ void PulsarAnimationWidget::paintGL() ...@@ -156,6 +161,7 @@ void PulsarAnimationWidget::paintGL()
glTranslatef(0.0f, 0.0f, -4.0f); glTranslatef(0.0f, 0.0f, -4.0f);
gluCylinder(m_quadricPulsarCone2, 0.5f, 0.0f, 3.0f, 32, 32); gluCylinder(m_quadricPulsarCone2, 0.5f, 0.0f, 3.0f, 32, 32);
glPopMatrix(); glPopMatrix();
glPopMatrix();
} }
void PulsarAnimationWidget::runAnimation() void PulsarAnimationWidget::runAnimation()
...@@ -230,8 +236,6 @@ void PulsarAnimationWidget::mouseReleaseEvent(QMouseEvent *event) ...@@ -230,8 +236,6 @@ void PulsarAnimationWidget::mouseReleaseEvent(QMouseEvent *event)
void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int angleV, const float zoom) void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int angleV, const float zoom)
{ {
static const float deg2rad = PI/180.0f;
m_cameraPosX = sin(angleH * deg2rad) * zoom; m_cameraPosX = sin(angleH * deg2rad) * zoom;
m_cameraPosY = sin(angleV * deg2rad) * zoom; m_cameraPosY = sin(angleV * deg2rad) * zoom;
m_cameraPosZ = cos(angleH * deg2rad) * cos(fabs(angleV * deg2rad)) * zoom; m_cameraPosZ = cos(angleH * deg2rad) * cos(fabs(angleV * deg2rad)) * zoom;
...@@ -256,6 +260,7 @@ void PulsarAnimationWidget::setOrbitRotationDelta(const float frequency) ...@@ -256,6 +260,7 @@ void PulsarAnimationWidget::setOrbitRotationDelta(const float frequency)
void PulsarAnimationWidget::setOrbitRadius(const float radius) void PulsarAnimationWidget::setOrbitRadius(const float radius)
{ {
m_orbitRadius = radius; // for the time being both have the same orbit (mass)
m_orbitRadiusNeg = -1.0 * radius; m_pulsarOrbitRadius = radius;
m_companionOrbitRadius = radius;
} }
...@@ -70,10 +70,12 @@ protected: ...@@ -70,10 +70,12 @@ protected:
float m_pulsarRotationAngle; float m_pulsarRotationAngle;
float m_pulsarRotationDelta; float m_pulsarRotationDelta;
float m_orbitRotationAngle; float m_orbitRotationAngle;
float m_orbitRotationDelta; float m_orbitRotationDelta;
float m_orbitRadius;
float m_orbitRadiusNeg; float m_pulsarOrbitRadius;
float m_companionOrbitRadius;
int m_mouseLastX; int m_mouseLastX;
int m_mouseLastY; int m_mouseLastY;
...@@ -84,6 +86,8 @@ protected: ...@@ -84,6 +86,8 @@ protected:
float m_cameraPosX; float m_cameraPosX;
float m_cameraPosY; float m_cameraPosY;
float m_cameraPosZ; float m_cameraPosZ;
static const float deg2rad;
}; };
#endif /* PULSARANIMATIONWIDGET_H_ */ #endif /* PULSARANIMATIONWIDGET_H_ */
Supports Markdown
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