9 #include "myglwidget.h"
11 // Non-default arguments must come first
12 MyGLWidget::MyGLWidget(Axis
*pAxisX
, Axis
*pAxisY
, Axis
*pAxisZ
,
13 Camera
*pCamera
, Sphere
* pSphere
,
14 unsigned int timerInterval
, QWidget
*parent
)
17 qDebug("MyGLWidget::MyGLWidget()");
26 m_timerInterval
= timerInterval
;
28 // Worker thread populates the data pool with coordinations and angles.
29 // It automatically blocks once the pool has reached a maximum number
30 // of data and wakes up when data resource are low.
34 connect(&m_timer
, SIGNAL(timeout()), this, SLOT(pullData()));
37 MyGLWidget::~MyGLWidget()
39 qDebug("MyGLWidget::~MyGLWidget()");
42 void MyGLWidget::initializeGL()
44 qDebug("MyGLWidget::initializeGL()");
46 // Enable backface culling
47 glEnable(GL_CULL_FACE
);
49 // Clear color is set to black
50 glClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
);
51 glShadeModel(GL_SMOOTH
);
53 // Reset modelview matrix
54 glMatrixMode(GL_MODELVIEW
);
57 // We don't need to call drawSphere() here,
58 // since the resizeGL() will be called upon
59 // the initial creation of the window.
62 void MyGLWidget::paintGL()
64 qDebug("MyGLWidget::paintGL()");
67 glClear(GL_COLOR_BUFFER_BIT
);
69 glMatrixMode(GL_PROJECTION
);
71 gluPerspective(90, 1, 0.01, 100);
73 // Reset modelview matrix
74 glMatrixMode(GL_MODELVIEW
);
77 //gluLookAt(1, 1, 1, 0, 0, -1, 0, 1, 0);
78 gluLookAt(m_pCamera
->getEyeX(),
81 m_pCamera
->getCenterX(),
82 m_pCamera
->getCenterY(),
83 m_pCamera
->getCenterZ(),
88 // Draw global axis system
89 m_pAxisX
->draw(0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
90 m_pAxisY
->draw(0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
);
91 m_pAxisZ
->draw(0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
93 // Rotate appropriately
94 std::cout
<< "x = " << m_xCoord
<< "\ty = " << m_yCoord
<< "\tz = " << m_zCoord
95 << "\txR = " << m_xRot
<< "\tyR = " << m_yRot
<< "\tzR = " << m_zRot
98 glTranslatef(0, -m_xCoord
/700, 0);
100 glRotatef(m_xRot
, 1.0f
, 0.0f
, 0.0f
);
101 glRotatef(m_yRot
, 0.0f
, 1.0f
, 0.0f
);
102 glRotatef(m_zRot
, 0.0f
, 0.0f
, 1.0f
);
105 if (m_pAxisX
->isLocal() || m_pAxisY
->isLocal() || m_pAxisZ
->isLocal()) {
106 m_pAxisX
->draw(0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
107 m_pAxisY
->draw(0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
);
108 m_pAxisZ
->draw(0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
117 void MyGLWidget::resizeGL(int width
, int height
)
119 qDebug("MyGLWidget::resizeGL()\n"
120 "New width = %d\tNew height = %d", width
, height
);
122 // Update viewport to cover the whole screen
123 glViewport(0, 0, width
, height
);
125 // Reset projection matrix
126 glMatrixMode(GL_PROJECTION
);
128 //gluPerspective(45.0, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
130 // Reset modelview matrix
131 glMatrixMode(GL_MODELVIEW
);
135 void MyGLWidget::pullData(void)
137 qDebug("MyGLWidget::pullData()");
140 if (data
.size() >= 6) {
141 qDebug("Queue size = %d", data
.size());
142 m_xCoord
= data
.dequeue();
143 m_yCoord
= data
.dequeue();
144 m_zCoord
= data
.dequeue();
145 m_xRot
= data
.dequeue();
146 m_yRot
= data
.dequeue();
147 m_zRot
= data
.dequeue();
151 qDebug("WAKING THREAD");
152 m_thread
.condition
.wakeOne();
159 void MyGLWidget::startWorkerThread(void)
161 qDebug("MyGLWidget::startWorkerThread()");
163 m_thread
.setData(&this->data
);
167 void MyGLWidget::startAnimation(void)
169 qDebug("MyGLWidget::startAnimation()");
171 m_timer
.start(m_timerInterval
);
174 void MyGLWidget::stopAnimation(void)
176 qDebug("MyGLWidget::stopAnimation()");
181 void MyGLWidget::setAxis(axis_t axis
, const Axis
*pAxis
)
183 qDebug("MyGLWidget::setAxis()");
198 void MyGLWidget::setCamera(const Camera
*pCamera
)
200 qDebug("MyGLWidget::setCamera()");
205 void MyGLWidget::setSphere(const Sphere
*pSphere
)
207 qDebug("MyGLWidge::setSphere()");