Commit 003b56a2 authored by Oliver Bock's avatar Oliver Bock

Fixed pulse profile computation

* Using fixed initializations instead of GUI values (required for consistency)
* Added missing initializations
* Fixed coordinate system and angle transformations (GUI vs. physics)
* Fixed trigonometry blunder (deg vs. rad)
* Also: optimized camera updates
* Also: more comments
* Pending: marker increasingly out of sync (over time)
parent 17d265bf
......@@ -43,8 +43,10 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
qWarning("Sorry, no multisampling support for animation...");
}
// connect primary rendering timer to local callback
connect(&m_frameTimer, SIGNAL(timeout()), this, SLOT(updateFrame()));
// initialize quadric pointers
m_quadricCompanionOrbitPlane = NULL;
m_quadricCompanion = NULL;
m_quadricPulsarOrbitPlane = NULL;
......@@ -54,29 +56,46 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
m_quadricPulsarSpinAxis = NULL;
m_quadricPulsarMagneticAxis = NULL;
// initialize texture pointers
m_pulsarTexture = 0;
m_backgroundTexture = 0;
// initial render timing settings
m_framesPerSecond = 25;
m_pulsarRotationDelta = 0.0f;
m_orbitRotationDelta = 0.0f;
resetParameters();
// initial binary system parameters (have to match GUI!)
m_pulsarMass = 1.4f;
// initial companion is "Neutron Star"
m_companionMass = 1.4f;
m_pulsarSpinAxisInclination = 0.0f;
m_pulsarMagneticAxisInclination = 45.0f;
m_pulsarSemiMajorAxis = 5.0f;
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
// initial spin frequency of 0.5 Hz
m_pulsarRotationDelta = (360.0f * 0.5f) / m_framesPerSecond;
// update orbital period (based on settings above)
updateOrbitPeriod();
// initial view features
m_showOrbits = false;
m_showRotationAxes = false;
m_cameraInteraction = false;
m_mouseLastX = 0;
m_mouseLastY = 0;
// initial view settings
m_mouseAngleH = 90.0f;
m_mouseAngleV = 30.0f;
m_cameraZoom = 15.0f;
m_cameraZoomLBound = 2.0f;
m_mouseLastX = 0;
m_mouseLastY = 0;
// update camera based on settings above
updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom);
// finally, create initial pulse profile based on settings above
updatePulseProfile();
}
......@@ -197,9 +216,9 @@ void PulsarAnimationWidget::paintGL()
// draw companion
glPushMatrix();
glTranslatef(sin((m_orbitRotationAngle + 180) * deg2rad) * m_companionSemiMajorAxis,
glTranslatef(sin((m_orbitRotationAngle + 180.0f) * deg2rad) * m_companionSemiMajorAxis,
0.0f,
cos((m_orbitRotationAngle + 180) * deg2rad) * m_companionSemiMajorAxis);
cos((m_orbitRotationAngle + 180.0f) * deg2rad) * m_companionSemiMajorAxis);
gluSphere(m_quadricCompanion, 1.0f, 32, 32);
glPopMatrix();
......@@ -404,12 +423,12 @@ void PulsarAnimationWidget::mouseMoveEvent(QMouseEvent *event)
Qt::MouseButtons buttons = event->buttons();
if((buttons & Qt::LeftButton) == Qt::LeftButton) {
if(m_mouseLastX != 0) {
m_mouseAngleH -= (m_mouseLastX - event->x()) / 2;
m_mouseAngleH -= (m_mouseLastX - event->x()) * 0.5f ;
m_mouseAngleH = m_mouseAngleH < 360 ? m_mouseAngleH : 0;
}
if(m_mouseLastY != 0) {
m_mouseAngleV -= (m_mouseLastY - event->y()) / 2;
m_mouseAngleV -= (m_mouseLastY - event->y()) * 0.5f;
m_mouseAngleV = m_mouseAngleV < 90 ? m_mouseAngleV : 90;
m_mouseAngleV = m_mouseAngleV > -90 ? m_mouseAngleV : -90;
}
......@@ -419,7 +438,7 @@ void PulsarAnimationWidget::mouseMoveEvent(QMouseEvent *event)
}
else if((buttons & Qt::RightButton) == Qt::RightButton) {
if(m_mouseLastY != 0) {
m_cameraZoom -= (m_mouseLastY - event->y()) / 2;
m_cameraZoom -= (m_mouseLastY - event->y()) * 0.5f;
m_cameraZoom = m_cameraZoom >= m_cameraZoomLBound ? m_cameraZoom : m_cameraZoomLBound;
updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom);
}
......@@ -444,7 +463,7 @@ void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int ang
{
m_cameraPosX = sin(angleH * deg2rad) * zoom;
m_cameraPosY = sin(angleV * deg2rad) * zoom;
m_cameraPosZ = cos(angleH * deg2rad) * cos(fabs(angleV * deg2rad)) * zoom;
m_cameraPosZ = cos(angleH * deg2rad) * cos(angleV * deg2rad) * zoom;
updatePulseProfile();
......@@ -501,6 +520,7 @@ void PulsarAnimationWidget::setPulsarSpinAxisInclination(const int degrees)
void PulsarAnimationWidget::setPulsarMagneticAxisInclination(const int degrees)
{
m_pulsarMagneticAxisInclination = degrees;
updatePulseProfile();
updateGL();
}
......@@ -508,8 +528,8 @@ void PulsarAnimationWidget::setPulsarMagneticAxisInclination(const int degrees)
void PulsarAnimationWidget::updateOrbitPeriod()
{
m_orbitalPeriod = 3.1553e7 * sqrt(
(pow(m_pulsarSemiMajorAxis,3) * pow(m_pulsarMass+m_companionMass,2)) /
pow(m_companionMass,3)
(pow(m_pulsarSemiMajorAxis, 3.0f) * pow(m_pulsarMass+m_companionMass, 2.0f)) /
pow(m_companionMass, 3.0f)
);
// visual correction factor (increase orbital momentum)
......@@ -521,9 +541,9 @@ void PulsarAnimationWidget::updateOrbitPeriod()
void PulsarAnimationWidget::updateOrbitRadii()
{
m_pulsarSemiMajorAxis = 1.0015e-5 * pow(
(pow(m_orbitalPeriod,2) * pow(m_companionMass,3)) /
pow(m_pulsarMass+m_companionMass,2),
1.0/3.0
(pow(m_orbitalPeriod, 2.0f) * pow(m_companionMass, 3.0f)) /
pow(m_pulsarMass+m_companionMass, 2.0f),
1.0f/3.0f
);
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
......@@ -541,32 +561,34 @@ void PulsarAnimationWidget::resetParameters()
void PulsarAnimationWidget::updatePulseProfile()
{
const double i = m_pulsarSpinAxisInclination;
const double y = m_pulsarMagneticAxisInclination;
const double deltaPhiOrb = m_orbitRotationDelta;
const double deltaPhiRot = m_pulsarRotationDelta;
const double rp = m_pulsarSemiMajorAxis;
const double xk = m_cameraPosZ;
const double yk = -m_cameraPosX;
const double zk = -m_cameraPosY;
const double cam = pow(xk,2) + pow(yk,2) + pow(zk,2);
const double alpha = -m_mouseAngleH;
const double delta = m_mouseAngleV;
const double gaussProfile = 0.012337;
// prepare parameters (e.g. convert to radians where necessary)
const double i = deg2rad * m_pulsarSpinAxisInclination;
const double y = deg2rad * m_pulsarMagneticAxisInclination;
double phiOrb = deg2rad * m_orbitRotationAngle;
const double deltaPhiRot = deg2rad * 1.0;
const double deltaPhiOrb = deg2rad * deltaPhiRot * m_orbitRotationDelta / m_pulsarRotationDelta;
const double rp = m_pulsarSemiMajorAxis;
const double xk = -m_cameraPosZ;
const double yk = -m_cameraPosX;
const double zk = m_cameraPosY;
const double cam = pow(xk, 2.0f) + pow(yk, 2.0f) + pow(zk, 2.0f);
const double alpha = deg2rad * (90.0f - m_mouseAngleH);
const double delta = deg2rad * m_mouseAngleV;
const double gaussProfile = 0.012337;
for(int x = 0; x < 360; ++x) {
// determine angle between pulsar's magnetic axis and line of sight
const double phiOrb = x * deltaPhiOrb;
phiOrb += deltaPhiOrb;
const double phiRot = x * deltaPhiRot;
double a = -sin(y) * sin(phiRot) * (xk + rp * cos(phiOrb)) \
+ (cos(i) * sin(y) * cos(phiRot) + sin(i) * cos(y)) * (yk + rp * sin(phiOrb)) \
- (sin(i) * sin(y) * cos(phiRot) - cos(i) * cos(y)) * zk;
double b = sqrt(pow(rp,2) + cam - 2 * sqrt(cam) * rp * cos(delta) * sin(alpha + phiOrb));
double b = sqrt(pow(rp,2.0) + cam - (2.0 * sqrt(cam) * rp * cos(delta) * sin(alpha + phiOrb)));
// determine pulse amplitude
double amp = exp(-2 * (1 - fabs(a/b)) / gaussProfile);
double amp = exp(-2.0 * (1.0 - fabs(a/b)) / gaussProfile);
// store amplitude
m_pulseProfile[x] = (float) amp;
......
......@@ -80,16 +80,6 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const QVector<float>&)),
ui.pulseScopeWidget, SLOT(drawCurve(const QVector<float>&)));
// initialize animation parameters (using GUI settings)
on_sliderPulsarSemiMajorAxis_valueChanged(ui.sliderPulsarSemiMajorAxis->value());
on_radioCompanionNS_toggled(true);
on_sliderPulsarMass_valueChanged(ui.sliderPulsarMass->value());
on_sliderPulsarSpinFrequency_valueChanged(ui.sliderPulsarSpinFrequency->value());
on_sliderPulsarSpinAxisInclination_valueChanged(ui.sliderPulsarSpinAxisInclination->value());
on_sliderPulsarMagneticAxisInclination_valueChanged(ui.sliderPulsarMagneticAxisInclination->value());
}
PulsatingScience::~PulsatingScience()
......
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