void nyGLWidget::initializeGL()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
}
void nyGLWidget::paintGL()
{
qglClearColor(clearColor);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glTranslatef(400.0f, 300.0f, -10.0f);
glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
// draw some objects
glPopMatrix();
}
void nyGLWidget::resizeGL(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,width,height,0,-1000,1000);
glMatrixMode(GL_MODELVIEW);
updateGL();
}
{
lastPos = event->pos();
}
{
int dx = event->x() - lastPos.x();
int dy = event->y() - lastPos.y();
if (event->buttons() & Qt::LeftButton) rotateBy(8 * dy, 8 * dx, 0);
else if (event->buttons() & Qt::RightButton) rotateBy(8 * dy, 0, 8 * dx);
lastPos = event->pos();
updateGL();
}
void nyGLWidget
::mouseReleaseEvent(QMouseEvent * /* event */) {
emit clicked();
}
void nyGLWidget::initializeGL()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
}
void nyGLWidget::paintGL()
{
qglClearColor(clearColor);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glTranslatef(400.0f, 300.0f, -10.0f);
glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
// draw some objects
glPopMatrix();
}
void nyGLWidget::resizeGL(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,width,height,0,-1000,1000);
glMatrixMode(GL_MODELVIEW);
updateGL();
}
void nyGLWidget::mousePressEvent(QMouseEvent *event)
{
lastPos = event->pos();
}
void nyGLWidget::mouseMoveEvent(QMouseEvent *event)
{
int dx = event->x() - lastPos.x();
int dy = event->y() - lastPos.y();
if (event->buttons() & Qt::LeftButton) rotateBy(8 * dy, 8 * dx, 0);
else if (event->buttons() & Qt::RightButton) rotateBy(8 * dy, 0, 8 * dx);
lastPos = event->pos();
updateGL();
}
void nyGLWidget::mouseReleaseEvent(QMouseEvent * /* event */)
{
emit clicked();
}
To copy to clipboard, switch view to plain text mode
Bookmarks