Commit ba9e75c1 authored by Oliver Bock's avatar Oliver Bock

Decoupled pulsar spin from orbital motion

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