sprint 3 总结

1.要求:

演示可参考毕业设计答辩,包含两部分内容:

    项目陈述,可综述项目、团队、开发过程等。

    运行演示,实现的功能、业务、用户反馈等。

  希望各组认真准备,拿出最好的阵容最好的状态,展示一学期的学习与工作成果。

  •   各组注意完成sprint3的博客,写上团队贡献分。
  •   将演示PPT(如果有)和代码上传到github。

2.内容:

因为我们组后面出现点问题,就剩我一个人做这个项目,然后因本人能力有限,而且对魔方感兴趣,所以自己用c++,Opengl做一个魔方。

 3.人员:

                   陈楷淇

 每日立会:

             地点:图书馆

             时间:12:30

 

 
#include<gl/glut.h>
#include<time.h>
#include<stdlib.h>
#define SPEED 10

int face = 0;
int stop = 0;
int    upColor[27];
int  downColor[27];
int  leftColor[27];
int rightColor[27];
int frontColor[27];
int  backColor[27];
int direction[9] = {1,1,1,0,0,0,2,2,2};
GLfloat rotate[27][3];
int cube[9][9] =
{
    { 0, 1, 2, 3, 4, 5, 6, 7, 8},
    { 9,10,11,12,13,14,15,16,17},
    {18,19,20,21,22,23,24,25,26},
    { 0, 3, 6, 9,12,15,18,21,24},
    { 1, 4, 7,10,13,16,19,22,25},
    { 2, 5, 8,11,14,17,20,23,26},
    { 6, 7, 8,15,16,17,24,25,26},
    { 3, 4, 5,12,13,14,21,22,23},
    { 0, 1, 2, 9,10,11,18,19,20}
};
GLfloat block[27][24] =
{
    {-3.0f, 3.0f,-3.0f,-1.0f, 3.0f,-3.0f,-3.0f, 3.0f,-1.0f,-1.0f, 3.0f,-1.0f,-3.0f, 1.0f,-3.0f,-1.0f, 1.0f,-3.0f,-3.0f, 1.0f,-1.0f,-1.0f, 1.0f,-1.0f},
    {-1.0f, 3.0f,-3.0f, 1.0f, 3.0f,-3.0f,-1.0f, 3.0f,-1.0f, 1.0f, 3.0f,-1.0f,-1.0f, 1.0f,-3.0f, 1.0f, 1.0f,-3.0f,-1.0f, 1.0f,-1.0f, 1.0f, 1.0f,-1.0f},
    { 1.0f, 3.0f,-3.0f, 3.0f, 3.0f,-3.0f, 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f,-1.0f,-1.0f, 1.0f,-1.0f, 1.0f, 3.0f,-1.0f, 1.0f, 1.0f,-3.0f,-1.0f, 3.0f,-3.0f,-1.0f, 1.0f,-3.0f, 1.0f, 3.0f,-3.0f, 1.0f},
    {-3.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f,-3.0f,-1.0f, 3.0f,-1.0f,-1.0f, 3.0f,-3.0f,-3.0f, 1.0f,-1.0f,-3.0f, 1.0f,-3.0f,-3.0f, 3.0f,-1.0f,-3.0f, 3.0f},
    {-1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 3.0f, 1.0f,-1.0f, 3.0f,-1.0f,-3.0f, 1.0f, 1.0f,-3.0f, 1.0f,-1.0f,-3.0f, 3.0f, 1.0f,-3.0f, 3.0f},
    { 1.0f,-1.0f, 1.0f, 3.0f,-1.0f, 1.0f, 1.0f,-1.0f, 3.0f, 3.0f,-1.0f, 3.0f, 1.0f,-3.0f, 1.0f, 3.0f,-3.0f, 1.0f, 1.0f,-3.0f, 3.0f, 3.0f,-3.0f, 3.0f}
}; 

