Part1.編譯 Transformation
步驟1.下載week05.zip步驟2.將data資料夾放入解壓縮後的week05資料夾
步驟3.用notepad++編輯專案檔(.cbp)的路徑
1.<Option working_dir="." />
2.<Add directory="C:/Users/使用者名稱/路徑/freeglut/include" />
步驟4.從transformation.cpp複製以下程式碼貼在glutDisplayFunc(display);這行的下面
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
再將GLfloat pos[] = { 0.0, 0.0, -1.0, 0.0 };放在main函式的外面

步驟5.執行

完成拉~~
part2.加入鍵盤與滑鼠控制
步驟1.加入幾個函式
int rotateX=0,rotateY=0,rotateZ=0;
void keyboard(unsigned char key,int x,int y)
{
printf("now: %c <%d %d>\n",key,x,y);
switch(key)
{
case '1':
{
rotateX++;
break;
}
case '2':
{
rotateY++;
break;
}
case '3':
{
rotateZ++;
break;
}
}
glutPostRedisplay();
}
int tmpx=0,tmpy=0;
void mouse(int botton,int state,int x,int y)
{
printf("(%d %d %d %d sasasas)\n",botton,state,x,y);
printf("<%d %d% d>\n",rotateX,rotateY,rotateZ);
printf("<%d %d>\n",tmpx,tmpy);
if(state==GLUT_DOWN)
{
tmpx=x;
tmpy=y;
}
}
void motion(int x,int y)
{
rotateY+=-(x-tmpx);
rotateX+=-(y-tmpy);
tmpx=x;
tmpy=y;
glutPostRedisplay();
}
步驟2.在display函式加入以下程式碼
glPushMatrix();
glRotatef(rotateX,1,0,0);
glRotatef(rotateY,0,1,0);
glRotatef(rotateZ,0,0,1);
drawmodel();
glPopMatrix();
步驟3.在main的glutDisplayFunc(display);下面加入以下程式碼
glutMotionFunc(motion);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
沒有留言:
張貼留言