Commit 5a0790ed authored by Oliver Bock's avatar Oliver Bock

Added orbit indicator displayed during interactive camera movement

* TODO: alpha blending doesn't seem to work
* Also: decreased camera zoom (zoom should be called distance...)
parent 4081dce8
......@@ -23,11 +23,19 @@
const float PulsarAnimationWidget::deg2rad = PI/180.0f;
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(parent),
QGLWidget(QGLFormat(QGL::AlphaChannel), parent),
m_frameTimer()
{
if(!format().rgba()) {
qWarning("Sorry, no RGBA support...");
}
if(!format().alpha()) {
qWarning("Sorry, no alpha channel support...");
}
connect(&m_frameTimer, SIGNAL(timeout()), this, SLOT(updateFrame()));
m_quadricPulsarOrbitPlane = NULL;
m_quadricPulsar = NULL;
m_quadricPulsarCone1 = NULL;
m_quadricPulsarCone2 = NULL;
......@@ -41,11 +49,12 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
m_pulsarRotationAngle = 0.0f;
m_orbitRotationAngle = 0.0f;
m_cameraInteraction = false;
m_mouseLastX = 0;
m_mouseLastY = 0;
m_mouseAngleH = 90.0f;
m_mouseAngleV = 30.f;
m_cameraZoom = 10.0f;
m_cameraZoom = 15.0f;
m_cameraZoomLBound = 2.0f;
updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom);
......@@ -53,6 +62,7 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
PulsarAnimationWidget::~PulsarAnimationWidget()
{
if(m_quadricPulsarOrbitPlane) gluDeleteQuadric(m_quadricPulsarOrbitPlane);
if(m_quadricPulsar) gluDeleteQuadric(m_quadricPulsar);
if(m_quadricPulsarCone1) gluDeleteQuadric(m_quadricPulsarCone1);
if(m_quadricPulsarCone2) gluDeleteQuadric(m_quadricPulsarCone2);
......@@ -85,9 +95,14 @@ void PulsarAnimationWidget::initializeGL()
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_quadricPulsarOrbitPlane = gluNewQuadric();
m_quadricPulsar = gluNewQuadric();
m_quadricPulsarCone1 = gluNewQuadric();
m_quadricPulsarCone2 = gluNewQuadric();
gluQuadricNormals(m_quadricPulsarOrbitPlane, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsar, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarCone1, GLU_SMOOTH);
gluQuadricNormals(m_quadricPulsarCone2, GLU_SMOOTH);
......@@ -117,6 +132,19 @@ void PulsarAnimationWidget::paintGL()
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
if(m_cameraInteraction) {
static GLfloat pulsarOrbitAmbientDiffuse[] = { 1.0, 1.0, 1.0, 0.25 };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, pulsarOrbitAmbientDiffuse);
glPushMatrix();
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
gluDisk(m_quadricPulsarOrbitPlane,
m_pulsarOrbitRadius * 0.9f,
m_pulsarOrbitRadius * 1.1f,
64, 1);
glPopMatrix();
}
// 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 };
......@@ -202,6 +230,12 @@ void PulsarAnimationWidget::updateFrame()
updateGL();
}
void PulsarAnimationWidget::mousePressEvent(QMouseEvent *event)
{
m_cameraInteraction = true;
updateGL();
}
void PulsarAnimationWidget::mouseMoveEvent(QMouseEvent *event)
{
Qt::MouseButtons buttons = event->buttons();
......@@ -237,6 +271,8 @@ void PulsarAnimationWidget::mouseReleaseEvent(QMouseEvent *event)
{
m_mouseLastX = 0;
m_mouseLastY = 0;
m_cameraInteraction = false;
updateGL();
}
void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int angleV, const float zoom)
......
......@@ -55,6 +55,7 @@ protected:
void resizeGL(int w, int h);
void paintGL();
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
......@@ -62,6 +63,7 @@ protected:
QTimer m_frameTimer;
GLUquadricObj *m_quadricPulsarOrbitPlane;
GLUquadricObj *m_quadricPulsar;
GLUquadricObj *m_quadricPulsarCone1;
GLUquadricObj *m_quadricPulsarCone2;
......@@ -77,6 +79,7 @@ protected:
float m_pulsarOrbitRadius;
float m_companionOrbitRadius;
bool m_cameraInteraction;
int m_mouseLastX;
int m_mouseLastY;
int m_mouseAngleH;
......
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