9 #include "coordsAndAngles.h"
10 #include "myglwidget.h"
11 #include "workerthread.h"
13 // Non-default arguments must come first
14 MyGLWidget::MyGLWidget(Axis
*pAxisX
, Axis
*pAxisY
, Axis
*pAxisZ
,
15 Camera
*pCamera
, Sphere
* pSphere
, QWidget
*parent
)
18 qDebug("MyGLWidget::MyGLWidget()");
28 MyGLWidget::~MyGLWidget()
30 qDebug("MyGLWidget::~MyGLWidget()");
33 void MyGLWidget::initializeGL()
35 qDebug("MyGLWidget::initializeGL()");
37 // Enable backface culling
38 glEnable(GL_CULL_FACE
);
40 // Clear color is set to black
41 glClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
);
42 glShadeModel(GL_SMOOTH
);
44 // Reset modelview matrix
45 glMatrixMode(GL_MODELVIEW
);
48 // We don't need to call drawSphere() here,
49 // since the resizeGL() will be called upon
50 // the initial creation of the window.
53 void MyGLWidget::paintGL()
55 qDebug("MyGLWidget::paintGL()");
58 glClear(GL_COLOR_BUFFER_BIT
);
60 glMatrixMode(GL_PROJECTION
);
62 gluPerspective(90, 1, 0.01, 100);
64 // Reset modelview matrix
65 glMatrixMode(GL_MODELVIEW
);
68 //gluLookAt(1, 1, 1, 0, 0, -1, 0, 1, 0);
69 gluLookAt(m_pCamera
->getEyeX(),
72 m_pCamera
->getCenterX(),
73 m_pCamera
->getCenterY(),
74 m_pCamera
->getCenterZ(),
79 // Draw global axis system
80 m_pAxisX
->draw(0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
81 m_pAxisY
->draw(0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
);
82 m_pAxisZ
->draw(0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
84 // Rotate appropriately
85 qDebug("xP = %f\tyP = %f\tzP = %f\txA = %f\tyA = %f\tzA = %f",
86 m_pCoordsAndAngles
->getXPos(),
87 m_pCoordsAndAngles
->getYPos(),
88 m_pCoordsAndAngles
->getZPos(),
89 m_pCoordsAndAngles
->getXAngle(),
90 m_pCoordsAndAngles
->getYAngle(),
91 m_pCoordsAndAngles
->getZAngle());
93 glTranslatef(0, -m_pCoordsAndAngles
->getXPos()/700, 0);
95 glRotatef(m_pCoordsAndAngles
->getXAngle(), 1.0f
, 0.0f
, 0.0f
);
96 glRotatef(m_pCoordsAndAngles
->getYAngle(), 0.0f
, 1.0f
, 0.0f
);
97 glRotatef(m_pCoordsAndAngles
->getZAngle(), 0.0f
, 0.0f
, 1.0f
);
100 if (m_pAxisX
->isLocal() || m_pAxisY
->isLocal() || m_pAxisZ
->isLocal()) {
101 m_pAxisX
->draw(0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
102 m_pAxisY
->draw(0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
);
103 m_pAxisZ
->draw(0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
112 void MyGLWidget::resizeGL(int width
, int height
)
114 qDebug("MyGLWidget::resizeGL()\n"
115 "New width = %d\tNew height = %d", width
, height
);
117 // Update viewport to cover the whole screen
118 glViewport(0, 0, width
, height
);
120 // Reset projection matrix
121 glMatrixMode(GL_PROJECTION
);
123 //gluPerspective(45.0, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
125 // Reset modelview matrix
126 glMatrixMode(GL_MODELVIEW
);
130 void MyGLWidget::setAxis(axis_t axis
, const Axis
*pAxis
)
132 qDebug("MyGLWidget::setAxis()");
147 void MyGLWidget::setCamera(const Camera
*pCamera
)
149 qDebug("MyGLWidget::setCamera()");
154 void MyGLWidget::setSphere(const Sphere
*pSphere
)
156 qDebug("MyGLWidget::setSphere()");
161 void MyGLWidget::setCoordsAndAngles(const CoordsAndAngles
*pCoordsAndAngles
)
163 qDebug("MyGLWidget::setCoordsAndAngles()");
165 m_pCoordsAndAngles
= pCoordsAndAngles
;