summaryrefslogtreecommitdiffstats
path: root/examples/opengl/grabber
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/grabber')
-rw-r--r--examples/opengl/grabber/glwidget.cpp63
-rw-r--r--examples/opengl/grabber/glwidget.h2
-rw-r--r--examples/opengl/grabber/main.cpp8
-rw-r--r--examples/opengl/grabber/mainwindow.cpp5
-rw-r--r--examples/opengl/grabber/mainwindow.h4
5 files changed, 38 insertions, 44 deletions
diff --git a/examples/opengl/grabber/glwidget.cpp b/examples/opengl/grabber/glwidget.cpp
index 6d8ef0049f..00964c1a0f 100644
--- a/examples/opengl/grabber/glwidget.cpp
+++ b/examples/opengl/grabber/glwidget.cpp
@@ -38,12 +38,12 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include <QtOpenGL>
+#include "glwidget.h"
-#include <math.h>
+#include <QMouseEvent>
+#include <QTimer>
-#include "glwidget.h"
+#include <math.h>
GLWidget::GLWidget(QWidget *parent)
: QGLWidget(parent)
@@ -191,57 +191,52 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius,
GLdouble r2 = outerRadius + toothSize / 2.0;
GLdouble delta = (2.0 * Pi / toothCount) / 4.0;
GLdouble z = thickness / 2.0;
- int i, j;
glShadeModel(GL_FLAT);
- for (i = 0; i < 2; ++i) {
+ for (int i = 0; i < 2; ++i) {
GLdouble sign = (i == 0) ? +1.0 : -1.0;
glNormal3d(0.0, 0.0, sign);
glBegin(GL_QUAD_STRIP);
- for (j = 0; j <= toothCount; ++j) {
+ for (int j = 0; j <= toothCount; ++j) {
GLdouble angle = 2.0 * Pi * j / toothCount;
- glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
- glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
- glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
- glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta),
- sign * z);
+ glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
+ glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
+ glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
+ glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta), sign * z);
}
glEnd();
glBegin(GL_QUADS);
- for (j = 0; j < toothCount; ++j) {
+ for (int j = 0; j < toothCount; ++j) {
GLdouble angle = 2.0 * Pi * j / toothCount;
- glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
- glVertex3d(r2 * cos(angle + delta), r2 * sin(angle + delta),
- sign * z);
- glVertex3d(r2 * cos(angle + 2 * delta), r2 * sin(angle + 2 * delta),
- sign * z);
- glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta),
- sign * z);
+ glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
+ glVertex3d(r2 * cos(angle + delta), r2 * sin(angle + delta), sign * z);
+ glVertex3d(r2 * cos(angle + 2 * delta), r2 * sin(angle + 2 * delta), sign * z);
+ glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta), sign * z);
}
glEnd();
}
glBegin(GL_QUAD_STRIP);
- for (i = 0; i < toothCount; ++i) {
- for (j = 0; j < 2; ++j) {
- GLdouble angle = 2.0 * Pi * (i + (j / 2.0)) / toothCount;
+ for (int i = 0; i < toothCount; ++i) {
+ for (int j = 0; j < 2; ++j) {
+ GLdouble angle = 2.0 * Pi * (i + j / 2.0) / toothCount;
GLdouble s1 = r1;
GLdouble s2 = r2;
if (j == 1)
qSwap(s1, s2);
- glNormal3d(cos(angle), sin(angle), 0.0);
- glVertex3d(s1 * cos(angle), s1 * sin(angle), +z);
- glVertex3d(s1 * cos(angle), s1 * sin(angle), -z);
+ glNormal3d(cos(angle), sin(angle), 0.0);
+ glVertex3d(s1 * cos(angle), s1 * sin(angle), +z);
+ glVertex3d(s1 * cos(angle), s1 * sin(angle), -z);
- glNormal3d(s2 * sin(angle + delta) - s1 * sin(angle),
+ glNormal3d(s2 * sin(angle + delta) - s1 * sin(angle),
s1 * cos(angle) - s2 * cos(angle + delta), 0.0);
- glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), +z);
- glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), -z);
+ glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), +z);
+ glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), -z);
}
}
glVertex3d(r1, 0.0, +z);
@@ -251,11 +246,11 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius,
glShadeModel(GL_SMOOTH);
glBegin(GL_QUAD_STRIP);
- for (i = 0; i <= toothCount; ++i) {
- GLdouble angle = i * 2.0 * Pi / toothCount;
- glNormal3d(-cos(angle), -sin(angle), 0.0);
- glVertex3d(r0 * cos(angle), r0 * sin(angle), +z);
- glVertex3d(r0 * cos(angle), r0 * sin(angle), -z);
+ for (int i = 0; i <= toothCount; ++i) {
+ GLdouble angle = i * 2.0 * Pi / toothCount;
+ glNormal3d(-cos(angle), -sin(angle), 0.0);
+ glVertex3d(r0 * cos(angle), r0 * sin(angle), +z);
+ glVertex3d(r0 * cos(angle), r0 * sin(angle), -z);
}
glEnd();
diff --git a/examples/opengl/grabber/glwidget.h b/examples/opengl/grabber/glwidget.h
index 88a97ac8b0..6f48102111 100644
--- a/examples/opengl/grabber/glwidget.h
+++ b/examples/opengl/grabber/glwidget.h
@@ -94,4 +94,4 @@ private:
QPoint lastPos;
};
-#endif
+#endif // GLWIDGET_H
diff --git a/examples/opengl/grabber/main.cpp b/examples/opengl/grabber/main.cpp
index f03543e449..be0e7b11cc 100644
--- a/examples/opengl/grabber/main.cpp
+++ b/examples/opengl/grabber/main.cpp
@@ -38,14 +38,14 @@
**
****************************************************************************/
-#include <QApplication>
-
#include "mainwindow.h"
+#include <QApplication>
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- MainWindow mainWin;
- mainWin.show();
+ MainWindow window;
+ window.show();
return app.exec();
}
diff --git a/examples/opengl/grabber/mainwindow.cpp b/examples/opengl/grabber/mainwindow.cpp
index a559649c55..e521b39dab 100644
--- a/examples/opengl/grabber/mainwindow.cpp
+++ b/examples/opengl/grabber/mainwindow.cpp
@@ -38,12 +38,11 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include <QtOpenGL>
-
#include "glwidget.h"
#include "mainwindow.h"
+#include <QtWidgets>
+
MainWindow::MainWindow()
{
centralWidget = new QWidget;
diff --git a/examples/opengl/grabber/mainwindow.h b/examples/opengl/grabber/mainwindow.h
index 6f981c5381..552f902c07 100644
--- a/examples/opengl/grabber/mainwindow.h
+++ b/examples/opengl/grabber/mainwindow.h
@@ -44,12 +44,12 @@
#include <QMainWindow>
QT_BEGIN_NAMESPACE
-class QAction;
class QLabel;
class QMenu;
class QScrollArea;
class QSlider;
QT_END_NAMESPACE
+
class GLWidget;
class MainWindow : public QMainWindow
@@ -91,4 +91,4 @@ private:
QAction *aboutQtAct;
};
-#endif
+#endif // MAINWINDOW_H