Commit cfe9b979 authored by Oliver Bock's avatar Oliver Bock

Aligned and synchronized axes with inclinations and pulsar rotation (incl. texture)

parent be74ad45
......@@ -43,8 +43,7 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
m_quadricPulsarCone1 = NULL;
m_quadricPulsarCone2 = NULL;
m_quadricPulsarSpinAxis = NULL;
m_quadricPulsarMagneticAxis1 = NULL;
m_quadricPulsarMagneticAxis2 = NULL;
m_quadricPulsarMagneticAxis = NULL;
m_pulsarTexture = 0;
m_backgroundTexture = 0;
......@@ -71,8 +70,7 @@ PulsarAnimationWidget::~PulsarAnimationWidget()
if(m_quadricPulsarCone1) gluDeleteQuadric(m_quadricPulsarCone1);
if(m_quadricPulsarCone2) gluDeleteQuadric(m_quadricPulsarCone2);
if(m_quadricPulsarSpinAxis) gluDeleteQuadric(m_quadricPulsarSpinAxis);
if(m_quadricPulsarMagneticAxis1) gluDeleteQuadric(m_quadricPulsarMagneticAxis1);
if(m_quadricPulsarMagneticAxis2) gluDeleteQuadric(m_quadricPulsarMagneticAxis2);
if(m_quadricPulsarMagneticAxis) gluDeleteQuadric(m_quadricPulsarMagneticAxis);
if(m_pulsarTexture) deleteTexture(m_pulsarTexture);
if(m_backgroundTexture) deleteTexture(m_backgroundTexture);
......@@ -114,16 +112,14 @@ void PulsarAnimationWidget::initializeGL()
m_quadricPulsarCone1 = gluNewQuadric();
m_quadricPulsarCone2 = gluNewQuadric();
m_quadricPulsarSpinAxis = gluNewQuadric();
m_quadricPulsarMagneticAxis1 = gluNewQuadric();
m_quadricPulsarMagneticAxis2 = gluNewQuadric();
m_quadricPulsarMagneticAxis = gluNewQuadric();
gluQuadricNormals(m_quadricPulsarOrbitPlane, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsar, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarCone1, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarCone2, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarSpinAxis, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarMagneticAxis1, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarMagneticAxis2, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarMagneticAxis, GLU_SMOOTH);
// load textures
m_pulsarTexture = bindTexture(QImage(":/textures/resources/texture_pulsar.png"), GL_TEXTURE_2D, GL_RGBA);
......@@ -175,6 +171,7 @@ void PulsarAnimationWidget::paintGL()
glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
// draw companion
glPushMatrix();
glTranslatef(sin((m_orbitRotationAngle + 180) * deg2rad) * m_companionOrbitRadius,
0.0f,
......@@ -182,36 +179,37 @@ void PulsarAnimationWidget::paintGL()
gluSphere(m_quadricPulsar, 1.0f, 32, 32);
glPopMatrix();
// draw pulsar
glPushMatrix();
glTranslatef(sin(m_orbitRotationAngle * deg2rad) * m_pulsarOrbitRadius,
0.0f,
cos(m_orbitRotationAngle * deg2rad) * m_pulsarOrbitRadius);
glPushMatrix();
// enable texture coordinates and bind texture
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glBindTexture(GL_TEXTURE_2D, m_pulsarTexture);
glRotatef(m_pulsarSpinAxisInclination, 0.0f, 0.0f, 1.0f);
glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f);
// draw spin axis
if(m_cameraInteraction) {
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, translucent);
glRotatef(90.0, 1.0f, 0.0f, 0.0f);
glRotatef(-m_pulsarSpinAxisInclination, 0.0f, 1.0f, 0.0f);
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);
glPopMatrix();
}
glRotatef(m_pulsarRotationAngle, 0.0f, 1.0f, 0.0f);
glRotatef(m_pulsarSpinAxisInclination, 1.0f, 0.0f, 0.0f);
// create texture coordinates and enable texturing
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glBindTexture(GL_TEXTURE_2D, m_pulsarTexture);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
gluSphere(m_quadricPulsar, 1.0f, 32, 32);
// disable texture coordinates
// disable texturing
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_2D);
......@@ -224,13 +222,21 @@ void PulsarAnimationWidget::paintGL()
glMaterialfv(GL_FRONT, GL_SPECULAR, coneSpecular);
// first cone
glPushMatrix();
glRotatef(m_pulsarRotationAngle - 90.0f, 0.0f, 1.0f, 0.0f);
glRotatef(-m_pulsarMagneticAxisInclination - m_pulsarSpinAxisInclination + 90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(m_pulsarSpinAxisInclination, 0.0f, 1.0f, 0.0f);
glRotatef(-m_pulsarRotationAngle - 90.0f, 0.0f, 0.0f, 1.0f);
glRotatef(-m_pulsarMagneticAxisInclination, 1.0f, 0.0f, 0.0f);
// draw magnetic axis (for both cones)
if(m_cameraInteraction) {
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, translucent);
gluCylinder(m_quadricPulsarMagneticAxis1, 0.05f, 0.05f, 5.0f, 32, 1);
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);
glPopMatrix();
}
glTranslatef(0.0f, 0.0f, -4.0f);
......@@ -240,14 +246,13 @@ void PulsarAnimationWidget::paintGL()
gluCylinder(m_quadricPulsarCone1, 0.5f, 0.0f, 3.0f, 32, 32);
glPopMatrix();
// second cone
glPushMatrix();
glRotatef(m_pulsarRotationAngle + 90.0f, 0.0f, 1.0f, 0.0f);
glRotatef(m_pulsarMagneticAxisInclination + m_pulsarSpinAxisInclination - 90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(-m_pulsarSpinAxisInclination, 0.0f, 1.0f, 0.0f);
if(m_cameraInteraction) {
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, translucent);
gluCylinder(m_quadricPulsarMagneticAxis2, 0.05f, 0.05f, 5.0f, 32, 1);
}
glRotatef(m_pulsarRotationAngle - 90.0f, 0.0f, 0.0f, 1.0f);
glRotatef(m_pulsarMagneticAxisInclination, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -4.0f);
......@@ -257,6 +262,7 @@ void PulsarAnimationWidget::paintGL()
glPopMatrix();
glPopMatrix();
// draw orbital plane
if(m_cameraInteraction) {
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, translucent);
......
......@@ -71,8 +71,7 @@ protected:
GLUquadricObj *m_quadricPulsarCone1;
GLUquadricObj *m_quadricPulsarCone2;
GLUquadricObj *m_quadricPulsarSpinAxis;
GLUquadricObj *m_quadricPulsarMagneticAxis1;
GLUquadricObj *m_quadricPulsarMagneticAxis2;
GLUquadricObj *m_quadricPulsarMagneticAxis;
GLuint m_pulsarTexture;
GLuint m_backgroundTexture;
......
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