#include "form.h"
#include "ui_form.h"
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QWidget>
#include <QtGui/QImage.h>
#include <QtGui/qevent.h>
#include <float.h>
#include <windows.h> // Windows的头文件
#include <QtOpenGL/QGLWidget>
#include <QtGui/QtGui>
#include <QtOpenGL/QtOpenGL>
#include <stdio.h> // 标准输入/输出库的头文件
bool fill=true;
//teapot is here~~~~~~~~~~~~~~~~~~~~~~~~~~
GLfloat ambientlight[]={0.3f,0.3f,0.3f,0.3f};
GLfloat eye[3] = { 0.0, 0.0, 0.0 };
GLfloat at[3] = { 0.0, 0.0, 0.0 };
GLfloat up[3] = { 0.0, 1.0, 0.0 };
int count3=0;
GLfloat cap[2][4][3][4][3]={{
{{{0.0f,3.0f,0.0f},{0.0,3,1.0},{0.0,3.0,0},{0.0,2.5,0.2}},
{{0.0f,3.0,0.0f},{1.0,3,1.0},{0,3.0,0},{0.2,2.5,0.2}},
{{0.0f,3.0,0.0f},{1.0,3,0.0f},{0,3.0,0},{0.2,2.5,0}}},
{{{-0.0f,3.0,0.0f},{-1.0,3,0.0f},{-0,3.0,0},{-0.2,2.5,0}},
{{-0.0f,3.0,0.0f},{-1.0,3,1.0},{-0,3.0,0},{-0.2,2.5,0.2}},
{{0.0f,3.0,0.0f},{0.0,3,1.0},{0.0,3.0,0},{0.0,2.5,0.2}}},
{{{0.0f,3.0,-0.0f},{0.0,3,-1.0},{0.0,3.0,-0.0},{0.0,2.5,-0.2}},
{{-0.0f,3.0,-0.0f},{-1.0,3,-1.0},{-0.0,3.0,-0},{-0.2,2.5,-0.2}},
{{-0.0f,3.0,0.0f},{-1.0,3,0.0f},{-0,3.0,0},{-0.2,2.5,0}}},
{{{0.0f,3.0,0.0f},{1.0,3,0.0f},{0,3.0,0},{0.2,2.5,0}},
{{0.0f,3.0,-0.0f},{1.0,3,-1.0},{0,3.0,-0.0},{0.2,2.5,-0.2}},
{{0.0f,3.0,-0.0f},{0.0,3,-1.0},{0.0,3.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0.8,0.0f},{2.0f,0.3f,0.0f},{1.5f, 0.075f,0.0f},{1.5f, 0.0f,0.0f}},
{{2.0f,0.8,-2.0f},{2.0f,0.3f,-2.0f},{1.5f, 0.075f,-1.5f},{1.5f, 0.0f,-1.5f}},
{{0.0f,0.8,-2.0f},{0.0f,0.3f,-2.0f},{0.0f, 0.075f,-1.5f},{0.0f, 0.0f,-1.5f}}}}};
GLfloat hand2[2][4][4][3];
GLfloat hand1[2][4][4][3]=
{{{{-1.6,1.9,0.0},{-1.6,1.9,0.3},{-1.5,2.1,0.3},{-1.5,2.1,0.0}},
{{-2.3,1.9,0.0},{-2.3,1.9,0.3}, {-2.5,2.1,0.3}, {-2.5,2.1,0.0}},
{{-2.7,1.9,0.0},{-2.7,1.9,0.3},{ -3.0,2.1,0.3},{-3.0,2.1,0.0}},
{{-2.7,1.65,0.0},{-2.7,1.65,0.3},{-3.0,1.65,0.3},{-3.0,1.65,0.0}}},
{{{-2.7,1.65,0.0}, { -2.7,1.65,0.3},{-3.0,1.65,0.3},{-3.0,1.65,0.0}},
{{-2.7,1.4,0.0},{-2.7,1.4,0.3},{-3.0,1.2,0.3 },{-3.0,1.2,0.0}},
{{-2.5,1.0 ,0.0 },{-2.5,1.0,0.3},{-2.65,0.79,0.3},{-2.65,0.79,0.0}},
{{-2.0,0.75,0.0},{-2.0,0.75,0.3},{-1.9,0.45,0.3},{-1.9,0.45,0.0}}}};
void hChangePoints(void){
int i,j,k;
for(i=0;i<2;i++){
for(j=0;j<4;j++){
for(k=0;k<4;k++){
hand2[i][j][k][0]=hand1[i][j][-k+3][0];
hand2[i][j][k][1]=hand1[i][j][-k+3][1];
hand2[i][j][k][2]=-hand1[i][j][-k+3][2];
}
}
}
}
GLfloat mouth1[2][4][4][3];
GLfloat mouth2[2][4][4][3];
GLfloat mouth[2][4][4][3]=
{{{{1.7, 0.0, 0.5},{1.7, 0.8, 0.5},{1.7, 0.8, 1.3},{1.7, 0.0, 1.3}},
{{3.1, 0.0, 0.8},{3.1, 0.8, 0.8},{2.6, 0.8, 1.3},{2.6, 0.0, 1.3}},
{{2.4, 0.0, 1.9},{2.4, 0.25, 1.9},{2.3, 0.25, 1.95},{2.3, 0.0, 1.95}},
{{3.3, 0.0, 2.3},{3.3, 0.25, 2.3},{2.7, 0.25, 2.3},{2.7, 0.0, 2.3}}},
{{{3.3, 0.0, 2.3}, {3.3, 0.25, 2.3},{2.7, 0.25, 2.3 },{2.7, 0.0, 2.3 }},
{{3.5, 0.0, 2.3}, {3.5, 0.25, 2.3},{2.8, 0.25, 2.3},{2.8, 0.0, 2.3}},
{{3.4, 0.0, 2.4}, {3.4, 0.1, 2.4}, {3.0, 0.1, 2.3}, {3.0, 0.0, 2.3}},
{{3.2, 0.0, 2.3}, {3.2, 0.15, 2.3},{2.8, 0.15, 2.3}, {2.8, 0.0, 2.3}}}};
void mChangePoints(void){
int i,j,k;
for(i=0;i<2;i++){
for(j=0;j<4;j++){
for(k=0;k<4;k++){
mouth1[i][j][k][0]=mouth[i][j][k][0];
mouth1[i][j][k][1]=mouth[i][j][k][2];
mouth1[i][j][k][2]=mouth[i][j][k][1];
}
}
}
for(i=0;i<2;i++){
for(j=0;j<4;j++){
for(k=0;k<4;k++){
mouth2[i][j][k][0]=mouth1[i][j][-k+3][0];
mouth2[i][j][k][1]=mouth1[i][j][-k+3][1];
mouth2[i][j][k][2]=-mouth1[i][j][-k+3][2];
}
}
}
}
GLfloat button[4][3][3]={
{{0.0f,0.0f,1.5f},{1.5,0.0f,1.5},{1.5,0.0f,0.0f}},
{{1.5,0.0f,0.0f},{1.5,0.0f,-1.5},{0.0f,0.0f,-1.5f}},
{{-1.5,0.0f,0.0f},{-1.5,0.0f,1.5},{0.0f,0.0f,1.5f}},
{{0.0f,0.0f,-1.5f},{-1.5,0.0f,-1.5},{-1.5,0.0f,0.0f}}};
void teapot(bool fill){
int i,j;
glEnable(GL_MAP2_VERTEX_3);
if(!fill){
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
else{
if(count3>=1){
for(j=0;j<2;j++){
for(i=0;i