2017年10月19日 星期四

Arthus week6

week06

step1:下載glut32.dll windows.zip data.zip source.zip 並解壓縮到桌面


step2:去moodle下載week5
week5打開cbp檔


step3:去setting compiler 把c++11的勾勾取消

 

step4:執行


step5:打開transformation.c 搜尋light


step6 :打光程式碼
GLfloat pos[] = { 0.0, 0.0, -1.0, 0.0 };
glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, pos);



step7:執行


step8:加入keyboard mouse
#include<stdio.h>
.
.
.
void keyboard (unsigned char key, int x, int y){
printf("now:%c (%d %d)\n",key,x,y);}
void mouse (int button,int state ,int x, int y)
{
printf("now: %d %d (%d %d)\n",button,state,x,y);
}
在int main()
{
.
.
.
glutCreateWindow("week06");
glutDisplayFunc(display);
glutKeyboardFunc(Keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}



step9:執行


keyboard讓東西轉 

step10:加 int rotateX=0,rotateY=0,rotateZ=0
在keyboard function中加入
    if(key=='1') rotateX++;
    if(key=='2') rotateY++;
    if(key=='3') rotateZ++;
glutPostRedisplay();///使得東西馬上更新
在display function中的drawmodol()前後加glPushMatrix()跟glPopMatrix()
並在前面加入
       glRotatef(rotateX,1,0,0);
        glRotatef(rotateY,0,1,0);
        glRotatef(rotateZ,0,0,1);
讓物體旋轉


step11:執行


MOUSE讓東西轉

step12:先加入int oldX=0,oldY=0;
在mouse function中加入
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();
}
在main中新增glutMotionFunc(motion);


step13:執行

沒有留言:

張貼留言