void SetColor(int color)//定义颜色(方便调用)
{
    switch(color)
    {
    case 0:glColor3f(0.0f,0.0f,0.0f);break;//black
    case 1:glColor3f(0.0f,0.0f,1.0f);break;//blue
    case 2:glColor3f(0.0f,1.0f,0.0f);break;//green
    case 3:glColor3f(0.0f,1.0f,1.0f);break;//cyan
    case 4:glColor3f(1.0f,0.0f,0.0f);break;//red
    case 5:glColor3f(1.0f,0.0f,1.0f);break;//purple
    case 6:glColor3f(1.0f,1.0f,0.0f);break;//yellow
    case 7:glColor3f(1.0f,1.0f,1.0f);break;//white
    case 8:glColor3f(1.0f,0.5f,0.0f);break;//orange
    default:return;
    }
}

void InitRot()//
{
    int i;
    for(i = 0;i < 27;i++)
    {
        rotate[i][0] = 0.0f;
        rotate[i][1] = 0.0f;
        rotate[i][2] = 0.0f;
    }
}

void InitColor()//初始颜色
{
    int i;
    for(i = 0;i < 27;i++)
    {
           upColor[i] = 6;
         downColor[i] = 6;
         leftColor[i] = 6;
        rightColor[i] = 6;
        frontColor[i] = 6;
         backColor[i] = 6;
    }
    for(i = 0;i < 9;i++)//每个面的颜色设置
    {
           upColor[cube[0][i]] = 7;
         downColor[cube[2][i]] = 6;
         leftColor[cube[3][i]] = 2;
        rightColor[cube[5][i]] = 1;
        frontColor[cube[6][i]] = 4;
         backColor[cube[8][i]] = 8;
    }
}

