Commit d14613a8 authored by Oliver Bock's avatar Oliver Bock

Added more required features

* Added companion classes (radio buttons)
* Added pulsar mass (slider)
* Added pulsar semi major axis (slider)
* Removed orbital frequency/radius sliders (calculated from mass ratio and/or semi major axis)
* Showing separate orbital plane visuals for pulsar and companion
* Using fixed size for orbital plane visuals (gives a feeling for radii/distances)

Also:
* Extended frustum's z-far plane
* Using dedicated quadric for companion (why did it work without?)

Note:
* Semi major axis is adjusted when mass ratio is changed (via then fixed orbital period)
* Semi major axis is capped at 1 AU and 20 AU
parent 9ae07431
......@@ -38,8 +38,10 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
connect(&m_frameTimer, SIGNAL(timeout()), this, SLOT(updateFrame()));
m_quadricCompanionOrbitPlane = NULL;
m_quadricCompanion = NULL;
m_quadricPulsarOrbitPlane = NULL;
m_quadricPulsar = NULL;
m_quadricPulsar = NULL;
m_quadricPulsarCone1 = NULL;
m_quadricPulsarCone2 = NULL;
m_quadricPulsarSpinAxis = NULL;
......@@ -52,6 +54,9 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
resetParameters();
m_pulsarMass = 1.4f;
m_companionMass = 1.4f;
m_showRotationAxes = false;
m_cameraInteraction = false;
m_mouseLastX = 0;
......@@ -66,6 +71,8 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
PulsarAnimationWidget::~PulsarAnimationWidget()
{
if(m_quadricCompanionOrbitPlane) gluDeleteQuadric(m_quadricCompanionOrbitPlane);
if(m_quadricCompanion) gluDeleteQuadric(m_quadricCompanion);
if(m_quadricPulsarOrbitPlane) gluDeleteQuadric(m_quadricPulsarOrbitPlane);
if(m_quadricPulsar) gluDeleteQuadric(m_quadricPulsar);
if(m_quadricPulsarCone1) gluDeleteQuadric(m_quadricPulsarCone1);
......@@ -108,6 +115,8 @@ void PulsarAnimationWidget::initializeGL()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
m_quadricCompanionOrbitPlane = gluNewQuadric();
m_quadricCompanion = gluNewQuadric();
m_quadricPulsarOrbitPlane = gluNewQuadric();
m_quadricPulsar = gluNewQuadric();
m_quadricPulsarCone1 = gluNewQuadric();
......@@ -115,6 +124,8 @@ void PulsarAnimationWidget::initializeGL()
m_quadricPulsarSpinAxis = gluNewQuadric();
m_quadricPulsarMagneticAxis = gluNewQuadric();
gluQuadricNormals(m_quadricCompanionOrbitPlane, GLU_SMOOTH);
gluQuadricNormals(m_quadricCompanion, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarOrbitPlane, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsar, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarCone1, GLU_SMOOTH);
......@@ -142,7 +153,7 @@ void PulsarAnimationWidget::resizeGL(int w, int h)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
gluPerspective(45.0f, (GLfloat)w / (GLfloat)h, 0.1f, 500.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
......@@ -174,17 +185,17 @@ void PulsarAnimationWidget::paintGL()
// draw companion
glPushMatrix();
glTranslatef(sin((m_orbitRotationAngle + 180) * deg2rad) * m_companionOrbitRadius,
glTranslatef(sin((m_orbitRotationAngle + 180) * deg2rad) * m_companionSemiMajorAxis,
0.0f,
cos((m_orbitRotationAngle + 180) * deg2rad) * m_companionOrbitRadius);
gluSphere(m_quadricPulsar, 1.0f, 32, 32);
cos((m_orbitRotationAngle + 180) * deg2rad) * m_companionSemiMajorAxis);
gluSphere(m_quadricCompanion, 1.0f, 32, 32);
glPopMatrix();
// draw pulsar
glPushMatrix();
glTranslatef(sin(m_orbitRotationAngle * deg2rad) * m_pulsarOrbitRadius,
glTranslatef(sin(m_orbitRotationAngle * deg2rad) * m_pulsarSemiMajorAxis,
0.0f,
cos(m_orbitRotationAngle * deg2rad) * m_pulsarOrbitRadius);
cos(m_orbitRotationAngle * deg2rad) * m_pulsarSemiMajorAxis);
glPushMatrix();
glRotatef(m_pulsarSpinAxisInclination, 0.0f, 0.0f, 1.0f);
......@@ -263,15 +274,27 @@ void PulsarAnimationWidget::paintGL()
glPopMatrix();
glPopMatrix();
// draw orbital plane
// draw orbital planes
if(m_cameraInteraction) {
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, translucent);
// pulsar
glPushMatrix();
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -0.1f);
gluDisk(m_quadricPulsarOrbitPlane,
m_pulsarOrbitRadius * 0.9f,
m_pulsarOrbitRadius * 1.1f,
m_pulsarSemiMajorAxis - 0.25f,
m_pulsarSemiMajorAxis + 0.25f,
64, 1);
glPopMatrix();
// companion
glPushMatrix();
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, 0.0f);
gluDisk(m_quadricCompanionOrbitPlane,
m_companionSemiMajorAxis - 0.25f,
m_companionSemiMajorAxis + 0.25f,
64, 1);
glPopMatrix();
}
......@@ -379,21 +402,34 @@ void PulsarAnimationWidget::setFramePerSecond(const unsigned int fps)
m_framesPerSecond = fps;
}
void PulsarAnimationWidget::setPulsarRotationDelta(const float frequency)
void PulsarAnimationWidget::setPulsarSemiMajorAxis(const float length)
{
m_pulsarRotationDelta = (360.0f * frequency) / m_framesPerSecond;
m_pulsarSemiMajorAxis = length;
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
updateOrbitPeriod();
updateGL();
}
void PulsarAnimationWidget::setOrbitRotationDelta(const float frequency)
void PulsarAnimationWidget::setCompanionMass(const float mass)
{
m_orbitRotationDelta = (360.0f * frequency) / m_framesPerSecond;
m_companionMass = mass;
updateOrbitRadii();
updateGL();
}
void PulsarAnimationWidget::setOrbitRadius(const float radius)
void PulsarAnimationWidget::setPulsarMass(const float mass)
{
// for the time being both have the same orbit (mass)
m_pulsarOrbitRadius = radius;
m_companionOrbitRadius = radius;
m_pulsarMass = mass;
updateOrbitRadii();
updateGL();
}
void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency)
{
m_pulsarRotationDelta = (360.0f * frequency) / m_framesPerSecond;
}
void PulsarAnimationWidget::setPulsarSpinAxisInclination(const int degrees)
......@@ -410,6 +446,32 @@ void PulsarAnimationWidget::setPulsarMagneticAxisInclination(const int degrees)
updateGL();
}
void PulsarAnimationWidget::updateOrbitPeriod()
{
m_orbitalPeriod = 3.1553e7 * sqrt(
(pow(m_pulsarSemiMajorAxis,3) * pow(m_pulsarMass+m_companionMass,2)) /
pow(m_companionMass,3)
);
// visual correction factor (increase orbital momentum)
double visualCorrection = 1e-8;
m_orbitRotationDelta = (360.0 / (m_orbitalPeriod*visualCorrection)) / m_framesPerSecond;
}
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
);
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
emit pulsarSemiMajorAxisUpdated(m_pulsarSemiMajorAxis);
}
void PulsarAnimationWidget::resetParameters()
{
m_pulsarRotationAngle = 0.0f;
......
......@@ -38,11 +38,12 @@ public:
virtual ~PulsarAnimationWidget();
void setFramePerSecond(const unsigned int fps);
void setPulsarRotationDelta(const float frequency);
void setOrbitRotationDelta(const float frequency);
void setOrbitRadius(const float radius);
void setCompanionMass(const float mass);
void setPulsarMass(const float mass);
void setPulsarSpinFrequency(const float frequency);
void setPulsarSpinAxisInclination(const int degrees);
void setPulsarMagneticAxisInclination(const int degrees);
void setPulsarSemiMajorAxis(const float length);
public slots:
void runAnimation();
......@@ -53,6 +54,9 @@ public slots:
void showRotationAxes(bool enabled);
signals:
void pulsarSemiMajorAxisUpdated(double value);
protected:
void initializeGL();
void resizeGL(int w, int h);
......@@ -62,11 +66,15 @@ protected:
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void updateOrbitPeriod();
void updateOrbitRadii();
void updateCameraPosition(const int angleH, const int angleV, const float zoom);
void resetParameters();
QTimer m_frameTimer;
GLUquadricObj *m_quadricCompanionOrbitPlane;
GLUquadricObj *m_quadricCompanion;
GLUquadricObj *m_quadricPulsarOrbitPlane;
GLUquadricObj *m_quadricPulsar;
GLUquadricObj *m_quadricPulsarCone1;
......@@ -82,11 +90,14 @@ protected:
float m_pulsarRotationAngle;
float m_pulsarRotationDelta;
double m_orbitalPeriod;
float m_orbitRotationAngle;
float m_orbitRotationDelta;
float m_pulsarOrbitRadius;
float m_companionOrbitRadius;
float m_pulsarMass;
double m_pulsarSemiMajorAxis;
float m_companionMass;
double m_companionSemiMajorAxis;
int m_pulsarSpinAxisInclination;
int m_pulsarMagneticAxisInclination;
......
......@@ -41,11 +41,18 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
connect(ui.actionRotationAxes, SIGNAL(toggled(bool)),
ui.pulsarGlWidget, SLOT(showRotationAxes(bool)));
connect(ui.pulsarGlWidget, SIGNAL(pulsarSemiMajorAxisUpdated(double)),
this, SLOT(updatePulsarSemiMajorAxisValue(double)));
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());
on_sliderOrbitRadius_valueChanged(ui.sliderOrbitRadius->value());
on_sliderOrbitFrequency_valueChanged(ui.sliderOrbitFrequency->value());
}
PulsatingScience::~PulsatingScience()
......@@ -81,10 +88,40 @@ void PulsatingScience::on_pushStop_clicked()
ui.pushStop->setEnabled(false);
}
void PulsatingScience::on_radioCompanionWD_toggled(bool checked)
{
if(checked) {
ui.pulsarGlWidget->setCompanionMass(0.6f);
ui.lcdCompanionMass->display(QString::number(0.6f, 'f', 1));
}
}
void PulsatingScience::on_radioCompanionSun_toggled(bool checked)
{
if(checked) {
ui.pulsarGlWidget->setCompanionMass(1.0f);
ui.lcdCompanionMass->display(QString::number(1.0f, 'f', 1));
}
}
void PulsatingScience::on_radioCompanionNS_toggled(bool checked)
{
if(checked) {
ui.pulsarGlWidget->setCompanionMass(1.4f);
ui.lcdCompanionMass->display(QString::number(1.4f, 'f', 1));
}
}
void PulsatingScience::on_sliderPulsarMass_valueChanged(int value)
{
ui.pulsarGlWidget->setPulsarMass(value * 0.1f);
ui.lcdPulsarMass->display(QString::number(value * 0.1f, 'f', 1));
}
void PulsatingScience::on_sliderPulsarSpinFrequency_valueChanged(int value)
{
ui.pulsarGlWidget->setPulsarRotationDelta(value / 10.0);
ui.lcdPulsarSpinFrequency->display(QString::number(value / 10.0, 'f', 1));
ui.pulsarGlWidget->setPulsarSpinFrequency(value * 0.1f);
ui.lcdPulsarSpinFrequency->display(QString::number(value * 0.1f, 'f', 1));
}
void PulsatingScience::on_sliderPulsarSpinAxisInclination_valueChanged(int value)
......@@ -99,16 +136,10 @@ void PulsatingScience::on_sliderPulsarMagneticAxisInclination_valueChanged(int v
ui.lcdPulsarMagneticAxisInclination->display(QString::number(value));
}
void PulsatingScience::on_sliderOrbitRadius_valueChanged(int value)
void PulsatingScience::on_sliderPulsarSemiMajorAxis_valueChanged(int value)
{
ui.pulsarGlWidget->setOrbitRadius(value);
ui.lcdOrbitRadius->display(QString::number(value, 'f', 1));
}
void PulsatingScience::on_sliderOrbitFrequency_valueChanged(int value)
{
ui.pulsarGlWidget->setOrbitRotationDelta(value / 10.0);
ui.lcdOrbitFrequency->display(QString::number(value / 10.0, 'f', 1));
ui.pulsarGlWidget->setPulsarSemiMajorAxis(value * 0.001f);
ui.lcdPulsarSemiMajorAxis->display(QString::number(value * 0.001f, 'f', 1));
}
void PulsatingScience::on_actionMenu_bar_toggled(bool checked)
......@@ -130,3 +161,8 @@ void PulsatingScience::on_actionAbout_activated()
"Copyright © 2009 "
"<a href=\"http://www.aei.mpg.de\">Max-Planck-Institut f&uuml;r Gravitationsphysik</a>");
}
void PulsatingScience::updatePulsarSemiMajorAxisValue(double value)
{
ui.sliderPulsarSemiMajorAxis->setValue(value * 1000.0);
}
......@@ -39,16 +39,21 @@ public slots:
void on_pushPause_clicked();
void on_pushStop_clicked();
void on_radioCompanionWD_toggled(bool checked);
void on_radioCompanionSun_toggled(bool checked);
void on_radioCompanionNS_toggled(bool checked);
void on_sliderPulsarMass_valueChanged(int value);
void on_sliderPulsarSpinFrequency_valueChanged(int value);
void on_sliderPulsarSpinAxisInclination_valueChanged(int value);
void on_sliderPulsarMagneticAxisInclination_valueChanged(int value);
void on_sliderOrbitRadius_valueChanged(int value);
void on_sliderOrbitFrequency_valueChanged(int value);
void on_sliderPulsarSemiMajorAxis_valueChanged(int value);
void on_actionMenu_bar_toggled(bool checked);
void on_actionStatus_bar_toggled(bool checked);
void on_actionAbout_activated();
void updatePulsarSemiMajorAxisValue(double value);
private:
Ui::PulsatingScienceClass ui;
};
......
This diff is collapsed.
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