本文主要是介绍Qt_OpenGL:3D旋转自定义换色,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Qt_OpenGL:3D旋转自定义换色
//.h
#ifndef ROTATEWIDGET_H
#define ROTATEWIDGET_H#include <QMainWindow>
#include <QtOpenGL/QtOpenGL>class RotateWidget : public QGLWidget
{Q_OBJECTpublic:RotateWidget(QWidget *parent = 0);~RotateWidget();
protected:void initializeGL();void paintGL();void resizeGL(int width, int height);void mousePressEvent(QMouseEvent*);void mouseMoveEvent(QMouseEvent*);void mouseDoubleClickEvent(QMouseEvent*);void mouseReleaseEvent(QMouseEvent *);
private slots:void Rotate();
private:void draw();int faceAtPosition(const QPoint &pos);void Spin(int xAngle, int yAngle, int zAngle);
private:QTimer *timer;GLfloat rotationX;GLfloat rotationY;GLfloat rotationZ;QColor faceColors[6];QPoint lastPos;};#endif // ROTATEWIDGET_H
//.cpp
#include "rotatewidget.h"
#include <glut.h>
#include <QTimer>RotateWidget::RotateWidget(QWidget *parent): QGLWidget(parent)
{setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));rotationX = -21.0;rotationY = -57.0;rotationZ = 0.0;faceColors[0] = Qt::red;faceColors[1] = Qt::green;faceColors[2] = Qt::blue;faceColors[3] = Qt::yellow;faceColors[4] = Qt::gray;faceColors[5] = Qt::cyan;timer = new QTimer(this);connect(timer, SIGNAL(timeout()), this, SLOT(Rotate()));timer->start(20);}void RotateWidget::initializeGL(){qglClearColor(Qt::black);glShadeModel(G
这篇关于Qt_OpenGL:3D旋转自定义换色的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!