2018年1月2日 星期二

abcqq week 06

1.打光

相關程式碼:

glutCreateWindow(...); //開視窗

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); //打光程式1
glEnable(GL_LIGHT0); //打光程式2
glLightfv(GL_LIGHT0, GPOSITION, pos); 


keyboard 副程式

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(); //畫面重新 re-display
}

滑鼠控制  

void mouse(int button, int state, int x, int y)
{   printf("button:%d state:%d (%d %d)\n", button, state, x, y);
    
    if(state==GLUT_DOWN) 
    {
        oldX=x; oldY=y;
    }
}

滑鼠拖曳
void motion(int x, int y)
{
    rotateY +=   -(x-oldX);
    rotateX +=   -(y-oldY);
    oldX=x; oldY=y;
    glutPostRedisplay();
}


沒有留言:

張貼留言