void ChangeSize(int w,int h)//坐标轴比例
{
    if(h == 0)h = 1;
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if(w <= h)glOrtho(-5.0f,5.0f,-5.0f*h/w,5.0f*h/w,-5.0f,5.0f);
    else glOrtho(-5.0f*w/h,5.0f*w/h,-5.0f,5.0f,-5.0f,5.0f);
    gluLookAt(0.2f,0.2f,1.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

void SetupRC(void)//
{
    glClearColor(0.0f,0.0f,0.0f,1.0f);//背景色
    glShadeModel(GL_FLAT);
    glEnable(GL_DEPTH_TEST);
    glLineWidth(5.0f);//线宽
}

void RenderScene(void)//魔方的线框架
{
    int i;
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    for(i = 0;i < 27;i++)
    {
        glPushMatrix();
        glRotatef(rotate[i][0], 1.0f, 0.0f, 0.0f);
        glRotatef(rotate[i][1], 0.0f, 1.0f, 0.0f);
        glRotatef(rotate[i][2], 0.0f, 0.0f,1.0f);
        glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
        glBegin(GL_QUADS);//画小正方形
        SetColor(upColor[i]);//up
        glVertex3f(block[i][ 0],block[i][ 1],block[i][ 2]);
        glVertex3f(block[i][ 3],block[i][ 4],block[i][ 5]);
        glVertex3f(block[i][ 9],block[i][10],block[i][11]);
        glVertex3f(block[i][ 6],block[i][ 7],block[i][ 8]);
        SetColor(downColor[i]);//down
        glVertex3f(block[i][12],block[i][13],block[i][14]);
        glVertex3f(block[i][15],block[i][16],block[i][17]);
        glVertex3f(block[i][21],block[i][22],block[i][23]);
        glVertex3f(block[i][18],block[i][19],block[i][20]);
        SetColor(leftColor[i]);//left
        glVertex3f(block[i][ 0],block[i][ 1],block[i][ 2]);
        glVertex3f(block[i][ 6],block[i][ 7],block[i][ 8]);
        glVertex3f(block[i][18],block[i][19],block[i][20]);
        glVertex3f(block[i][12],block[i][13],block[i][14]);
        SetColor(rightColor[i]);//right
        glVertex3f(block[i][ 3],block[i][ 4],block[i][ 5]);
        glVertex3f(block[i][ 9],block[i][10],block[i][11]);
        glVertex3f(block[i][21],block[i][22],block[i][23]);
        glVertex3f(block[i][15],block[i][16],block[i][17]);
        SetColor(frontColor[i]);//front
        glVertex3f(block[i][ 6],block[i][ 7],block[i][ 8]);
        glVertex3f(block[i][ 9],block[i][10],block[i][11]);
        glVertex3f(block[i][21],block[i][22],block[i][23]);
        glVertex3f(block[i][18],block[i][19],block[i][20]);
        SetColor(backColor[i]);//back
        glVertex3f(block[i][ 0],block[i][ 1],block[i][ 2]);
        glVertex3f(block[i][ 3],block[i][ 4],block[i][ 5]);
        glVertex3f(block[i][15],block[i][16],block[i][17]);
        glVertex3f(block[i][12],block[i][13],block[i][14]);
        glEnd();
        glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
        glBegin(GL_QUADS);//画框架
        SetColor(3);
        glVertex3f(block[i][ 0],block[i][ 1],block[i][ 2]);
        glVertex3f(block[i][ 3],block[i][ 4],block[i][ 5]);
        glVertex3f(block[i][ 9],block[i][10],block[i][11]);
        glVertex3f(block[i][ 6],block[i][ 7],block[i][ 8]);
        glVertex3f(block[i][12],block[i][13],block[i][14]);
        glVertex3f(block[i][15],block[i][16],block[i][17]);
        glVertex3f(block[i][21],block[i][22],block[i][23]);
        glVertex3f(block[i][18],block[i][19],block[i][20]);
        glVertex3f(block[i][ 0],block[i][ 1],block[i][ 2]);
        glVertex3f(block[i][ 6],block[i][ 7],block[i][ 8]);
        glVertex3f(block[i][18],block[i][19],block[i][20]);
        glVertex3f(block[i][12],block[i][13],block[i][14]);
        glVertex3f(block[i][ 3],block[i][ 4],block[i][ 5]);
        glVertex3f(block[i][ 9],block[i][10],block[i][11]);
        glVertex3f(block[i][21],block[i][22],block[i][23]);
        glVertex3f(block[i][15],block[i][16],block[i][17]);
        glEnd();
        glPopMatrix();
    }
    glutSwapBuffers();
}

void ChangeColor(int a)//转后颜色改变
{
    int i;
    int tempColor;
    switch(face)
    {
    case 0:
        for(i = -1;i <= a;i++)
        {
            tempColor =    upColor[ 0];   upColor[ 0] =    upColor[ 6];   upColor[ 6] =    upColor[ 8];   upColor[ 8] =    upColor[ 2];   upColor[ 2] = tempColor;
            tempColor =  leftColor[ 0]; leftColor[ 0] = frontColor[ 6];frontColor[ 6] = rightColor[ 8];rightColor[ 8] =  backColor[ 2]; backColor[ 2] = tempColor;
            tempColor =  backColor[ 0]; backColor[ 0] =  leftColor[ 6]; leftColor[ 6] = frontColor[ 8];frontColor[ 8] = rightColor[ 2];rightColor[ 2] = tempColor;
            tempColor =    upColor[ 1];   upColor[ 1] =    upColor[ 3];   upColor[ 3] =    upColor[ 7];   upColor[ 7] =    upColor[ 5];   upColor[ 5] = tempColor;
            tempColor =  backColor[ 1]; backColor[ 1] =  leftColor[ 3]; leftColor[ 3] = frontColor[ 7];frontColor[ 7] = rightColor[ 5];rightColor[ 5] = tempColor;
        }
        break;
    case 1:
        for(i = -1;i <= a;i++)
        {
            tempColor =  leftColor[ 9]; leftColor[ 9] = frontColor[15];frontColor[15] = rightColor[17];rightColor[17] =  backColor[11]; backColor[11] = tempColor;
            tempColor =  backColor[ 9]; backColor[ 9] =  leftColor[15]; leftColor[15] = frontColor[17];frontColor[17] = rightColor[11];rightColor[11] = tempColor;
            tempColor =  backColor[10]; backColor[10] =  leftColor[12]; leftColor[12] = frontColor[16];frontColor[16] = rightColor[14];rightColor[14] = tempColor;
        }
        break;
    case 2:
        for(i = -1;i <= a;i++)
        {
            tempColor =  downColor[18]; downColor[18] =  downColor[24]; downColor[24] =  downColor[26]; downColor[26] =  downColor[20]; downColor[20] = tempColor;
            tempColor =  leftColor[18]; leftColor[18] = frontColor[24];frontColor[24] = rightColor[26];rightColor[26] =  backColor[20]; backColor[20] = tempColor;
            tempColor =  backColor[18]; backColor[18] =  leftColor[24]; leftColor[24] = frontColor[26];frontColor[26] = rightColor[20];rightColor[20] = tempColor;
            tempColor =  downColor[19]; downColor[19] =  downColor[21]; downColor[21] =  downColor[25]; downColor[25] =  downColor[23]; downColor[23] = tempColor;
            tempColor =  backColor[19]; backColor[19] =  leftColor[21]; leftColor[21] = frontColor[25];frontColor[25] = rightColor[23];rightColor[23] = tempColor;
        }
        break;
    case 3:
        for(i = -1;i <= -a;i++)
        {
            tempColor =  leftColor[ 0]; leftColor[ 0] =  leftColor[18]; leftColor[18] =  leftColor[24]; leftColor[24] =  leftColor[ 6]; leftColor[ 6] = tempColor;
            tempColor =    upColor[ 0];   upColor[ 0] =  backColor[18]; backColor[18] =  downColor[24]; downColor[24] = frontColor[ 6];frontColor[ 6] = tempColor;
            tempColor =  backColor[ 0]; backColor[ 0] =  downColor[18]; downColor[18] = frontColor[24];frontColor[24] =    upColor[ 6];   upColor[ 6] = tempColor;
            tempColor =  leftColor[ 3]; leftColor[ 3] =  leftColor[ 9]; leftColor[ 9] =  leftColor[21]; leftColor[21] =  leftColor[15]; leftColor[15] = tempColor;
            tempColor =    upColor[ 3];   upColor[ 3] =  backColor[ 9]; backColor[ 9] =  downColor[21]; downColor[21] = frontColor[15];frontColor[15] = tempColor;
        }
        break;
    case 4:
        for(i = -1;i <= -a;i++)
        {
            tempColor =    upColor[ 1];   upColor[ 1] =  backColor[19]; backColor[19] =  downColor[25]; downColor[25] = frontColor[ 7];frontColor[ 7] = tempColor;
            tempColor =  backColor[ 1]; backColor[ 1] =  downColor[19]; downColor[19] = frontColor[25];frontColor[25] =    upColor[ 7];   upColor[ 7] = tempColor;
            tempColor =    upColor[ 4];   upColor[ 4] =  backColor[10]; backColor[10] =  downColor[22]; downColor[22] = frontColor[16];frontColor[16] = tempColor;
        }
        break;
    case 5:
        for(i = -1;i <= -a;i++)
        {
            tempColor = rightColor[ 2];rightColor[ 2] = rightColor[20];rightColor[20] = rightColor[26];rightColor[26] = rightColor[ 8];rightColor[ 8] = tempColor;
            tempColor =    upColor[ 2];   upColor[ 2] =  backColor[20]; backColor[20] =  downColor[26]; downColor[26] = frontColor[ 8];frontColor[ 8] = tempColor;
            tempColor =  backColor[ 2]; backColor[ 2] =  downColor[20]; downColor[20] = frontColor[26];frontColor[26] =    upColor[ 8];   upColor[ 8] = tempColor;
            tempColor = rightColor[ 5];rightColor[ 5] = rightColor[11];rightColor[11] = rightColor[23];rightColor[23] = rightColor[17];rightColor[17] = tempColor;
            tempColor =    upColor[ 5];   upColor[ 5] =  backColor[11]; backColor[11] =  downColor[23]; downColor[23] = frontColor[17];frontColor[17] = tempColor;
        }
        break;
    case 6:
        for(i = -1;i <= a;i++)
        {
            tempColor = frontColor[ 6];frontColor[ 6] = frontColor[24];frontColor[24] = frontColor[26];frontColor[26] = frontColor[ 8];frontColor[ 8] = tempColor;
            tempColor =    upColor[ 6];   upColor[ 6] =  leftColor[24]; leftColor[24] =  downColor[26]; downColor[26] = rightColor[ 8];rightColor[ 8] = tempColor;
            tempColor =  leftColor[ 6]; leftColor[ 6] =  downColor[24]; downColor[24] = rightColor[26];rightColor[26] =    upColor[ 8];   upColor[ 8] = tempColor;
            tempColor = frontColor[ 7];frontColor[ 7] = frontColor[15];frontColor[15] = frontColor[25];frontColor[25] = frontColor[17];frontColor[17] = tempColor;
            tempColor =    upColor[ 7];   upColor[ 7] =  leftColor[15]; leftColor[15] =  downColor[25]; downColor[25] = rightColor[17];rightColor[17] = tempColor;
        }
        break;
    case 7:
        for(i = -1;i <= a;i++)
        {
            tempColor =    upColor[ 3];   upColor[ 3] =  leftColor[21]; leftColor[21] =  downColor[23]; downColor[23] = rightColor[ 5];rightColor[ 5] = tempColor;
            tempColor =  leftColor[ 3]; leftColor[ 3] =  downColor[21]; downColor[21] = rightColor[23];rightColor[23] =    upColor[ 5];   upColor[ 5] = tempColor;
            tempColor =    upColor[ 4];   upColor[ 4] =  leftColor[12]; leftColor[12] =  downColor[22]; downColor[22] = rightColor[14];rightColor[14] = tempColor;
        }
        break;
    case 8:
        for(i = -1;i <= a;i++)
        {
            tempColor =  backColor[ 0]; backColor[ 0] =  backColor[18]; backColor[18] =  backColor[20]; backColor[20] =  backColor[ 2]; backColor[ 2] = tempColor;
            tempColor =    upColor[ 0];   upColor[ 0] =  leftColor[18]; leftColor[18] =  downColor[20]; downColor[20] = rightColor[ 2];rightColor[ 2] = tempColor;
            tempColor =  leftColor[ 0]; leftColor[ 0] =  downColor[18]; downColor[18] = rightColor[20];rightColor[20] =    upColor[ 2];   upColor[ 2] = tempColor;
            tempColor =  backColor[ 1]; backColor[ 1] =  backColor[ 9]; backColor[ 9] =  backColor[19]; backColor[19] =  backColor[11]; backColor[11] = tempColor;
            tempColor =    upColor[ 1];   upColor[ 1] =  leftColor[ 9]; leftColor[ 9] =  downColor[19]; downColor[19] = rightColor[11];rightColor[11] = tempColor;
        }
        break;
    default:
        return;
    }
}

void Rotate(int value)//设置转角度,90°
{
    int i;
    for(i = 0;i < 9;i++)
        rotate[cube[face][i]][direction[face]] -= 9.0f;
    glutPostRedisplay();
    if(rotate[cube[face][0]][direction[face]] == -90.0f)
    {
        if(value == 1)
        {
            stop = 0;
            InitRot();
            ChangeColor(-1);
            return;//复原
        }
        if(value >= 2)//打乱
        {
            value++;
            InitRot();
            ChangeColor(-1);
            face = rand() % 9;
            if(value == 15)
            {
                stop = 0;
                return;
            }
        }
    }
    glutTimerFunc(SPEED,Rotate,value);
}

void Keyboard(unsigned char key,int x,int y)//键盘热键
{
    if(stop == 1)
        return;
    stop = 1;
    switch(key)
    {
    case '1':face = 0;break;
    case '2':face = 1;break;
    case '3':face = 2;break;
    case '4':face = 3;break;
    case '5':face = 4;break;
    case '6':face = 5;break;
    case '7':face = 6;break;
    case '8':face = 7;break;
    case '9':face = 8;break;
    default:return;
    }
    glutTimerFunc(SPEED,Rotate,1);
}

void ProcessMenu(int value)
{
    switch(value)
    {
    case 1:
        InitRot();
        InitColor();
        break;
    case 2:
        stop = 1;
        glutTimerFunc(SPEED,Rotate,2);
        break;
    default:
        return;
    }
    glutPostRedisplay();
}

int main(int argc,char *argv[])//主函数
{
    
    InitRot();
    InitColor();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(500,200);
    glutCreateWindow("魔方");
    glutReshapeFunc(ChangeSize);
    SetupRC();
    glutDisplayFunc(RenderScene);
    srand(time(0));
    glutKeyboardFunc(Keyboard);
    glutCreateMenu(ProcessMenu);
    glutAddMenuEntry("复原",1);
    glutAddMenuEntry("打乱",2);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    glutMainLoop();
    return 0;
}

 

 

 

posted @ 2016-06-24 14:28  13陈楷淇  阅读(179)  评论(0编辑  收藏  举报