#include "mypanelopengl.h"
#include <cmath>
#include <QTimer>
#include "main.h"
extern QList<FileData> points;
int counter = 0;
MyPanelOpenGL
::MyPanelOpenGL(QWidget *parent
) :{
rotationY = -90.0;
}
void MyPanelOpenGL::initializeGL()
{
qglClearColor(Qt::white);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
gluLookAt(-5,0,0,0,0,0,0,1,0);
}
void MyPanelOpenGL::resizeGL(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-60,60,-60,60,-620,620);
glMatrixMode(GL_MODELVIEW);
}
void MyPanelOpenGL::drawspine()
{
glBegin(GL_LINES);
glColor3ub(0,0,0);
//Spine
glVertex3f(0, -50, 0);
glVertex3f(0, 50, 0);
glEnd();
}
void MyPanelOpenGL::drawshoulder()
{
glBegin(GL_LINES);
glColor3ub(0,0,0);
//Shoulder
glVertex3f(-50, 0, 0);
glVertex3f(50, 0, 0);
glEnd();
}
void MyPanelOpenGL::drawarm(int i)
{
glBegin(GL_LINES);
glColor3ub(0,0,0);
//Arm
glVertex3f(-50, 0, 0);
glVertex3f(points[i].ElbowY, -points[i].ElbowZ, points[i].ElbowX);
glEnd();
}
void MyPanelOpenGL::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(5.0, 5.0, 0.0);
glLineWidth(1);
glColor3f(0, 0.7f, 0.7f);
glRotatef(rotationY, 0.0, 1.0, 0.0);
drawspine();
drawshoulder();
drawarm(counter);
if ( counter < points.size()-1 )
{
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
counter++;
timer->start(500);
}
}
void MyPanelOpenGL
::mousePressEvent(QMouseEvent *event
) {
lastPos = event->pos();
}
{
GLfloat dx = GLfloat(event->x() - lastPos.x()) / width();
GLfloat dy = GLfloat(event->y() - lastPos.y()) / height();
counter++;
if (event->buttons() & Qt::LeftButton) {
rotationX += 180 * dy;
rotationY += 180 * dx;
updateGL();
} else if (event->buttons() & Qt::RightButton) {
rotationX += 180 * dy;
rotationZ += 180 * dx;
updateGL();
}
lastPos = event->pos();
}
#include "mypanelopengl.h"
#include <cmath>
#include <QTimer>
#include "main.h"
extern QList<FileData> points;
int counter = 0;
MyPanelOpenGL::MyPanelOpenGL(QWidget *parent) :
QGLWidget(parent)
{
rotationY = -90.0;
}
void MyPanelOpenGL::initializeGL()
{
qglClearColor(Qt::white);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
gluLookAt(-5,0,0,0,0,0,0,1,0);
}
void MyPanelOpenGL::resizeGL(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-60,60,-60,60,-620,620);
glMatrixMode(GL_MODELVIEW);
}
void MyPanelOpenGL::drawspine()
{
glBegin(GL_LINES);
glColor3ub(0,0,0);
//Spine
glVertex3f(0, -50, 0);
glVertex3f(0, 50, 0);
glEnd();
}
void MyPanelOpenGL::drawshoulder()
{
glBegin(GL_LINES);
glColor3ub(0,0,0);
//Shoulder
glVertex3f(-50, 0, 0);
glVertex3f(50, 0, 0);
glEnd();
}
void MyPanelOpenGL::drawarm(int i)
{
glBegin(GL_LINES);
glColor3ub(0,0,0);
//Arm
glVertex3f(-50, 0, 0);
glVertex3f(points[i].ElbowY, -points[i].ElbowZ, points[i].ElbowX);
glEnd();
}
void MyPanelOpenGL::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(5.0, 5.0, 0.0);
glLineWidth(1);
glColor3f(0, 0.7f, 0.7f);
glRotatef(rotationY, 0.0, 1.0, 0.0);
drawspine();
drawshoulder();
drawarm(counter);
if ( counter < points.size()-1 )
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
counter++;
timer->start(500);
}
}
void MyPanelOpenGL::mousePressEvent(QMouseEvent *event)
{
lastPos = event->pos();
}
void MyPanelOpenGL::mouseMoveEvent(QMouseEvent *event)
{
GLfloat dx = GLfloat(event->x() - lastPos.x()) / width();
GLfloat dy = GLfloat(event->y() - lastPos.y()) / height();
counter++;
if (event->buttons() & Qt::LeftButton) {
rotationX += 180 * dy;
rotationY += 180 * dx;
updateGL();
} else if (event->buttons() & Qt::RightButton) {
rotationX += 180 * dy;
rotationZ += 180 * dx;
updateGL();
}
lastPos = event->pos();
}
To copy to clipboard, switch view to plain text mode
Bookmarks