2017年10月19日 星期四

魏建新的第六週學習單

1.在MOODLE上下載week05跟freeglut解壓
2.解決編輯問題

3.加入光影,鍵盤,mouse函式

4.RUN


函式:
GLfloat pos[] = { 0.0, 0.0, -1.0, 0.0 };
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
int rotateX=0,rotateY=0,rotateZ=0;
int oldX=0,oldY=0;
void keyboard(unsigned char key,int x,int y)
{
    printf("now: %c (%d %d)\n",key,x,y);
    if(key=='1')
    {
        rotateX++;
    }
    if(key=='2')
    {
        rotateY++;
    }
    if(key=='3')
    {
        rotateZ++;
    }
    glutPostRedisplay();
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)
    {
        oldX=x;
        oldY=y;
    }
}
void motion(int x,int y)
{
    rotateX+= -(x-oldX);
    rotateY+= -(y-oldY);
    oldX=x;
    oldY=y;
    glutPostRedisplay();
}

沒有留言:

張貼留言