2017年10月19日 星期四

陳泱竹 Week06

1.開啟Lighting 打光:
從老師給的Week05範例中新增以下打光程式碼:
GLfloat pos[] = { 0.0, 0.0, -1.0, 0.0 };///

glEnable(GL_LIGHTING);///開啟打光
glEnable(GL_LIGHT0);///
glLightfv(GL_LIGHT0, GL_POSITION, pos);///
glEnable(GL_DEPTH_TEST);///



2.用滑鼠跟鍵盤控制:
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)
    {
        old_X=x;
        old_Y=y;
    }
}
void motion(int x,int y)
{
    rotateY += -(x-old_X);
    rotateX += -(y-old_Y);
    old_X=x;
    old_Y=y;
    glutPostRedisplay();
}
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
配合旋轉
glRotated(rotateX,1,0,0);
glRotated(rotatey,0,1,0);
glRotated(rotatez,0,0,1);




沒有留言:

張貼留言