Commit 817406f3 authored by Oliver Bock's avatar Oliver Bock

Just to be on the safe side

* Use double precision
* No explicit float literals
parent 5761d7ec
......@@ -20,12 +20,12 @@
#include "pulsaranimationwidget.h"
const float PulsarAnimationWidget::deg2rad = PI/180.0f;
const double PulsarAnimationWidget::deg2rad = PI/180.0;
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers), parent),
m_frameTimer(),
m_pulseProfile(360, 0.0f)
m_pulseProfile(360, 0.0)
{
if(!format().directRendering()) {
qWarning("Sorry, no direct rendering support for animation...");
......@@ -62,20 +62,20 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
// initial render timing settings
m_framesPerSecond = 25;
m_pulsarRotationDelta = 0.0f;
m_orbitRotationDelta = 0.0f;
m_pulsarRotationDelta = 0.0;
m_orbitRotationDelta = 0.0;
resetParameters();
// initial binary system parameters (have to match GUI!)
m_pulsarMass = 1.4f;
m_pulsarMass = 1.4;
// initial companion is "Neutron Star"
m_companionMass = 1.4f;
m_pulsarSpinAxisInclination = 0.0f;
m_pulsarMagneticAxisInclination = 45.0f;
m_pulsarSemiMajorAxis = 5.0f;
m_companionMass = 1.4;
m_pulsarSpinAxisInclination = 0.0;
m_pulsarMagneticAxisInclination = 45.0;
m_pulsarSemiMajorAxis = 5.0;
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
// initial spin frequency of 0.5 Hz
m_pulsarRotationDelta = (360.0f * 0.5f) / m_framesPerSecond;
m_pulsarRotationDelta = (360.0 * 0.5) / m_framesPerSecond;
// update orbital period (based on settings above)
updateOrbitPeriod();
......@@ -85,10 +85,10 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
m_cameraInteraction = false;
// initial view settings
m_mouseAngleH = 90.0f;
m_mouseAngleV = 30.0f;
m_cameraZoom = 15.0f;
m_cameraZoomLBound = 2.0f;
m_mouseAngleH = 90.0;
m_mouseAngleV = 30.0;
m_cameraZoom = 15.0;
m_cameraZoomLBound = 2.0;
m_mouseLastX = 0;
m_mouseLastY = 0;
......@@ -117,18 +117,18 @@ PulsarAnimationWidget::~PulsarAnimationWidget()
void PulsarAnimationWidget::initializeGL()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(1.0f);
glClearDepth(1.0);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
GLfloat LightAmbient[] = { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[] = { 0.0f, 0.0f, 3.0f, 1.0f };
GLfloat spot_direction[] = { 0.0, 0.0, -1.0 };
GLfloat LightAmbient[] = {0.3, 0.3, 0.3, 1.0};
GLfloat LightDiffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat LightSpecular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat LightPosition[] = {0.0, 0.0, 3.0, 1.0};
GLfloat spot_direction[] = {0.0, 0.0, -1.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
......@@ -184,7 +184,7 @@ void PulsarAnimationWidget::resizeGL(int w, int h)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)w / (GLfloat)h, 0.1f, 500.0f);
gluPerspective(45.0, (GLfloat)w / (GLfloat)h, 0.1, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
......@@ -202,11 +202,11 @@ void PulsarAnimationWidget::paintGL()
0.0, 1.0, 0.0);
// TODO: should be located elsewhere
static GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
static GLfloat mat_diffuse[] = { 0.5, 0.5, 0.5, 1.0 };
static GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
static GLfloat low_shininess[] = { 2.5 };
static GLfloat translucent[] = { 1.0, 1.0, 1.0, 0.33 };
static GLfloat no_mat[] = {0.0, 0.0, 0.0, 1.0};
static GLfloat mat_diffuse[] = {0.5, 0.5, 0.5, 1.0};
static GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
static GLfloat low_shininess[] = {2.5};
static GLfloat translucent[] = {1.0, 1.0, 1.0, 0.33};
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
......@@ -216,29 +216,29 @@ void PulsarAnimationWidget::paintGL()
// draw companion
glPushMatrix();
glTranslatef(sin((m_orbitRotationAngle + 180.0f) * deg2rad) * m_companionSemiMajorAxis,
0.0f,
cos((m_orbitRotationAngle + 180.0f) * deg2rad) * m_companionSemiMajorAxis);
gluSphere(m_quadricCompanion, 1.0f, 32, 32);
glTranslatef(sin((m_orbitRotationAngle + 180.0) * deg2rad) * m_companionSemiMajorAxis,
0.0,
cos((m_orbitRotationAngle + 180.0) * deg2rad) * m_companionSemiMajorAxis);
gluSphere(m_quadricCompanion, 1.0, 32, 32);
glPopMatrix();
// draw pulsar
glPushMatrix();
glTranslatef(sin(m_orbitRotationAngle * deg2rad) * m_pulsarSemiMajorAxis,
0.0f,
0.0,
cos(m_orbitRotationAngle * deg2rad) * m_pulsarSemiMajorAxis);
glPushMatrix();
glRotatef(m_pulsarSpinAxisInclination, 0.0f, 0.0f, 1.0f);
glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f);
glRotatef(m_pulsarSpinAxisInclination, 0.0, 0.0, 1.0);
glRotatef(m_pulsarRotationAngle, 0.0, 1.0, 0.0);
// draw spin axis
if(m_showRotationAxes) {
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, translucent);
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -5.0f);
gluCylinder(m_quadricPulsarSpinAxis, 0.05f, 0.05f, 10.0f, 32, 1);
glRotatef(90.0, 1.0, 0.0, 0.0);
glTranslatef(0.0, 0.0, -5.0);
gluCylinder(m_quadricPulsarSpinAxis, 0.05, 0.05, 10.0, 32, 1);
glPopMatrix();
}
......@@ -250,7 +250,7 @@ void PulsarAnimationWidget::paintGL()
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
gluSphere(m_quadricPulsar, 1.0f, 32, 32);
gluSphere(m_quadricPulsar, 1.0, 32, 32);
// disable texturing
glDisable(GL_TEXTURE_GEN_S);
......@@ -259,49 +259,49 @@ void PulsarAnimationWidget::paintGL()
glPopMatrix();
// TODO: should be located elsewhere
static GLfloat coneAmbient[] = { 1.0, 1.0, 0.0, 1.0 };
static GLfloat coneDiffuse[] = { 1.0, 1.0, 0.0, 1.0 };
static GLfloat coneSpecular[] = { 1.0, 1.0, 0.5, 1.0 };
static GLfloat coneAmbient[] = {1.0, 1.0, 0.0, 1.0};
static GLfloat coneDiffuse[] = {1.0, 1.0, 0.0, 1.0};
static GLfloat coneSpecular[] = {1.0, 1.0, 0.5, 1.0};
glMaterialfv(GL_FRONT, GL_SPECULAR, coneSpecular);
// first cone
glPushMatrix();
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(m_pulsarSpinAxisInclination, 0.0f, 1.0f, 0.0f);
glRotatef(90.0, 1.0, 0.0, 0.0);
glRotatef(m_pulsarSpinAxisInclination, 0.0, 1.0, 0.0);
glRotatef(-m_pulsarRotationAngle - 90.0f, 0.0f, 0.0f, 1.0f);
glRotatef(-m_pulsarMagneticAxisInclination, 1.0f, 0.0f, 0.0f);
glRotatef(-m_pulsarRotationAngle - 90.0, 0.0, 0.0, 1.0);
glRotatef(-m_pulsarMagneticAxisInclination, 1.0, 0.0, 0.0);
// draw magnetic axis (for both cones)
if(m_showRotationAxes) {
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, translucent);
glTranslatef(0.0f, 0.0f, -5.0f);
gluCylinder(m_quadricPulsarMagneticAxis, 0.05f, 0.05f, 10.0f, 32, 1);
glTranslatef(0.0, 0.0, -5.0);
gluCylinder(m_quadricPulsarMagneticAxis, 0.05, 0.05, 10.0, 32, 1);
glPopMatrix();
}
glTranslatef(0.0f, 0.0f, -4.0f);
glTranslatef(0.0, 0.0, -4.0);
glMaterialfv(GL_FRONT, GL_AMBIENT, coneAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, coneDiffuse);
gluCylinder(m_quadricPulsarCone1, 0.475f, 0.0f, 3.0f, 32, 32);
gluCylinder(m_quadricPulsarCone1, 0.475, 0.0, 3.0, 32, 32);
glPopMatrix();
// second cone
glPushMatrix();
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(-m_pulsarSpinAxisInclination, 0.0f, 1.0f, 0.0f);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glRotatef(-m_pulsarSpinAxisInclination, 0.0, 1.0, 0.0);
glRotatef(m_pulsarRotationAngle - 90.0f, 0.0f, 0.0f, 1.0f);
glRotatef(m_pulsarMagneticAxisInclination, 1.0f, 0.0f, 0.0f);
glRotatef(m_pulsarRotationAngle - 90.0, 0.0, 0.0, 1.0);
glRotatef(m_pulsarMagneticAxisInclination, 1.0, 0.0, 0.0);
glTranslatef(0.0f, 0.0f, -4.0f);
glTranslatef(0.0, 0.0, -4.0);
glMaterialfv(GL_FRONT, GL_AMBIENT, coneAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, coneDiffuse);
gluCylinder(m_quadricPulsarCone2, 0.475f, 0.0f, 3.0f, 32, 32);
gluCylinder(m_quadricPulsarCone2, 0.475, 0.0, 3.0, 32, 32);
glPopMatrix();
glPopMatrix();
......@@ -309,15 +309,15 @@ void PulsarAnimationWidget::paintGL()
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width(), 0, height(), 0.1f, 501.0f);
glOrtho(0, width(), 0, height(), 0.1, 501.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// draw backdrop (independent parallel projection)
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_specular);
glTranslatef(0.0f, 0.0f, -501.0f);
drawTexture(QPointF(0.0f, 0.0f), m_backgroundTexture);
glTranslatef(0.0, 0.0, -501.0);
drawTexture(QPointF(0.0, 0.0), m_backgroundTexture);
// restore original state
glMatrixMode(GL_PROJECTION);
......@@ -329,18 +329,18 @@ void PulsarAnimationWidget::paintGL()
if(m_cameraInteraction || m_showOrbits) {
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, translucent);
static float sizeOffset = 0.25f;
static double sizeOffset = 0.25;
// companion's plane (only if not identical with pulsar's)
if(m_companionSemiMajorAxis != m_pulsarSemiMajorAxis) {
glPushMatrix();
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(90.0, 1.0, 0.0, 0.0);
// separate them slightly in case of overlap
// based on ugly mass diff check (no collision detection)
// single known problematic pair: (m_c=1.4, m_p=1.5)
if((int)(10*(m_pulsarMass-m_companionMass)+0.5f) == 1){
glTranslatef(0.0f, 0.0f, 0.01f);
if((int)(10*(m_pulsarMass-m_companionMass)+0.5) == 1){
glTranslatef(0.0, 0.0, 0.01);
}
gluDisk(m_quadricCompanionOrbitPlane,
......@@ -352,7 +352,7 @@ void PulsarAnimationWidget::paintGL()
// pulsar's plane
glPushMatrix();
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(90.0, 1.0, 0.0, 0.0);
gluDisk(m_quadricPulsarOrbitPlane,
m_pulsarSemiMajorAxis - sizeOffset,
m_pulsarSemiMajorAxis + sizeOffset,
......@@ -363,7 +363,7 @@ void PulsarAnimationWidget::paintGL()
void PulsarAnimationWidget::runAnimation()
{
m_frameTimer.start(1000.0f / m_framesPerSecond);
m_frameTimer.start(1000.0 / m_framesPerSecond);
}
void PulsarAnimationWidget::pauseAnimation()
......@@ -382,13 +382,13 @@ void PulsarAnimationWidget::stopAnimation()
void PulsarAnimationWidget::updateFrame()
{
m_pulsarRotationAngle += m_pulsarRotationDelta;
if(m_pulsarRotationAngle > 360.0f) {
m_pulsarRotationAngle -= 360.0f;
if(m_pulsarRotationAngle > 360.0) {
m_pulsarRotationAngle -= 360.0;
updatePulseProfile();
}
m_orbitRotationAngle += m_orbitRotationDelta;
if(m_orbitRotationAngle > 360.0f) {
m_orbitRotationAngle -= 360.0f;
if(m_orbitRotationAngle > 360.0) {
m_orbitRotationAngle -= 360.0;
}
updateGL();
......@@ -423,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()) * 0.5f ;
m_mouseAngleH -= (m_mouseLastX - event->x()) * 0.5 ;
m_mouseAngleH = m_mouseAngleH < 360 ? m_mouseAngleH : 0;
}
if(m_mouseLastY != 0) {
m_mouseAngleV -= (m_mouseLastY - event->y()) * 0.5f;
m_mouseAngleV -= (m_mouseLastY - event->y()) * 0.5;
m_mouseAngleV = m_mouseAngleV < 90 ? m_mouseAngleV : 90;
m_mouseAngleV = m_mouseAngleV > -90 ? m_mouseAngleV : -90;
}
......@@ -438,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()) * 0.5f;
m_cameraZoom -= (m_mouseLastY - event->y()) * 0.5;
m_cameraZoom = m_cameraZoom >= m_cameraZoomLBound ? m_cameraZoom : m_cameraZoomLBound;
updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom);
}
......@@ -459,7 +459,7 @@ void PulsarAnimationWidget::mouseReleaseEvent(QMouseEvent *event)
updateGL();
}
void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int angleV, const float zoom)
void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int angleV, const double zoom)
{
m_cameraPosX = sin(angleH * deg2rad) * zoom;
m_cameraPosY = sin(angleV * deg2rad) * zoom;
......@@ -475,7 +475,7 @@ void PulsarAnimationWidget::setFramePerSecond(const unsigned int fps)
m_framesPerSecond = fps;
}
void PulsarAnimationWidget::setPulsarSemiMajorAxis(const float length)
void PulsarAnimationWidget::setPulsarSemiMajorAxis(const double length)
{
m_pulsarSemiMajorAxis = length;
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
......@@ -485,7 +485,7 @@ void PulsarAnimationWidget::setPulsarSemiMajorAxis(const float length)
updateGL();
}
void PulsarAnimationWidget::setCompanionMass(const float mass)
void PulsarAnimationWidget::setCompanionMass(const double mass)
{
m_companionMass = mass;
updateOrbitRadii();
......@@ -494,7 +494,7 @@ void PulsarAnimationWidget::setCompanionMass(const float mass)
updateGL();
}
void PulsarAnimationWidget::setPulsarMass(const float mass)
void PulsarAnimationWidget::setPulsarMass(const double mass)
{
m_pulsarMass = mass;
updateOrbitRadii();
......@@ -503,9 +503,9 @@ void PulsarAnimationWidget::setPulsarMass(const float mass)
updateGL();
}
void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency)
void PulsarAnimationWidget::setPulsarSpinFrequency(const double frequency)
{
m_pulsarRotationDelta = (360.0f * frequency) / m_framesPerSecond;
m_pulsarRotationDelta = (360.0 * frequency) / m_framesPerSecond;
updatePulseProfile();
}
......@@ -528,8 +528,8 @@ void PulsarAnimationWidget::setPulsarMagneticAxisInclination(const int degrees)
void PulsarAnimationWidget::updateOrbitPeriod()
{
m_orbitalPeriod = 3.1553e7 * sqrt(
(pow(m_pulsarSemiMajorAxis, 3.0f) * pow(m_pulsarMass+m_companionMass, 2.0f)) /
pow(m_companionMass, 3.0f)
(pow(m_pulsarSemiMajorAxis, 3.0) * pow(m_pulsarMass+m_companionMass, 2.0)) /
pow(m_companionMass, 3.0)
);
// visual correction factor (increase orbital momentum)
......@@ -541,9 +541,9 @@ void PulsarAnimationWidget::updateOrbitPeriod()
void PulsarAnimationWidget::updateOrbitRadii()
{
m_pulsarSemiMajorAxis = 1.0015e-5 * pow(
(pow(m_orbitalPeriod, 2.0f) * pow(m_companionMass, 3.0f)) /
pow(m_pulsarMass+m_companionMass, 2.0f),
1.0f/3.0f
(pow(m_orbitalPeriod, 2.0) * pow(m_companionMass, 3.0)) /
pow(m_pulsarMass+m_companionMass, 2.0),
1.0/3.0
);
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
......@@ -553,8 +553,8 @@ void PulsarAnimationWidget::updateOrbitRadii()
void PulsarAnimationWidget::resetParameters()
{
m_pulsarRotationAngle = 0.0f;
m_orbitRotationAngle = 0.0f;
m_pulsarRotationAngle = 0.0;
m_orbitRotationAngle = 0.0;
emit pulsarAnimationReset();
}
......@@ -571,8 +571,8 @@ void PulsarAnimationWidget::updatePulseProfile()
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 cam = pow(xk, 2.0) + pow(yk, 2.0) + pow(zk, 2.0);
const double alpha = deg2rad * (90.0 - m_mouseAngleH);
const double delta = deg2rad * m_mouseAngleV;
const double gaussProfile = 0.012337;
......@@ -587,11 +587,8 @@ void PulsarAnimationWidget::updatePulseProfile()
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.0 * (1.0 - fabs(a/b)) / gaussProfile);
// store amplitude
m_pulseProfile[x] = (float) amp;
// determine and store pulse amplitude
m_pulseProfile[x] = exp(-2.0 * (1.0 - fabs(a/b)) / gaussProfile);
}
// propagate new profile
......
......@@ -39,12 +39,12 @@ public:
virtual ~PulsarAnimationWidget();
void setFramePerSecond(const unsigned int fps);
void setCompanionMass(const float mass);
void setPulsarMass(const float mass);
void setPulsarSpinFrequency(const float frequency);
void setCompanionMass(const double mass);
void setPulsarMass(const double mass);
void setPulsarSpinFrequency(const double frequency);
void setPulsarSpinAxisInclination(const int degrees);
void setPulsarMagneticAxisInclination(const int degrees);
void setPulsarSemiMajorAxis(const float length);
void setPulsarSemiMajorAxis(const double length);
public slots:
void runAnimation();
......@@ -58,8 +58,8 @@ public slots:
signals:
void pulsarSemiMajorAxisUpdated(double value);
void pulseProfileUpdated(const QVector<float>& data);
void pulsarAnimationStep(float stepSize);
void pulseProfileUpdated(const QVector<double>& data);
void pulsarAnimationStep(double stepSize);
void pulsarAnimationReset();
private:
......@@ -73,7 +73,7 @@ private:
void updateOrbitPeriod();
void updateOrbitRadii();
void updateCameraPosition(const int angleH, const int angleV, const float zoom);
void updateCameraPosition(const int angleH, const int angleV, const double zoom);
void resetParameters();
void updatePulseProfile();
......@@ -93,16 +93,16 @@ private:
int m_framesPerSecond;
float m_pulsarRotationAngle;
float m_pulsarRotationDelta;
double m_pulsarRotationAngle;
double m_pulsarRotationDelta;
double m_orbitalPeriod;
float m_orbitRotationAngle;
float m_orbitRotationDelta;
double m_orbitRotationAngle;
double m_orbitRotationDelta;
float m_pulsarMass;
double m_pulsarMass;
double m_pulsarSemiMajorAxis;
float m_companionMass;
double m_companionMass;
double m_companionSemiMajorAxis;
int m_pulsarSpinAxisInclination;
......@@ -116,15 +116,15 @@ private:
int m_mouseLastY;
int m_mouseAngleH;
int m_mouseAngleV;
float m_cameraZoom;
float m_cameraZoomLBound;
float m_cameraPosX;
float m_cameraPosY;
float m_cameraPosZ;
double m_cameraZoom;
double m_cameraZoomLBound;
double m_cameraPosX;
double m_cameraPosY;
double m_cameraPosZ;
QVector<float> m_pulseProfile;
QVector<double> m_pulseProfile;
static const float deg2rad;
static const double deg2rad;
};
#endif /* PULSARANIMATIONWIDGET_H_ */
......@@ -72,14 +72,14 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
connect(ui.pulsarGlWidget, SIGNAL(pulsarSemiMajorAxisUpdated(double)),
this, SLOT(updatePulsarSemiMajorAxisValue(double)));
connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationStep(float)),
ui.pulseScopeWidget, SLOT(markerStep(float)), Qt::DirectConnection);
connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationStep(double)),
ui.pulseScopeWidget, SLOT(markerStep(double)), Qt::DirectConnection);
connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationReset()),
ui.pulseScopeWidget, SLOT(markerReset()));
connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const QVector<float>&)),
ui.pulseScopeWidget, SLOT(drawCurve(const QVector<float>&)), Qt::DirectConnection);
connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const QVector<double>&)),
ui.pulseScopeWidget, SLOT(drawCurve(const QVector<double>&)), Qt::DirectConnection);
}
PulsatingScience::~PulsatingScience()
......@@ -151,37 +151,37 @@ void PulsatingScience::on_pushStop_clicked()
void PulsatingScience::on_radioCompanionWD_toggled(bool checked)
{
if(checked) {
ui.pulsarGlWidget->setCompanionMass(0.6f);
ui.lcdCompanionMass->display(QString::number(0.6f, 'f', 1));
ui.pulsarGlWidget->setCompanionMass(0.6);
ui.lcdCompanionMass->display(QString::number(0.6, '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));
ui.pulsarGlWidget->setCompanionMass(1.0);
ui.lcdCompanionMass->display(QString::number(1.0, '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));
ui.pulsarGlWidget->setCompanionMass(1.4);
ui.lcdCompanionMass->display(QString::number(1.4, '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));
ui.pulsarGlWidget->setPulsarMass(value * 0.1);
ui.lcdPulsarMass->display(QString::number(value * 0.1, 'f', 1));
}
void PulsatingScience::on_sliderPulsarSpinFrequency_valueChanged(int value)
{
ui.pulsarGlWidget->setPulsarSpinFrequency(value * 0.1f);
ui.lcdPulsarSpinFrequency->display(QString::number(value * 0.1f, 'f', 1));
ui.pulsarGlWidget->setPulsarSpinFrequency(value * 0.1);
ui.lcdPulsarSpinFrequency->display(QString::number(value * 0.1, 'f', 1));
}
void PulsatingScience::on_sliderPulsarSpinAxisInclination_valueChanged(int value)
......@@ -198,8 +198,8 @@ void PulsatingScience::on_sliderPulsarMagneticAxisInclination_valueChanged(int v
void PulsatingScience::on_sliderPulsarSemiMajorAxis_valueChanged(int value)
{
ui.pulsarGlWidget->setPulsarSemiMajorAxis(value * 0.001f);
ui.lcdPulsarSemiMajorAxis->display(QString::number(value * 0.001f, 'f', 1));
ui.pulsarGlWidget->setPulsarSemiMajorAxis(value * 0.001);
ui.lcdPulsarSemiMajorAxis->display(QString::number(value * 0.001, 'f', 1));
ui.lcdPulsarSemiMajorAxis->setStyleSheet("color: black");
}
......
......@@ -42,16 +42,16 @@ PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent),
qWarning("Sorry, no multisampling support for pulse scope...");
}
m_scopeSizeH = 360.0f;
m_scopeSizeV = 1.0f;
m_scopeSizeH = 360.0;
m_scopeSizeV = 1.0;
m_path = NULL;
m_marker = m_scene.addLine(0.0f, 0.0f, 0.0f, m_scopeSizeV, QPen(Qt::red));
m_marker = m_scene.addLine(0.0, 0.0, 0.0, m_scopeSizeV, QPen(Qt::red));
m_marker->setZValue(1);
setScene(&m_scene);
m_data.fill(0.0f, m_scopeSizeH);
m_data.fill(0.0, m_scopeSizeH);
drawCurve(m_data);
}
......@@ -67,11 +67,11 @@ void PulseScopeWidget::resizeEvent(QResizeEvent *event)
fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
}
void PulseScopeWidget::drawCurve(const QVector<float>& vector)
void PulseScopeWidget::drawCurve(const QVector<double>& vector)
{
m_data = vector;
QPainterPath pulsePath(QPoint(0.0f, m_scopeSizeV));
QPainterPath pulsePath(QPoint(0.0, m_scopeSizeV));
for(int i = 0; i < m_scopeSizeH; ++i) {
pulsePath.lineTo(i, m_scopeSizeV - m_data.at(i));
}
......@@ -83,12 +83,12 @@ void PulseScopeWidget::drawCurve(const QVector<float>& vector)
}
}
void PulseScopeWidget::markerStep(float stepSize) {
static float x = 0.0f;
void PulseScopeWidget::markerStep(double stepSize) {
static double x = 0.0;
if(x < m_scopeSizeH) {
x += stepSize;
m_marker->setLine(x, 0.0f, x, m_scopeSizeV);
m_marker->setLine(x, 0.0, x, m_scopeSizeV);
}
else {
x -= m_scopeSizeH;
......@@ -96,5 +96,5 @@ void PulseScopeWidget::markerStep(float stepSize) {
}
void PulseScopeWidget::markerReset() {
m_marker->setLine(0.0f, 0.0f, 0.0f, m_scopeSizeV);
m_marker->setLine(0.0, 0.0, 0.0, m_scopeSizeV);
}
......@@ -41,18 +41,18 @@ public:
void resizeEvent(QResizeEvent *event);
public slots:
void drawCurve(const QVector<float>& vector);
void markerStep(float stepSize);
void drawCurve(const QVector<double>& vector);
void markerStep(double stepSize);
void markerReset();
private:
QGraphicsScene m_scene;
QVector<float> m_data;
QVector<double> m_data;
QGraphicsPathItem *m_path;
QGraphicsLineItem *m_marker;
float m_scopeSizeH;
float m_scopeSizeV;
double m_scopeSizeH;
double m_scopeSizeV;
};
#endif /* PULSESCOPEWIDGET_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